repeat.txt 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. *repeat.txt* Nvim
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. Repeating commands, Vim scripts and debugging *repeating*
  4. Chapter 26 of the user manual introduces repeating |usr_26.txt|.
  5. Type |gO| to see the table of contents.
  6. ==============================================================================
  7. Single repeats *single-repeat*
  8. *.*
  9. . Repeat last change, with count replaced with [count].
  10. Also repeat a yank command, when the 'y' flag is
  11. included in 'cpoptions'. Does not repeat a
  12. command-line command.
  13. Simple changes can be repeated with the "." command. Without a count, the
  14. count of the last change is used. If you enter a count, it will replace the
  15. last one. |v:count| and |v:count1| will be set.
  16. If the last change included a specification of a numbered register, the
  17. register number will be incremented. See |redo-register| for an example how
  18. to use this.
  19. Note that when repeating a command that used a Visual selection, the same SIZE
  20. of area is used, see |visual-repeat|.
  21. *@:*
  22. @: Repeat last command-line [count] times.
  23. ==============================================================================
  24. Multiple repeats *multi-repeat*
  25. *:g* *:global* *E148*
  26. :[range]g[lobal]/{pattern}/[cmd]
  27. Execute the Ex command [cmd] (default ":p") on the
  28. lines within [range] where {pattern} matches.
  29. :[range]g[lobal]!/{pattern}/[cmd]
  30. Execute the Ex command [cmd] (default ":p") on the
  31. lines within [range] where {pattern} does NOT match.
  32. *:v* *:vglobal*
  33. :[range]v[global]/{pattern}/[cmd]
  34. Same as :g!.
  35. Instead of the '/' which surrounds the {pattern}, you can use any other
  36. single byte character, but not an alphabetic character, '\', '"' or '|'.
  37. This is useful if you want to include a '/' in the search pattern or
  38. replacement string.
  39. For the definition of a pattern, see |pattern|.
  40. NOTE [cmd] may contain a range; see |collapse| and |edit-paragraph-join| for
  41. examples.
  42. The global commands work by first scanning through the [range] lines and
  43. marking each line where a match occurs (for a multi-line pattern, only the
  44. start of the match matters).
  45. In a second scan the [cmd] is executed for each marked line, as if the cursor
  46. was in that line. For ":v" and ":g!" the command is executed for each not
  47. marked line. If a line is deleted its mark disappears.
  48. The default for [range] is the whole buffer (1,$). Use "CTRL-C" to interrupt
  49. the command. If an error message is given for a line, the command for that
  50. line is aborted and the global command continues with the next marked or
  51. unmarked line.
  52. *E147*
  53. When the command is used recursively, it only works on one line. Giving a
  54. range is then not allowed. This is useful to find all lines that match a
  55. pattern and do not match another pattern: >
  56. :g/found/v/notfound/{cmd}
  57. This first finds all lines containing "found", but only executes {cmd} when
  58. there is no match for "notfound".
  59. To execute a non-Ex command, you can use the `:normal` command: >
  60. :g/pat/normal {commands}
  61. Make sure that {commands} ends with a whole command, otherwise Vim will wait
  62. for you to type the rest of the command for each match. The screen will not
  63. have been updated, so you don't know what you are doing. See |:normal|.
  64. The undo/redo command will undo/redo the whole global command at once.
  65. The previous context mark will only be set once (with "''" you go back to
  66. where the cursor was before the global command).
  67. The global command sets both the last used search pattern and the last used
  68. substitute pattern (this is vi compatible). This makes it easy to globally
  69. replace a string:
  70. :g/pat/s//PAT/g
  71. This replaces all occurrences of "pat" with "PAT". The same can be done with:
  72. :%s/pat/PAT/g
  73. Which is two characters shorter!
  74. When using "global" in Ex mode, a special case is using ":visual" as a
  75. command. This will move to a matching line, go to Normal mode to let you
  76. execute commands there until you use |Q| to return to Ex mode. This will be
  77. repeated for each matching line. While doing this you cannot use ":global".
  78. To abort this type CTRL-C twice.
  79. ==============================================================================
  80. Complex repeats *complex-repeat*
  81. *q* *recording*
  82. q{0-9a-zA-Z"} Record typed characters into register {0-9a-zA-Z"}
  83. (uppercase to append). The 'q' command is disabled
  84. while executing a register, and it doesn't work inside
  85. a mapping and |:normal|.
  86. Note: If the register being used for recording is also
  87. used for |y| and |p| the result is most likely not
  88. what is expected, because the put will paste the
  89. recorded macro and the yank will overwrite the
  90. recorded macro.
  91. q Stops recording.
  92. Implementation note: The 'q' that stops recording is
  93. not stored in the register, unless it was the result
  94. of a mapping
  95. *@*
  96. @{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} [count]
  97. times. Note that register '%' (name of the current
  98. file) and '#' (name of the alternate file) cannot be
  99. used.
  100. The register is executed like a mapping, that means
  101. that the difference between 'wildchar' and 'wildcharm'
  102. applies.
  103. For "@=" you are prompted to enter an expression. The
  104. result of the expression is then executed.
  105. See also |@:|.
  106. *@@* *E748*
  107. @@ Repeat the previous @{0-9a-z":*} [count] times.
  108. *:@*
  109. :[addr]@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} as an Ex
  110. command. First set cursor at line [addr] (default is
  111. current line). When the last line in the register does
  112. not have a <CR> it will be added automatically when
  113. the 'e' flag is present in 'cpoptions'.
  114. For ":@=" the last used expression is used. The
  115. result of evaluating the expression is executed as an
  116. Ex command.
  117. Mappings are not recognized in these commands.
  118. *:@:*
  119. :[addr]@: Repeat last command-line. First set cursor at line
  120. [addr] (default is current line).
  121. :[addr]@ *:@@*
  122. :[addr]@@ Repeat the previous :@{0-9a-z"}. First set cursor at
  123. line [addr] (default is current line).
  124. ==============================================================================
  125. Using Vim scripts *using-scripts*
  126. For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
  127. *:so* *:source* *load-vim-script*
  128. :so[urce] {file} Read Ex commands from {file}. These are commands that
  129. start with a ":".
  130. Triggers the |SourcePre| autocommand.
  131. *:source!*
  132. :so[urce]! {file} Read Vim commands from {file}. These are commands
  133. that are executed from Normal mode, like you type
  134. them.
  135. When used after |:global|, |:argdo|, |:windo|,
  136. |:bufdo|, in a loop or when another command follows
  137. the display won't be updated while executing the
  138. commands.
  139. Cannot be used in the |sandbox|.
  140. *:ru* *:runtime*
  141. :ru[ntime][!] [where] {file} ..
  142. Read Ex commands from {file} in each directory given
  143. by 'runtimepath' and/or 'packpath'. There is no error
  144. for non-existing files.
  145. Example: >
  146. :runtime syntax/c.vim
  147. < There can be multiple {file} arguments, separated by
  148. spaces. Each {file} is searched for in the first
  149. directory from 'runtimepath', then in the second
  150. directory, etc. Use a backslash to include a space
  151. inside {file} (although it's better not to use spaces
  152. in file names, it causes trouble).
  153. When [!] is included, all found files are sourced.
  154. When it is not included only the first found file is
  155. sourced.
  156. When [where] is omitted only 'runtimepath' is used.
  157. Other values:
  158. START search under "start" in 'packpath'
  159. OPT search under "opt" in 'packpath'
  160. PACK search under "start" and "opt" in
  161. 'packpath'
  162. ALL first use 'runtimepath', then search
  163. under "start" and "opt" in 'packpath'
  164. When {file} contains wildcards it is expanded to all
  165. matching files. Example: >
  166. :runtime! plugin/*.vim
  167. < This is what Vim uses to load the plugin files when
  168. starting up. This similar command: >
  169. :runtime plugin/*.vim
  170. < would source the first file only.
  171. When 'verbose' is one or higher, there is a message
  172. when no file could be found.
  173. When 'verbose' is two or higher, there is a message
  174. about each searched file.
  175. *:pa* *:packadd* *E919*
  176. :pa[ckadd][!] {name} Search for an optional plugin directory in 'packpath'
  177. and source any plugin files found. The directory must
  178. match:
  179. pack/*/opt/{name} ~
  180. The directory is added to 'runtimepath' if it wasn't
  181. there yet.
  182. If the directory pack/*/opt/{name}/after exists it is
  183. added at the end of 'runtimepath'.
  184. If loading packages from "pack/*/start" was skipped,
  185. then this directory is searched first:
  186. pack/*/start/{name} ~
  187. Note that {name} is the directory name, not the name
  188. of the .vim file. All the files matching the pattern
  189. pack/*/opt/{name}/plugin/**/*.vim ~
  190. will be sourced. This allows for using subdirectories
  191. below "plugin", just like with plugins in
  192. 'runtimepath'.
  193. If the filetype detection was not enabled yet (this
  194. is usually done with a "syntax enable" or "filetype
  195. on" command in your .vimrc file), this will also look
  196. for "{name}/ftdetect/*.vim" files.
  197. When the optional ! is added no plugin files or
  198. ftdetect scripts are loaded, only the matching
  199. directories are added to 'runtimepath'. This is
  200. useful in your .vimrc. The plugins will then be
  201. loaded during initialization, see |load-plugins|.
  202. Also see |pack-add|.
  203. *:packl* *:packloadall*
  204. :packl[oadall][!] Load all packages in the "start" directory under each
  205. entry in 'packpath'.
  206. First all the directories found are added to
  207. 'runtimepath', then the plugins found in the
  208. directories are sourced. This allows for a plugin to
  209. depend on something of another plugin, e.g. an
  210. "autoload" directory. See |packload-two-steps| for
  211. how this can be useful.
  212. This is normally done automatically during startup,
  213. after loading your .vimrc file. With this command it
  214. can be done earlier.
  215. Packages will be loaded only once. Using
  216. `:packloadall` a second time will have no effect.
  217. When the optional ! is added this command will load
  218. packages even when done before.
  219. Note that when using `:packloadall` in the |vimrc|
  220. file, the 'runtimepath' option is updated, and later
  221. all plugins in 'runtimepath' will be loaded, which
  222. means they are loaded again. Plugins are expected to
  223. handle that.
  224. An error only causes sourcing the script where it
  225. happens to be aborted, further plugins will be loaded.
  226. See |packages|.
  227. :scripte[ncoding] [encoding] *:scripte* *:scriptencoding* *E167*
  228. Specify the character encoding used in the script.
  229. The following lines will be converted from [encoding]
  230. to the value of the 'encoding' option, if they are
  231. different. Examples: >
  232. scriptencoding iso-8859-5
  233. scriptencoding cp932
  234. <
  235. When [encoding] is empty, no conversion is done. This
  236. can be used to restrict conversion to a sequence of
  237. lines: >
  238. scriptencoding euc-jp
  239. ... lines to be converted ...
  240. scriptencoding
  241. ... not converted ...
  242. < When conversion isn't supported by the system, there
  243. is no error message and no conversion is done. When a
  244. line can't be converted there is no error and the
  245. original line is kept.
  246. Don't use "ucs-2" or "ucs-4", scripts cannot be in
  247. these encodings (they would contain NUL bytes).
  248. When a sourced script starts with a BOM (Byte Order
  249. Mark) in utf-8 format Vim will recognize it, no need
  250. to use ":scriptencoding utf-8" then.
  251. *:scr* *:scriptnames*
  252. :scr[iptnames] List all sourced script names, in the order they were
  253. first sourced. The number is used for the script ID
  254. |<SID>|.
  255. :scr[iptnames][!] {scriptId} *:script*
  256. Edit script {scriptId}. Although ":scriptnames name"
  257. works, using ":script name" is recommended.
  258. When the current buffer can't be |abandon|ed and the !
  259. is not present, the command fails.
  260. *:fini* *:finish* *E168*
  261. :fini[sh] Stop sourcing a script. Can only be used in a Vim
  262. script file. This is a quick way to skip the rest of
  263. the file. If it is used after a |:try| but before the
  264. matching |:finally| (if present), the commands
  265. following the ":finally" up to the matching |:endtry|
  266. are executed first. This process applies to all
  267. nested ":try"s in the script. The outermost ":endtry"
  268. then stops sourcing the script.
  269. All commands and command sequences can be repeated by putting them in a named
  270. register and then executing it. There are two ways to get the commands in the
  271. register:
  272. - Use the record command "q". You type the commands once, and while they are
  273. being executed they are stored in a register. Easy, because you can see
  274. what you are doing. If you make a mistake, "p"ut the register into the
  275. file, edit the command sequence, and then delete it into the register
  276. again. You can continue recording by appending to the register (use an
  277. uppercase letter).
  278. - Delete or yank the command sequence into the register.
  279. Often used command sequences can be put under a function key with the ':map'
  280. command.
  281. An alternative is to put the commands in a file, and execute them with the
  282. ':source!' command. Useful for long command sequences. Can be combined with
  283. the ':map' command to put complicated commands under a function key.
  284. The ':source' command reads Ex commands from a file line by line. You will
  285. have to type any needed keyboard input. The ':source!' command reads from a
  286. script file character by character, interpreting each character as if you
  287. typed it.
  288. Example: When you give the ":!ls" command you get the |hit-enter| prompt. If
  289. you ':source' a file with the line "!ls" in it, you will have to type the
  290. <Enter> yourself. But if you ':source!' a file with the line ":!ls" in it,
  291. the next characters from that file are read until a <CR> is found. You will
  292. not have to type <CR> yourself, unless ":!ls" was the last line in the file.
  293. It is possible to put ':source[!]' commands in the script file, so you can
  294. make a top-down hierarchy of script files. The ':source' command can be
  295. nested as deep as the number of files that can be opened at one time (about
  296. 15). The ':source!' command can be nested up to 15 levels deep.
  297. You can use the "<sfile>" string (literally, this is not a special key) inside
  298. of the sourced file, in places where a file name is expected. It will be
  299. replaced by the file name of the sourced file. For example, if you have a
  300. "other.vimrc" file in the same directory as your |init.vim| file, you can
  301. source it from your |init.vim| file with this command: >
  302. :source <sfile>:h/other.vimrc
  303. In script files terminal-dependent key codes are represented by
  304. terminal-independent two character codes. This means that they can be used
  305. in the same way on different kinds of terminals. The first character of a
  306. key code is 0x80 or 128, shown on the screen as "~@". The second one can be
  307. found in the list |key-notation|. Any of these codes can also be entered
  308. with CTRL-V followed by the three digit decimal code.
  309. *:source_crnl* *W15*
  310. Windows: Files that are read with ":source" normally have <CR><NL> <EOL>s.
  311. These always work. If you are using a file with <NL> <EOL>s (for example, a
  312. file made on Unix), this will be recognized if 'fileformats' is not empty and
  313. the first line does not end in a <CR>. This fails if the first line has
  314. something like ":map <F1> :help^M", where "^M" is a <CR>. If the first line
  315. ends in a <CR>, but following ones don't, you will get an error message,
  316. because the <CR> from the first lines will be lost.
  317. On other systems, Vim expects ":source"ed files to end in a <NL>. These
  318. always work. If you are using a file with <CR><NL> <EOL>s (for example, a
  319. file made on Windows), all lines will have a trailing <CR>. This may cause
  320. problems for some commands (e.g., mappings). There is no automatic <EOL>
  321. detection, because it's common to start with a line that defines a mapping
  322. that ends in a <CR>, which will confuse the automaton.
  323. *line-continuation*
  324. Long lines in a ":source"d Ex command script file can be split by inserting
  325. a line continuation symbol "\" (backslash) at the start of the next line.
  326. There can be white space before the backslash, which is ignored.
  327. Example: the lines >
  328. :set comments=sr:/*,mb:*,el:*/,
  329. \://,
  330. \b:#,
  331. \:%,
  332. \n:>,
  333. \fb:-
  334. are interpreted as if they were given in one line:
  335. :set comments=sr:/*,mb:*,el:*/,://,b:#,:%,n:>,fb:-
  336. All leading whitespace characters in the line before a backslash are ignored.
  337. Note however that trailing whitespace in the line before it cannot be
  338. inserted freely; it depends on the position where a command is split up
  339. whether additional whitespace is allowed or not.
  340. When a space is required it's best to put it right after the backslash. A
  341. space at the end of a line is hard to see and may be accidentally deleted. >
  342. :syn match Comment
  343. \ "very long regexp"
  344. \ keepend
  345. There is a problem with the ":append" and ":insert" commands: >
  346. :1append
  347. \asdf
  348. .
  349. The backslash is seen as a line-continuation symbol, thus this results in the
  350. command: >
  351. :1appendasdf
  352. .
  353. To avoid this, add the 'C' flag to the 'cpoptions' option: >
  354. :set cpo+=C
  355. :1append
  356. \asdf
  357. .
  358. :set cpo-=C
  359. Note that when the commands are inside a function, you need to add the 'C'
  360. flag when defining the function, it is not relevant when executing it. >
  361. :set cpo+=C
  362. :function Foo()
  363. :1append
  364. \asdf
  365. .
  366. :endfunction
  367. :set cpo-=C
  368. <
  369. *line-continuation-comment*
  370. To add a comment in between the lines start with '\" '. Notice the space
  371. after the double quote. Example: >
  372. let array = [
  373. "\ first entry comment
  374. \ 'first',
  375. "\ second entry comment
  376. \ 'second',
  377. \ ]
  378. Rationale:
  379. Most programs work with a trailing backslash to indicate line
  380. continuation. Using this in Vim would cause incompatibility with Vi.
  381. For example for this Vi mapping: >
  382. :map xx asdf\
  383. < Therefore the unusual leading backslash is used.
  384. Starting a comment in a continuation line results in all following
  385. continuation lines to be part of the comment. Since it was like this
  386. for a long time, when making it possible to add a comment halfway a
  387. sequence of continuation lines, it was not possible to use \", since
  388. that was a valid continuation line. Using '"\ ' comes closest, even
  389. though it may look a bit weird. Requiring the space after the
  390. backslash is to make it very unlikely this is a normal comment line.
  391. ==============================================================================
  392. Using Vim packages *packages*
  393. A Vim package is a directory that contains one or more plugins. The
  394. advantages over normal plugins:
  395. - A package can be downloaded as an archive and unpacked in its own directory.
  396. Thus the files are not mixed with files of other plugins. That makes it
  397. easy to update and remove.
  398. - A package can be a git, mercurial, etc. repository. That makes it really
  399. easy to update.
  400. - A package can contain multiple plugins that depend on each other.
  401. - A package can contain plugins that are automatically loaded on startup and
  402. ones that are only loaded when needed with `:packadd`.
  403. Using a package and loading automatically ~
  404. Let's assume your Vim files are in the "~/.local/share/nvim/site" directory
  405. and you want to add a package from a zip archive "/tmp/foopack.zip":
  406. % mkdir -p ~/.local/share/nvim/site/pack/foo
  407. % cd ~/.local/share/nvim/site/pack/foo
  408. % unzip /tmp/foopack.zip
  409. The directory name "foo" is arbitrary, you can pick anything you like.
  410. You would now have these files under ~/.local/share/nvim/site:
  411. pack/foo/README.txt
  412. pack/foo/start/foobar/plugin/foo.vim
  413. pack/foo/start/foobar/syntax/some.vim
  414. pack/foo/opt/foodebug/plugin/debugger.vim
  415. When Vim starts up, after processing your .vimrc, it scans all directories in
  416. 'packpath' for plugins under the "pack/*/start" directory. First all those
  417. directories are added to 'runtimepath'. Then all the plugins are loaded.
  418. See |packload-two-steps| for how these two steps can be useful.
  419. In the example Vim will find "pack/foo/start/foobar/plugin/foo.vim" and adds
  420. "~/.local/share/nvim/site/pack/foo/start/foobar" to 'runtimepath'.
  421. If the "foobar" plugin kicks in and sets the 'filetype' to "some", Vim will
  422. find the syntax/some.vim file, because its directory is in 'runtimepath'.
  423. Vim will also load ftdetect files, if there are any.
  424. Note that the files under "pack/foo/opt" are not loaded automatically, only the
  425. ones under "pack/foo/start". See |pack-add| below for how the "opt" directory
  426. is used.
  427. Loading packages automatically will not happen if loading plugins is disabled,
  428. see |load-plugins|.
  429. To load packages earlier, so that 'runtimepath' gets updated: >
  430. :packloadall
  431. This also works when loading plugins is disabled. The automatic loading will
  432. only happen once.
  433. If the package has an "after" directory, that directory is added to the end of
  434. 'runtimepath', so that anything there will be loaded later.
  435. Using a single plugin and loading it automatically ~
  436. If you don't have a package but a single plugin, you need to create the extra
  437. directory level:
  438. % mkdir -p ~/.local/share/nvim/site/pack/foo/start/foobar
  439. % cd ~/.local/share/nvim/site/pack/foo/start/foobar
  440. % unzip /tmp/someplugin.zip
  441. You would now have these files:
  442. pack/foo/start/foobar/plugin/foo.vim
  443. pack/foo/start/foobar/syntax/some.vim
  444. From here it works like above.
  445. Optional plugins ~
  446. *pack-add*
  447. To load an optional plugin from a pack use the `:packadd` command: >
  448. :packadd foodebug
  449. This searches for "pack/*/opt/foodebug" in 'packpath' and will find
  450. ~/.local/share/nvim/site/pack/foo/opt/foodebug/plugin/debugger.vim and source
  451. it.
  452. This could be done if some conditions are met. For example, depending on
  453. whether Vim supports a feature or a dependency is missing.
  454. You can also load an optional plugin at startup, by putting this command in
  455. your |.vimrc|: >
  456. :packadd! foodebug
  457. The extra "!" is so that the plugin isn't loaded if Vim was started with
  458. |--noplugin|.
  459. It is perfectly normal for a package to only have files in the "opt"
  460. directory. You then need to load each plugin when you want to use it.
  461. Where to put what ~
  462. Since color schemes, loaded with `:colorscheme`, are found below
  463. "pack/*/start" and "pack/*/opt", you could put them anywhere. We recommend
  464. you put them below "pack/*/opt", for example
  465. ".vim/pack/mycolors/opt/dark/colors/very_dark.vim".
  466. Filetype plugins should go under "pack/*/start", so that they are always
  467. found. Unless you have more than one plugin for a file type and want to
  468. select which one to load with `:packadd`. E.g. depending on the compiler
  469. version: >
  470. if foo_compiler_version > 34
  471. packadd foo_new
  472. else
  473. packadd foo_old
  474. endif
  475. The "after" directory is most likely not useful in a package. It's not
  476. disallowed though.
  477. ==============================================================================
  478. Creating Vim packages *package-create*
  479. This assumes you write one or more plugins that you distribute as a package.
  480. If you have two unrelated plugins you would use two packages, so that Vim
  481. users can chose what they include or not. Or you can decide to use one
  482. package with optional plugins, and tell the user to add the ones he wants with
  483. `:packadd`.
  484. Decide how you want to distribute the package. You can create an archive or
  485. you could use a repository. An archive can be used by more users, but is a
  486. bit harder to update to a new version. A repository can usually be kept
  487. up-to-date easily, but it requires a program like "git" to be available.
  488. You can do both, github can automatically create an archive for a release.
  489. Your directory layout would be like this:
  490. start/foobar/plugin/foo.vim " always loaded, defines commands
  491. start/foobar/plugin/bar.vim " always loaded, defines commands
  492. start/foobar/autoload/foo.vim " loaded when foo command used
  493. start/foobar/doc/foo.txt " help for foo.vim
  494. start/foobar/doc/tags " help tags
  495. opt/fooextra/plugin/extra.vim " optional plugin, defines commands
  496. opt/fooextra/autoload/extra.vim " loaded when extra command used
  497. opt/fooextra/doc/extra.txt " help for extra.vim
  498. opt/fooextra/doc/tags " help tags
  499. This allows for the user to do: >
  500. mkdir ~/.local/share/nvim/site/pack/myfoobar
  501. cd ~/.local/share/nvim/site/pack/myfoobar
  502. git clone https://github.com/you/foobar.git
  503. Here "myfoobar" is a name that the user can choose, the only condition is that
  504. it differs from other packages.
  505. In your documentation you explain what the plugins do, and tell the user how
  506. to load the optional plugin: >
  507. :packadd! fooextra
  508. You could add this packadd command in one of your plugins, to be executed when
  509. the optional plugin is needed.
  510. Run the `:helptags` command to generate the doc/tags file. Including this
  511. generated file in the package means that the user can drop the package in his
  512. pack directory and the help command works right away. Don't forget to re-run
  513. the command after changing the plugin help: >
  514. :helptags path/start/foobar/doc
  515. :helptags path/opt/fooextra/doc
  516. Dependencies between plugins ~
  517. *packload-two-steps*
  518. Suppose you have two plugins that depend on the same functionality. You can
  519. put the common functionality in an autoload directory, so that it will be
  520. found automatically. Your package would have these files:
  521. pack/foo/start/one/plugin/one.vim >
  522. call foolib#getit()
  523. < pack/foo/start/two/plugin/two.vim >
  524. call foolib#getit()
  525. < pack/foo/start/lib/autoload/foolib.vim >
  526. func foolib#getit()
  527. This works, because loading packages will first add all found directories to
  528. 'runtimepath' before sourcing the plugins.
  529. ==============================================================================
  530. Debugging scripts *debug-scripts*
  531. Besides the obvious messages that you can add to your scripts to find out what
  532. they are doing, Vim offers a debug mode. This allows you to step through a
  533. sourced file or user function and set breakpoints.
  534. NOTE: The debugging mode is far from perfect. Debugging will have side
  535. effects on how Vim works. You cannot use it to debug everything. For
  536. example, the display is messed up by the debugging messages.
  537. An alternative to debug mode is setting the 'verbose' option. With a bigger
  538. number it will give more verbose messages about what Vim is doing.
  539. STARTING DEBUG MODE *debug-mode*
  540. To enter debugging mode use one of these methods:
  541. 1. Start Vim with the |-D| argument: >
  542. vim -D file.txt
  543. < Debugging will start as soon as the first vimrc file is sourced. This is
  544. useful to find out what is happening when Vim is starting up. A side
  545. effect is that Vim will switch the terminal mode before initialisations
  546. have finished, with unpredictable results.
  547. For a GUI-only version (Windows) the debugging will start as
  548. soon as the GUI window has been opened. To make this happen early, add a
  549. ":gui" command in the vimrc file.
  550. *:debug*
  551. 2. Run a command with ":debug" prepended. Debugging will only be done while
  552. this command executes. Useful for debugging a specific script or user
  553. function. And for scripts and functions used by autocommands. Example: >
  554. :debug edit test.txt.gz
  555. 3. Set a breakpoint in a sourced file or user function. You could do this in
  556. the command line: >
  557. vim -c "breakadd file */explorer.vim" .
  558. < This will run Vim and stop in the first line of the "explorer.vim" script.
  559. Breakpoints can also be set while in debugging mode.
  560. In debugging mode every executed command is displayed before it is executed.
  561. Comment lines, empty lines and lines that are not executed are skipped. When
  562. a line contains two commands, separated by "|", each command will be displayed
  563. separately.
  564. DEBUG MODE
  565. Once in debugging mode, the usual Ex commands can be used. For example, to
  566. inspect the value of a variable: >
  567. echo idx
  568. When inside a user function, this will print the value of the local variable
  569. "idx". Prepend "g:" to get the value of a global variable: >
  570. echo g:idx
  571. All commands are executed in the context of the current function or script.
  572. You can also set options, for example setting or resetting 'verbose' will show
  573. what happens, but you might want to set it just before executing the lines you
  574. are interested in: >
  575. :set verbose=20
  576. Commands that require updating the screen should be avoided, because their
  577. effect won't be noticed until after leaving debug mode. For example: >
  578. :help
  579. won't be very helpful.
  580. There is a separate command-line history for debug mode.
  581. The line number for a function line is relative to the start of the function.
  582. If you have trouble figuring out where you are, edit the file that defines
  583. the function in another Vim, search for the start of the function and do
  584. "99j". Replace "99" with the line number.
  585. Additionally, these commands can be used:
  586. *>cont*
  587. cont Continue execution until the next breakpoint is hit.
  588. *>quit*
  589. quit Abort execution. This is like using CTRL-C, some
  590. things might still be executed, doesn't abort
  591. everything. Still stops at the next breakpoint.
  592. *>next*
  593. next Execute the command and come back to debug mode when
  594. it's finished. This steps over user function calls
  595. and sourced files.
  596. *>step*
  597. step Execute the command and come back to debug mode for
  598. the next command. This steps into called user
  599. functions and sourced files.
  600. *>interrupt*
  601. interrupt This is like using CTRL-C, but unlike ">quit" comes
  602. back to debug mode for the next command that is
  603. executed. Useful for testing |:finally| and |:catch|
  604. on interrupt exceptions.
  605. *>finish*
  606. finish Finish the current script or user function and come
  607. back to debug mode for the command after the one that
  608. sourced or called it.
  609. *>bt*
  610. *>backtrace*
  611. *>where*
  612. backtrace Show the call stacktrace for current debugging session.
  613. bt
  614. where
  615. *>frame*
  616. frame N Goes to N backtrace level. + and - signs make movement
  617. relative. E.g., ":frame +3" goes three frames up.
  618. *>up*
  619. up Goes one level up from call stacktrace.
  620. *>down*
  621. down Goes one level down from call stacktrace.
  622. About the additional commands in debug mode:
  623. - There is no command-line completion for them, you get the completion for the
  624. normal Ex commands only.
  625. - You can shorten them, up to a single character, unless more than one command
  626. starts with the same letter. "f" stands for "finish", use "fr" for "frame".
  627. - Hitting <CR> will repeat the previous one. When doing another command, this
  628. is reset (because it's not clear what you want to repeat).
  629. - When you want to use the Ex command with the same name, prepend a colon:
  630. ":cont", ":next", ":finish" (or shorter).
  631. The backtrace shows the hierarchy of function calls, e.g.:
  632. >bt ~
  633. 3 function One[3] ~
  634. 2 Two[3] ~
  635. ->1 Three[3] ~
  636. 0 Four ~
  637. line 1: let four = 4 ~
  638. The "->" points to the current frame. Use "up", "down" and "frame N" to
  639. select another frame.
  640. In the current frame you can evaluate the local function variables. There is
  641. no way to see the command at the current line yet.
  642. DEFINING BREAKPOINTS
  643. *:breaka* *:breakadd*
  644. :breaka[dd] func [lnum] {name}
  645. Set a breakpoint in a function. Example: >
  646. :breakadd func Explore
  647. < Doesn't check for a valid function name, thus the breakpoint
  648. can be set before the function is defined.
  649. :breaka[dd] file [lnum] {name}
  650. Set a breakpoint in a sourced file. Example: >
  651. :breakadd file 43 init.vim
  652. :breaka[dd] here
  653. Set a breakpoint in the current line of the current file.
  654. Like doing: >
  655. :breakadd file <cursor-line> <current-file>
  656. < Note that this only works for commands that are executed when
  657. sourcing the file, not for a function defined in that file.
  658. The [lnum] is the line number of the breakpoint. Vim will stop at or after
  659. this line. When omitted line 1 is used.
  660. *:debug-name*
  661. {name} is a pattern that is matched with the file or function name. The
  662. pattern is like what is used for autocommands. There must be a full match (as
  663. if the pattern starts with "^" and ends in "$"). A "*" matches any sequence
  664. of characters. 'ignorecase' is not used, but "\c" can be used in the pattern
  665. to ignore case |/\c|. Don't include the () for the function name!
  666. The match for sourced scripts is done against the full file name. If no path
  667. is specified the current directory is used. Examples: >
  668. breakadd file explorer.vim
  669. matches "explorer.vim" in the current directory. >
  670. breakadd file *explorer.vim
  671. matches ".../plugin/explorer.vim", ".../plugin/iexplorer.vim", etc. >
  672. breakadd file */explorer.vim
  673. matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory.
  674. The match for functions is done against the name as it's shown in the output
  675. of ":function". For local functions this means that something like "<SNR>99_"
  676. is prepended.
  677. Note that functions are first loaded and later executed. When they are loaded
  678. the "file" breakpoints are checked, when they are executed the "func"
  679. breakpoints.
  680. DELETING BREAKPOINTS
  681. *:breakd* *:breakdel* *E161*
  682. :breakd[el] {nr}
  683. Delete breakpoint {nr}. Use |:breaklist| to see the number of
  684. each breakpoint.
  685. :breakd[el] *
  686. Delete all breakpoints.
  687. :breakd[el] func [lnum] {name}
  688. Delete a breakpoint in a function.
  689. :breakd[el] file [lnum] {name}
  690. Delete a breakpoint in a sourced file.
  691. :breakd[el] here
  692. Delete a breakpoint at the current line of the current file.
  693. When [lnum] is omitted, the first breakpoint in the function or file is
  694. deleted.
  695. The {name} must be exactly the same as what was typed for the ":breakadd"
  696. command. "explorer", "*explorer.vim" and "*explorer*" are different.
  697. LISTING BREAKPOINTS
  698. *:breakl* *:breaklist*
  699. :breakl[ist]
  700. List all breakpoints.
  701. OBSCURE
  702. *:debugg* *:debuggreedy*
  703. :debugg[reedy]
  704. Read debug mode commands from the normal input stream, instead
  705. of getting them directly from the user. Only useful for test
  706. scripts. Example: >
  707. echo 'q^Mq' | vim -e -s -c debuggreedy -c 'breakadd file script.vim' -S script.vim
  708. :0debugg[reedy]
  709. Undo ":debuggreedy": get debug mode commands directly from the
  710. user, don't use typeahead for debug commands.
  711. ==============================================================================
  712. Profiling *profile* *profiling*
  713. Profiling means that Vim measures the time that is spent on executing
  714. functions and/or scripts. The |+profile| feature is required for this.
  715. It is only included when Vim was compiled with "huge" features.
  716. You can also use the |reltime()| function to measure time. This only requires
  717. the |+reltime| feature, which is present more often.
  718. For profiling syntax highlighting see |:syntime|.
  719. For example, to profile the one_script.vim script file: >
  720. :profile start /tmp/one_script_profile
  721. :profile file one_script.vim
  722. :source one_script.vim
  723. :exit
  724. :prof[ile] start {fname} *:prof* *:profile* *E750*
  725. Start profiling, write the output in {fname} upon exit.
  726. "~/" and environment variables in {fname} will be expanded.
  727. If {fname} already exists it will be silently overwritten.
  728. The variable |v:profiling| is set to one.
  729. :prof[ile] stop
  730. Write the logfile and stop profiling.
  731. :prof[ile] pause
  732. Don't profile until the following ":profile continue". Can be
  733. used when doing something that should not be counted (e.g., an
  734. external command). Does not nest.
  735. :prof[ile] continue
  736. Continue profiling after ":profile pause".
  737. :prof[ile] func {pattern}
  738. Profile function that matches the pattern {pattern}.
  739. See |:debug-name| for how {pattern} is used.
  740. :prof[ile][!] file {pattern}
  741. Profile script file that matches the pattern {pattern}.
  742. See |:debug-name| for how {pattern} is used.
  743. This only profiles the script itself, not the functions
  744. defined in it.
  745. When the [!] is added then all functions defined in the script
  746. will also be profiled.
  747. Note that profiling only starts when the script is loaded
  748. after this command. A :profile command in the script itself
  749. won't work.
  750. :prof[ile] dump
  751. Don't wait until exiting Vim and write the current state of
  752. profiling to the log immediately.
  753. :profd[el] ... *:profd* *:profdel*
  754. Stop profiling for the arguments specified. See |:breakdel|
  755. for the arguments.
  756. You must always start with a ":profile start fname" command. The resulting
  757. file is written when Vim exits. Here is an example of the output, with line
  758. numbers prepended for the explanation:
  759. 1 FUNCTION Test2() ~
  760. 2 Called 1 time ~
  761. 3 Total time: 0.155251 ~
  762. 4 Self time: 0.002006 ~
  763. 5 ~
  764. 6 count total (s) self (s) ~
  765. 7 9 0.000096 for i in range(8) ~
  766. 8 8 0.153655 0.000410 call Test3() ~
  767. 9 8 0.000070 endfor ~
  768. 10 " Ask a question ~
  769. 11 1 0.001341 echo input("give me an answer: ") ~
  770. The header (lines 1-4) gives the time for the whole function. The "Total"
  771. time is the time passed while the function was executing. The "Self" time is
  772. the "Total" time reduced by time spent in:
  773. - other user defined functions
  774. - sourced scripts
  775. - executed autocommands
  776. - external (shell) commands
  777. Lines 7-11 show the time spent in each executed line. Lines that are not
  778. executed do not count. Thus a comment line is never counted.
  779. The Count column shows how many times a line was executed. Note that the
  780. "for" command in line 7 is executed one more time as the following lines.
  781. That is because the line is also executed to detect the end of the loop.
  782. The time Vim spends waiting for user input isn't counted at all. Thus how
  783. long you take to respond to the input() prompt is irrelevant.
  784. Profiling should give a good indication of where time is spent, but keep in
  785. mind there are various things that may clobber the results:
  786. - Real elapsed time is measured, if other processes are busy they may cause
  787. delays at unpredictable moments. You may want to run the profiling several
  788. times and use the lowest results.
  789. - If you have several commands in one line you only get one time. Split the
  790. line to see the time for the individual commands.
  791. - The time of the lines added up is mostly less than the time of the whole
  792. function. There is some overhead in between.
  793. - Functions that are deleted before Vim exits will not produce profiling
  794. information. You can check the |v:profiling| variable if needed: >
  795. :if !v:profiling
  796. : delfunc MyFunc
  797. :endif
  798. <
  799. - Profiling may give weird results on multi-processor systems, when sleep
  800. mode kicks in or the processor frequency is reduced to save power.
  801. - The "self" time is wrong when a function is used recursively.
  802. ==============================================================================
  803. Context *Context* *context*
  804. The editor state is represented by the Context concept. This includes things
  805. like the current |jumplist|, values of |registers|, and more, described below.
  806. *context-types*
  807. The following Context items are supported:
  808. "jumps" |jumplist|
  809. "regs" |registers|
  810. "bufs" |buffer-list|
  811. "gvars" |global-variable|s
  812. "sfuncs" |script-local| functions
  813. "funcs" global and |script-local| functions
  814. *context-dict*
  815. Context objects are dictionaries with the following key-value pairs:
  816. - "jumps", "regs", "bufs", "gvars":
  817. |readfile()|-style |List| representation of corresponding msgpack
  818. objects (see |msgpackdump()| and |msgpackparse()|).
  819. - "funcs" (includes |script-local| functions as well):
  820. |List| of |:function| definitions.
  821. *context-stack*
  822. An initially-empty internal Context stack is maintained by the ctx-family
  823. functions (see |ctx-functions|).
  824. vim:tw=78:ts=8:noet:ft=help:norl: