repeat.txt 42 KB

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