starting.txt 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  1. *starting.txt* Nvim
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. Starting Vim *starting*
  4. Type |gO| to see the table of contents.
  5. ==============================================================================
  6. Nvim arguments *cli-arguments*
  7. Most often, Nvim is started to edit a single file with the command: >
  8. nvim filename
  9. More generally, Nvim is started with: >
  10. nvim [option | filename] ..
  11. Option arguments and file name arguments can be mixed, and any number of them
  12. can be given. However, watch out for options that take an argument.
  13. The following items decide how to start editing:
  14. *-file* *---*
  15. filename One or more file names. The first one will be the current
  16. file and read into the buffer. The cursor will be positioned
  17. on the first line of the buffer.
  18. To avoid a file name starting with a '-' being interpreted as
  19. an option, precede the arglist with "--", e.g.: >
  20. nvim -- -filename
  21. < All arguments after "--" are interpreted as file names, no
  22. other options or "+command" arguments can follow.
  23. *--*
  24. `-` Alias for stdin (standard input).
  25. Example: >
  26. echo text | nvim - file
  27. < "text" is read into buffer 1, "file" is opened as buffer 2.
  28. In most cases (except -s, -es, |--embed|, --headless) if stdin
  29. is not a TTY then it is read as text, so "-" is implied: >
  30. echo text | nvim file
  31. < The buffer will be marked as modified, because it contains
  32. text that needs to be saved (except for readonly |-R| mode).
  33. If you don't like that, put these lines in your init.vim: >
  34. " Don't set 'modified' when reading from stdin
  35. au StdinReadPost * set nomodified
  36. <
  37. To read stdin as Normal commands use |-s| with "-": >
  38. echo "ifoo" | nvim -s -
  39. < To read stdin as Ex commands use |-es| or |-e|: >
  40. echo "echo getpid()" | nvim -e - -V1
  41. < To open a file literally named "-", put it after "--": >
  42. echo foo | nvim -- -
  43. < To read stdin as text with |--headless| use "-".
  44. *-t* *-tag*
  45. -t {tag} A tag. "tag" is looked up in the tags file, the associated
  46. file becomes the current file, and the associated command is
  47. executed. Mostly this is used for C programs, in which case
  48. "tag" often is a function name. The effect is that the file
  49. containing that function becomes the current file and the
  50. cursor is positioned on the start of the function (see
  51. |tags|).
  52. *-q* *-qf*
  53. -q [errorfile] QuickFix mode. The file with the name [errorfile] is read
  54. and the first error is displayed. See |quickfix|.
  55. If [errorfile] is not given, the 'errorfile' option is used
  56. for the file name. See 'errorfile' for the default value.
  57. (nothing) Without one of the four items above, Vim will start editing a
  58. new buffer. It's empty and doesn't have a file name.
  59. *startup-options*
  60. The option arguments may be given in any order. Single-letter options can be
  61. combined after one dash. There can be no option arguments after the "--"
  62. argument.
  63. --help *-h* *--help* *-?*
  64. -?
  65. -h Give usage (help) message and exit.
  66. --version *-v* *--version*
  67. -v Print version information and exit. Same output as for
  68. |:version| command.
  69. *--clean*
  70. --clean Mimics a fresh install of Nvim:
  71. - Skips initializations from files and environment variables.
  72. - No 'shada' file is read or written.
  73. - Excludes user directories from 'runtimepath'
  74. - Loads builtin plugins, unlike "-u NONE -i NONE".
  75. *--noplugin*
  76. --noplugin Skip loading plugins. Resets the 'loadplugins' option.
  77. Note that the |-u| argument may also disable loading plugins:
  78. argument load vimrc files load plugins ~
  79. (nothing) yes yes
  80. -u NONE no no
  81. -u NORC no yes
  82. --noplugin yes no
  83. --startuptime {fname} *--startuptime*
  84. During startup write timing messages to the file {fname}.
  85. This can be used to find out where time is spent while loading
  86. your |config|, plugins and opening the first file.
  87. When {fname} already exists new messages are appended.
  88. *-+*
  89. +[num] The cursor will be positioned on line "num" for the first
  90. file being edited. If "num" is missing, the cursor will be
  91. positioned on the last line.
  92. *-+/*
  93. +/{pat} The cursor will be positioned on the first line containing
  94. "pat" in the first file being edited (see |pattern| for the
  95. available search patterns). The search starts at the cursor
  96. position, which can be the first line or the cursor position
  97. last used from |shada|. To force a search from the first
  98. line use "+1 +/pat".
  99. +{command} *-+c* *-c*
  100. -c {command} {command} will be executed after the first file has been
  101. read (and after autocommands and modelines for that file have
  102. been processed). "command" is interpreted as an Ex command.
  103. If the "command" contains spaces, it must be enclosed in
  104. double quotes (this depends on the shell that is used).
  105. Example: >
  106. vim "+set si" main.c
  107. vim "+find stdio.h"
  108. vim -c "set ff=dos" -c wq mine.mak
  109. <
  110. Note: You can use up to 10 "+" or "-c" arguments in a Vim
  111. command. They are executed in the order given. A "-S"
  112. argument counts as a "-c" argument as well.
  113. --cmd {command} *--cmd*
  114. {command} will be executed before processing any vimrc file.
  115. Otherwise, it acts like -c {command}. You can use up to 10 of
  116. these commands, independently from "-c" commands.
  117. *-S*
  118. -S [file] Executes Vimscript or Lua (".lua") [file] after the first file
  119. has been read. See also |:source|. If [file] is not given,
  120. defaults to "Session.vim". Equivalent to: >
  121. -c "source {file}"
  122. < Can be repeated like "-c", subject to the same limit of 10
  123. "-c" arguments. {file} cannot start with a "-".
  124. -L *-L* *-r*
  125. -r Recovery mode. Without a file name argument, a list of
  126. existing swap files is given. With a file name, a swap file
  127. is read to recover a crashed editing session. See
  128. |crash-recovery|.
  129. *-R*
  130. -R Readonly mode. The 'readonly' option will be set for all the
  131. files being edited. You can still edit the buffer, but will
  132. be prevented from accidentally overwriting a file. If you
  133. forgot that you are in View mode and did make some changes,
  134. you can overwrite a file by adding an exclamation mark to
  135. the Ex command, as in ":w!". The 'readonly' option can be
  136. reset with ":set noro" (see the options chapter, |options|).
  137. Subsequent edits will not be done in readonly mode. Calling
  138. the executable "view" has the same effect as the -R argument.
  139. The 'updatecount' option will be set to 10000, meaning that
  140. the swap file will not be updated automatically very often.
  141. See |-M| for disallowing modifications.
  142. *-m*
  143. -m Modifications not allowed to be written. The 'write' option
  144. will be reset, so that writing files is disabled. However,
  145. the 'write' option can be set to enable writing again.
  146. *-M*
  147. -M Modifications not allowed. The 'modifiable' option will be
  148. reset, so that changes are not allowed. The 'write' option
  149. will be reset, so that writing files is disabled. However,
  150. the 'modifiable' and 'write' options can be set to enable
  151. changes and writing.
  152. -e *-e* *-E*
  153. -E Start Nvim in Ex mode |gQ|, see |Ex-mode|.
  154. If stdin is not a TTY:
  155. -e reads/executes stdin as Ex commands.
  156. -E reads stdin as text (into buffer 1).
  157. -es *-es* *-Es* *-s-ex* *silent-mode*
  158. -Es Script mode, aka "silent mode", aka "batch mode". No UI,
  159. disables most prompts and messages. Unrelated to |-s|.
  160. See also |-S| to run script files.
  161. -es reads/executes stdin as Ex commands. >
  162. printf "put ='foo'\n%%print\n" | nvim -es
  163. < -Es reads stdin as text (into buffer 1). Use |-c| or "+" to
  164. send commands. >
  165. printf "foo\n" | nvim -Es +"%print"
  166. < These commands display on stdout:
  167. :list
  168. :number
  169. :print
  170. :set
  171. With |:verbose| or 'verbose', other commands display on stderr: >
  172. nvim -es +"verbose echo 'foo'"
  173. nvim -V1 -es +"echo 'foo'"
  174. <
  175. Skips user |config| unless |-u| was given.
  176. Disables |shada| unless |-i| was given.
  177. Disables swapfile (like |-n|).
  178. *-l*
  179. -l {script} [args]
  180. Executes Lua {script} non-interactively (no UI) with optional
  181. [args] after processing any preceding Nvim |cli-arguments|,
  182. then exits. Exits 1 on Lua error. See |-S| to run multiple Lua
  183. scripts without args, with a UI.
  184. *lua-args*
  185. All [args] are treated as {script} arguments and stored in the
  186. Lua `_G.arg` global table, thus "-l" ends processing of Nvim
  187. arguments. The {script} name is stored at `_G.arg[0]`.
  188. Sets 'verbose' to 1 (like "-V1"), so Lua `print()` writes to
  189. output.
  190. If {script} prints messages and doesn't cause Nvim to exit,
  191. Nvim ensures output ends with a newline.
  192. Arguments before "-l" are processed before executing {script}.
  193. This example quits before executing "foo.lua": >
  194. nvim +q -l foo.lua
  195. < This loads Lua module "bar" before executing "foo.lua": >
  196. nvim +"lua require('bar')" -l foo.lua
  197. < *lua-shebang*
  198. You can set the "shebang" of the script so that Nvim executes
  199. the script when called with "./" from a shell (remember to
  200. "chmod u+x"): >
  201. #!/usr/bin/env -S nvim -l
  202. <
  203. Skips user |config| unless |-u| was given.
  204. Disables plugins unless 'loadplugins' was set.
  205. Disables |shada| unless |-i| was given.
  206. Disables swapfile (like |-n|).
  207. *-ll*
  208. -ll {script} [args]
  209. Executes a Lua script, similarly to |-l|, but the editor is not
  210. initialized. This gives a Lua environment similar to a worker
  211. thread. See |lua-loop-threading|.
  212. Unlike `-l` no prior arguments are allowed.
  213. *-b*
  214. -b Binary mode. File I/O will only recognize <NL> to separate
  215. lines. The 'expandtab' option will be reset. The 'textwidth'
  216. option is set to 0. 'modeline' is reset. The 'binary' option
  217. is set. This is done after reading the |vimrc| but before
  218. reading any file in the arglist. See also |edit-binary|.
  219. *-A*
  220. -A Arabic mode. Sets the 'arabic' option on.
  221. *-H*
  222. -H Hebrew mode. Sets the 'rightleft' option on and the 'keymap'
  223. option to "hebrew".
  224. *-V* *verbose*
  225. -V[N] Verbose. Sets the 'verbose' option to [N] (default: 10).
  226. Messages will be given for each file that is ":source"d and
  227. for reading or writing a ShaDa file. Can be used to find
  228. out what is happening upon startup and exit.
  229. Example: >
  230. nvim -V8
  231. -V[N]{file}
  232. Like -V and sets 'verbosefile' to {file} (must not start with
  233. a digit). Messages are not displayed, instead they are
  234. written to {file}.
  235. Example: >
  236. nvim -V20vimlog
  237. <
  238. *-D*
  239. -D Debugging. Go to debugging mode when executing the first
  240. command from a script. |debug-mode|
  241. *-n*
  242. -n No |swap-file| will be used. Recovery after a crash will be
  243. impossible. Handy if you want to view or edit a file on a
  244. very slow medium (e.g., a floppy).
  245. Can also be done with ":set updatecount=0". You can switch it
  246. on again by setting the 'updatecount' option to some value,
  247. e.g., ":set uc=100".
  248. 'updatecount' is set to 0 AFTER executing commands from a
  249. vimrc file, but before the GUI initializations. Thus it
  250. overrides a setting for 'updatecount' in a vimrc file, but not
  251. in a gvimrc file. See |startup|.
  252. When you want to reduce accesses to the disk (e.g., for a
  253. laptop), don't use "-n", but set 'updatetime' and
  254. 'updatecount' to very big numbers, and type ":preserve" when
  255. you want to save your work. This way you keep the possibility
  256. for crash recovery.
  257. *-o*
  258. -o[N] Open N windows, split horizontally. If [N] is not given,
  259. one window is opened for every file given as argument. If
  260. there is not enough room, only the first few files get a
  261. window. If there are more windows than arguments, the last
  262. few windows will be editing an empty file.
  263. *-O*
  264. -O[N] Open N windows, split vertically. Otherwise, it's like -o.
  265. If both the -o and the -O option are given, the last one on
  266. the command line determines how the windows will be split.
  267. *-p*
  268. -p[N] Open N tab pages. If [N] is not given, one tab page is opened
  269. for every file given as argument. The maximum is set with
  270. 'tabpagemax' pages (default 50). If there are more tab pages
  271. than arguments, the last few tab pages will be editing an
  272. empty file. Also see |tabpage|.
  273. *-d*
  274. -d Start in |diff-mode|.
  275. *-u* *E282*
  276. -u {vimrc} The file {vimrc} is read for initializations. Most other
  277. initializations are skipped; see |initialization|.
  278. This can be used to start Vim in a special mode, with special
  279. mappings and settings. A shell alias can be used to make
  280. this easy to use. For example, in a C shell descendant: >
  281. alias vimc 'nvim -u ~/.config/nvim/c_init.vim \!*'
  282. < And in a Bash shell: >
  283. alias vimc='nvim -u ~/.config/nvim/c_init.vim'
  284. < Also consider using autocommands; see |autocommand|.
  285. When {vimrc} is "NONE" (all uppercase), all initializations
  286. from files and environment variables are skipped. Plugins and
  287. syntax highlighting are also skipped.
  288. When {vimrc} is "NORC" (all uppercase), this has the same
  289. effect as "NONE", but plugins and syntax highlighting are not
  290. skipped.
  291. *-i*
  292. -i {shada} The file {shada} is used instead of the default ShaDa
  293. file. If the name "NONE" is used (all uppercase), no ShaDa
  294. file is read or written, even if 'shada' is set or when
  295. ":rsh" or ":wsh" are used. See also |shada-file|.
  296. *-s*
  297. -s {scriptin} Read script file {scriptin}, interpreting characters as
  298. Normal-mode input. The same can be done with ":source!": >
  299. :source! {scriptin}
  300. < Reads from stdin if {scriptin} is "-": >
  301. echo "ifoo" | nvim -s -
  302. < If the end of the file is reached before Nvim exits, further
  303. characters are read from the keyboard.
  304. Does not work with |-es|. See also |complex-repeat|.
  305. *-w_nr*
  306. -w {number}
  307. -w{number} Set the 'window' option to {number}.
  308. *-w*
  309. -w {scriptout} All keys that you type are recorded in the file "scriptout",
  310. until you exit Vim. Useful to create a script file to be used
  311. with "vim -s" or ":source!". Appends to the "scriptout" file
  312. if it already exists. {scriptout} cannot start with a digit.
  313. See also |vim.on_key()|.
  314. See also |complex-repeat|.
  315. *-W*
  316. -W {scriptout} Like -w, but do not append, overwrite an existing file.
  317. *--api-info*
  318. --api-info Print msgpack-encoded |api-metadata| and exit.
  319. *--embed*
  320. --embed Use stdin/stdout as a msgpack-RPC channel, so applications can
  321. embed and control Nvim via the RPC |API|.
  322. Waits for the client ("embedder") to call |nvim_ui_attach()|
  323. before sourcing startup files and reading buffers, so that UIs
  324. can deterministically handle (display) early messages,
  325. dialogs, etc. The client can do other requests before
  326. `nvim_ui_attach` (e.g. `nvim_get_api_info` for feature-detection).
  327. During this pre-startup phase the user config is of course not
  328. available (similar to `--cmd`).
  329. Embedders _not_ using the UI protocol must pass |--headless|: >
  330. nvim --embed --headless
  331. < Then startup will continue without waiting for `nvim_ui_attach`.
  332. This is equivalent to: >
  333. nvim --headless --cmd "call stdioopen({'rpc': v:true})"
  334. <
  335. Embedders that use the UI protocol on a socket connection must
  336. pass |--listen| as well as |--embed|: >
  337. nvim --embed --listen addr
  338. < See also: |ui-startup| |channel-stdio|
  339. *--headless*
  340. --headless Start without UI, and do not wait for `nvim_ui_attach`. The
  341. builtin TUI is not used, so stdio works as an arbitrary
  342. communication channel. |channel-stdio|
  343. Also useful for scripting (tests) to see messages that would
  344. not be printed by |-es|.
  345. To detect if a UI is available, check if |nvim_list_uis()| is
  346. empty during or after |VimEnter|.
  347. To read stdin as text, "-" must be given explicitly:
  348. --headless cannot assume that stdin is just text. >
  349. echo foo | nvim --headless +"%print" +"q!" -
  350. <
  351. See also |--embed|.
  352. See also |-es|, which also disables most messages.
  353. --listen {addr} *--listen*
  354. Start |RPC| server on pipe or TCP address {addr}. Sets the
  355. primary listen address |v:servername| to {addr}. |serverstart()|
  356. To start the server on-demand with systemd, use a systemd
  357. socket unit and associated service unit running: >
  358. systemd-socket-proxyd --exit-idle-time
  359. <
  360. ==============================================================================
  361. Initialization *initialization* *startup*
  362. At startup, Nvim checks environment variables and files and sets values
  363. accordingly, proceeding as follows:
  364. 1. Set the 'shell' option *SHELL* *COMSPEC*
  365. The environment variable SHELL, if it exists, is used to set the
  366. 'shell' option. On Win32, the COMSPEC variable is used
  367. if SHELL is not set.
  368. 2. Process the arguments
  369. The options and file names from the command that start Vim are
  370. inspected.
  371. The |-V| argument can be used to display or log what happens next,
  372. useful for debugging the initializations.
  373. The |--cmd| arguments are executed.
  374. Buffers are created for all files (but not loaded yet).
  375. 3. Start a server (unless |--listen| was given) and set |v:servername|.
  376. 4. Wait for UI to connect.
  377. Nvim started with |--embed| waits for the UI to connect before
  378. proceeding to load user configuration.
  379. 5. Setup |default-mappings| and |default-autocmds|. Create |popup-menu|.
  380. 6. Enable filetype and indent plugins.
  381. This does the same as the command: >
  382. :runtime! ftplugin.vim indent.vim
  383. < Skipped if the "-u NONE" command line argument was given.
  384. 7. Load user config (execute Ex commands from files, environment, …).
  385. $VIMINIT environment variable is read as one Ex command line (separate
  386. multiple commands with '|' or <NL>).
  387. *config* *init.vim* *init.lua* *vimrc* *exrc*
  388. A file containing initialization commands is generically called
  389. a "vimrc" or config file. It can be either Vimscript ("init.vim") or
  390. Lua ("init.lua"), but not both. *E5422*
  391. See also |vimrc-intro| and |base-directories|.
  392. The config file is located at:
  393. Unix ~/.config/nvim/init.vim (or init.lua)
  394. Windows ~/AppData/Local/nvim/init.vim (or init.lua)
  395. |$XDG_CONFIG_HOME| $XDG_CONFIG_HOME/nvim/init.vim (or init.lua)
  396. If Nvim was started with "-u {file}" then {file} is used as the config
  397. and all initializations until 8. are skipped. $MYVIMRC is not set.
  398. "nvim -u NORC" can be used to skip these initializations without
  399. reading a file. "nvim -u NONE" also skips plugins and syntax
  400. highlighting. |-u|
  401. If Nvim was started with |-es| or |-Es| or |-l| all initializations until 8.
  402. are skipped.
  403. *system-vimrc* *sysinit.vim*
  404. a. The system vimrc file is read for initializations. If
  405. nvim/sysinit.vim file exists in one of $XDG_CONFIG_DIRS, it will be
  406. used. Otherwise the system vimrc file is used. The path of this file
  407. is given by the |:version| command. Usually it's "$VIM/sysinit.vim".
  408. *VIMINIT* *EXINIT* *$MYVIMRC*
  409. b. Locations searched for initializations, in order of preference:
  410. - $VIMINIT environment variable (Ex command line).
  411. - User |config|: $XDG_CONFIG_HOME/nvim/init.vim (or init.lua).
  412. - Other config: {dir}/nvim/init.vim (or init.lua) where {dir} is any
  413. directory in $XDG_CONFIG_DIRS.
  414. - $EXINIT environment variable (Ex command line).
  415. |$MYVIMRC| is set to the first valid location unless it was already
  416. set or when using $VIMINIT.
  417. c. If the 'exrc' option is on (which is NOT the default), the current
  418. directory is searched for the following files, in order of precedence:
  419. - ".nvim.lua"
  420. - ".nvimrc"
  421. - ".exrc"
  422. The first that exists is used, the others are ignored.
  423. 8. Enable filetype detection.
  424. This does the same as the command: >
  425. :runtime! filetype.lua
  426. < Skipped if ":filetype off" was called or if the "-u NONE" command line
  427. argument was given.
  428. 9. Enable syntax highlighting.
  429. This does the same as the command: >
  430. :runtime! syntax/syntax.vim
  431. < Skipped if ":syntax off" was called or if the "-u NONE" command
  432. line argument was given.
  433. 10. Load the plugin scripts. *load-plugins*
  434. This does the same as the command: >
  435. :runtime! plugin/**/*.{vim,lua}
  436. < The result is that all directories in 'runtimepath' will be searched
  437. for the "plugin" sub-directory and all files ending in ".vim" or
  438. ".lua" will be sourced (in alphabetical order per directory),
  439. also in subdirectories. First "*.vim" are sourced, then "*.lua" files,
  440. per directory.
  441. However, directories in 'runtimepath' ending in "after" are skipped
  442. here and only loaded after packages, see below.
  443. Loading plugins won't be done when:
  444. - The |'loadplugins'| option was reset in a vimrc file.
  445. - The |--noplugin| command line argument is used.
  446. - The |--clean| command line argument is used.
  447. - The "-u NONE" command line argument is used |-u|.
  448. Note that using `-c 'set noloadplugins'` doesn't work, because the
  449. commands from the command line have not been executed yet. You can
  450. use `--cmd 'set noloadplugins'` or `--cmd 'set loadplugins'` |--cmd|.
  451. Packages are loaded. These are plugins, as above, but found in the
  452. "start" directory of each entry in 'packpath'. Every plugin directory
  453. found is added in 'runtimepath' and then the plugins are sourced. See
  454. |packages|.
  455. The plugins scripts are loaded, as above, but now only the directories
  456. ending in "after" are used. Note that 'runtimepath' will have changed
  457. if packages have been found, but that should not add a directory
  458. ending in "after".
  459. 11. Set 'shellpipe' and 'shellredir'
  460. The 'shellpipe' and 'shellredir' options are set according to the
  461. value of the 'shell' option, unless they have been set before.
  462. This means that Nvim will figure out the values of 'shellpipe' and
  463. 'shellredir' for you, unless you have set them yourself.
  464. 12. Set 'updatecount' to zero, if "-n" command argument used.
  465. 13. Set binary options if the |-b| flag was given.
  466. 14. Read the |shada-file|.
  467. 15. Read the quickfix file if the |-q| flag was given, or exit on failure.
  468. 16. Open all windows
  469. When the |-o| flag was given, windows will be opened (but not
  470. displayed yet).
  471. When the |-p| flag was given, tab pages will be created (but not
  472. displayed yet).
  473. When switching screens, it happens now. Redrawing starts.
  474. If the |-q| flag was given, the first error is jumped to.
  475. Buffers for all windows will be loaded, without triggering |BufAdd|
  476. autocommands.
  477. 17. Execute startup commands
  478. If a |-t| flag was given, the tag is jumped to.
  479. Commands given with |-c| and |+cmd| are executed.
  480. The starting flag is reset, has("vim_starting") will now return zero.
  481. The |v:vim_did_enter| variable is set to 1.
  482. The |VimEnter| autocommands are executed.
  483. Saving the current state of Vim to a file ~
  484. Whenever you have changed values of options or when you have created a
  485. mapping, then you may want to save them in a vimrc file for later use. See
  486. |save-settings| about saving the current state of settings to a file.
  487. Avoiding trojan horses ~
  488. *trojan-horse*
  489. While reading the "vimrc" or the "exrc" file in the current directory, some
  490. commands can be disabled for security reasons by setting the 'secure' option.
  491. This is always done when executing the command from a tags file. Otherwise,
  492. it would be possible that you accidentally use a vimrc or tags file that
  493. somebody else created and contains nasty commands. The disabled commands are
  494. the ones that start a shell, the ones that write to a file, and ":autocmd".
  495. The ":map" commands are echoed, so you can see which keys are being mapped.
  496. If you want Vim to execute all commands in a local vimrc file, you
  497. can reset the 'secure' option in the EXINIT or VIMINIT environment variable or
  498. in the global exrc or vimrc file. This is not possible in vimrc or
  499. exrc in the current directory, for obvious reasons.
  500. On Unix systems, this only happens if you are not the owner of the
  501. vimrc file. Warning: If you unpack an archive that contains a vimrc or exrc
  502. file, it will be owned by you. You won't have the security protection. Check
  503. the vimrc file before you start Vim in that directory, or reset the 'exrc'
  504. option. Some Unix systems allow a user to do "chown" on a file. This makes
  505. it possible for another user to create a nasty vimrc and make you the owner.
  506. Be careful!
  507. When using tag search commands, executing the search command (the last
  508. part of the line in the tags file) is always done in secure mode. This works
  509. just like executing a command from a vimrc in the current directory.
  510. If Vim startup is slow ~
  511. *slow-start*
  512. If Vim takes a long time to start up, use the |--startuptime| argument to find
  513. out what happens.
  514. If you have 'shada' enabled, the loading of the ShaDa file may take a
  515. while. You can find out if this is the problem by disabling ShaDa for a
  516. moment (use the Vim argument "-i NONE", |-i|). Try reducing the number of
  517. lines stored in a register with ":set shada='20,<50,s10". |shada-file|.
  518. Troubleshooting broken configurations ~
  519. *bisect*
  520. The extreme flexibility of editors like Vim and Emacs means that any plugin or
  521. setting can affect the entire editor in ways that are not initially obvious.
  522. To find the cause of a problem in your config, you must "bisect" it:
  523. 1. Remove or disable half of your |config|.
  524. 2. Restart Nvim.
  525. 3. If the problem still occurs, goto 1.
  526. 4. If the problem is gone, restore half of the removed lines.
  527. 5. Continue narrowing your config in this way, until you find the setting or
  528. plugin causing the issue.
  529. Intro message ~
  530. *:intro*
  531. When Vim starts without a file name, an introductory message is displayed. It
  532. is removed as soon as the display is redrawn. To see the message again, use
  533. the ":intro" command. To avoid the intro message on startup, add the "I" flag
  534. to 'shortmess'.
  535. ==============================================================================
  536. $VIM and $VIMRUNTIME
  537. *$VIM*
  538. The environment variable "$VIM" is used to locate various user files for Nvim,
  539. such as the user |config|. This depends on the system, see
  540. |startup|.
  541. Nvim will try to get the value for $VIM in this order:
  542. 1. Environment variable $VIM, if it is set.
  543. 2. Path derived from the 'helpfile' option, unless it contains some
  544. environment variable too (default is "$VIMRUNTIME/doc/help.txt"). File
  545. name ("help.txt", etc.) is removed. Trailing directory names are removed,
  546. in this order: "doc", "runtime".
  547. 3. Path derived from the location of the `nvim` executable.
  548. 4. Compile-time defined installation directory (see output of ":version").
  549. After doing this once, Nvim sets the $VIM environment variable.
  550. *$VIMRUNTIME*
  551. The environment variable "$VIMRUNTIME" is used to locate various support
  552. files, such as the documentation and syntax-highlighting files. For example,
  553. the main help file is normally "$VIMRUNTIME/doc/help.txt".
  554. Nvim will try to get the value for $VIMRUNTIME in this order:
  555. 1. Environment variable $VIMRUNTIME, if it is set.
  556. 2. Directory path "$VIM/vim{version}", if it exists, where {version} is the
  557. Vim version number without '-' or '.'. For example: "$VIM/vim82".
  558. 3. Directory path "$VIM/runtime", if it exists.
  559. 4. Value of $VIM environment variable. This is for backwards compatibility
  560. with older Vim versions.
  561. 5. If "../share/nvim/runtime" exists relative to |v:progpath|, it is used.
  562. 6. Path derived from the 'helpfile' option (if it doesn't contain '$') with
  563. "doc/help.txt" removed from the end.
  564. After doing this once, Nvim sets the $VIMRUNTIME environment variable.
  565. In case you need the value of $VIMRUNTIME in a shell (e.g., for a script that
  566. greps in the help files) you might be able to use this: >
  567. VIMRUNTIME="$(nvim --clean --headless --cmd 'echo $VIMRUNTIME|q')"
  568. ==============================================================================
  569. Suspending *suspend*
  570. *CTRL-Z* *v_CTRL-Z*
  571. CTRL-Z Suspend Nvim, like ":stop".
  572. Works in Normal and in Visual mode. In Insert and
  573. Command-line mode, the CTRL-Z is inserted as a normal
  574. character. In Visual mode Nvim goes back to Normal
  575. mode.
  576. :sus[pend][!] or *:sus* *:suspend* *:st* *:stop*
  577. :st[op][!] Suspend Nvim using OS "job control"; it will continue
  578. if you make it the foreground job again. Triggers
  579. |VimSuspend| before suspending and |VimResume| when
  580. resumed.
  581. If "!" is not given and 'autowrite' is set, every
  582. buffer with changes and a file name is written out.
  583. If "!" is given or 'autowrite' is not set, changed
  584. buffers are not written, don't forget to bring Nvim
  585. back to the foreground later!
  586. In the GUI, suspending is implementation-defined.
  587. ==============================================================================
  588. Exiting *exiting*
  589. There are several ways to exit Vim:
  590. - Close the last window with `:quit`. Only when there are no changes.
  591. - Close the last window with `:quit!`. Also when there are changes.
  592. - Close all windows with `:qall`. Only when there are no changes.
  593. - Close all windows with `:qall!`. Also when there are changes.
  594. - Use `:cquit`. Also when there are changes.
  595. When using `:cquit` or when there was an error message Vim exits with exit
  596. code 1. Errors can be avoided by using `:silent!` or with `:catch`.
  597. ==============================================================================
  598. Saving settings *save-settings*
  599. Mostly you will edit your vimrc files manually. This gives you the greatest
  600. flexibility. There are a few commands to generate a vimrc file automatically.
  601. You can use these files as they are, or copy/paste lines to include in another
  602. vimrc file.
  603. *:mk* *:mkexrc*
  604. :mk[exrc] [file] Write current key mappings and changed options to
  605. [file] (default ".exrc" in the current directory),
  606. unless it already exists.
  607. :mk[exrc]! [file] Always write current key mappings and changed
  608. options to [file] (default ".exrc" in the current
  609. directory).
  610. *:mkv* *:mkvi* *:mkvimrc*
  611. :mkv[imrc][!] [file] Like ":mkexrc", but the default is ".nvimrc" in the
  612. current directory. The ":version" command is also
  613. written to the file.
  614. These commands will write ":map" and ":set" commands to a file, in such a way
  615. that when these commands are executed, the current key mappings and options
  616. will be set to the same values. The options 'columns', 'endofline',
  617. 'fileformat', 'lines', 'modified', and 'scroll' are not included, because
  618. these are terminal or file dependent.
  619. Note that the options 'binary', 'paste' and 'readonly' are included, this
  620. might not always be what you want.
  621. When special keys are used in mappings, the 'cpoptions' option will be
  622. temporarily set to its Vim default, to avoid the mappings to be
  623. misinterpreted. This makes the file incompatible with Vi, but makes sure it
  624. can be used with different terminals.
  625. Only global mappings are stored, not mappings local to a buffer.
  626. A common method is to use a default |config| file, make some modifications
  627. with ":map" and ":set" commands and write the modified file. First read the
  628. default vimrc in with a command like ":source ~piet/.vimrc.Cprogs", change
  629. the settings and then save them in the current directory with ":mkvimrc!". If
  630. you want to make this file your default |config|, move it to
  631. $XDG_CONFIG_HOME/nvim. You could also use autocommands |autocommand| and/or
  632. modelines |modeline|.
  633. *vimrc-option-example*
  634. If you only want to add a single option setting to your vimrc, you can use
  635. these steps:
  636. 1. Edit your vimrc file with Vim.
  637. 2. Play with the option until it's right. E.g., try out different values for
  638. 'guifont'.
  639. 3. Append a line to set the value of the option, using the expression register
  640. '=' to enter the value. E.g., for the 'guifont' option: >
  641. o:set guifont=<C-R>=&guifont<CR><Esc>
  642. < [<C-R> is a CTRL-R, <CR> is a return, <Esc> is the escape key]
  643. You need to escape special characters, esp. spaces.
  644. ==============================================================================
  645. Views and Sessions *views-sessions*
  646. This is introduced in sections |21.4| and |21.5| of the user manual.
  647. *View* *view-file*
  648. A View is a collection of settings that apply to one window. You can save a
  649. View and when you restore it later, the text is displayed in the same way.
  650. The options and mappings in this window will also be restored, so that you can
  651. continue editing like when the View was saved.
  652. *Session* *session-file*
  653. A Session keeps the Views for all windows, plus the global settings. You can
  654. save a Session and when you restore it later the window layout looks the same.
  655. You can use a Session to quickly switch between different projects,
  656. automatically loading the files you were last working on in that project.
  657. Views and Sessions are a nice addition to ShaDa files, which are used to
  658. remember information for all Views and Sessions together |shada-file|.
  659. You can quickly start editing with a previously saved View or Session with the
  660. |-S| argument: >
  661. vim -S Session.vim
  662. <
  663. *:mks* *:mksession*
  664. :mks[ession][!] [file] Write a Vim script that restores the current editing
  665. session.
  666. When [!] is included, an existing file is overwritten.
  667. When [file] is omitted, "Session.vim" is used.
  668. The output of ":mksession" is like ":mkvimrc", but additional commands are
  669. added to the file. Which ones depends on the 'sessionoptions' option. The
  670. resulting file, when executed with a ":source" command:
  671. 1. Restores global mappings and options, if 'sessionoptions' contains
  672. "options". Script-local mappings will not be written.
  673. 2. Restores global variables that start with an uppercase letter and contain
  674. at least one lowercase letter, if 'sessionoptions' contains "globals".
  675. 3. Closes all windows in the current tab page, except the current one; closes
  676. all tab pages except the current one (this results in currently loaded
  677. buffers to be unloaded, some may become hidden if 'hidden' is set or
  678. otherwise specified); wipes out the current buffer, if it is empty and
  679. unnamed.
  680. 4. Restores the current directory, if 'sessionoptions' contains "curdir", or
  681. sets the current directory to where the Session file is, if
  682. 'sessionoptions' contains "sesdir".
  683. 5. Restores GUI Vim window position, if 'sessionoptions' contains "winpos".
  684. 6. Restores screen size, if 'sessionoptions' contains "resize".
  685. 7. Reloads the buffer list, with the last cursor positions. If
  686. 'sessionoptions' contains "buffers" then all buffers are restored,
  687. including hidden and unloaded buffers. Otherwise, only buffers in windows
  688. are restored.
  689. 8. Restores all windows with the same layout. If 'sessionoptions' contains
  690. "help", help windows are restored. If 'sessionoptions' contains "blank",
  691. windows editing a buffer without a name will be restored.
  692. If 'sessionoptions' contains "winsize" and no (help/blank) windows were
  693. left out, the window sizes are restored (relative to the screen size).
  694. Otherwise, the windows are just given sensible sizes.
  695. 9. Restores the Views for all the windows, as with |:mkview|. But
  696. 'sessionoptions' is used instead of 'viewoptions'.
  697. 10. If a file exists with the same name as the Session file, but ending in
  698. "x.vim" (for eXtra), executes that as well. You can use `*x.vim` files to
  699. specify additional settings and actions associated with a given Session,
  700. such as creating menu items in the GUI version.
  701. After restoring the Session, the full filename of your current Session is
  702. available in the internal variable |v:this_session|.
  703. An example mapping: >
  704. :nmap <F2> :wa<Bar>exe "mksession! " .. v:this_session<CR>:so ~/sessions/
  705. This saves the current Session, and starts off the command to load another.
  706. A session includes all tab pages, unless "tabpages" was removed from
  707. 'sessionoptions'. |tab-page|
  708. The |SessionLoadPost| autocmd event is triggered after a session file is
  709. loaded/sourced.
  710. *SessionLoad-variable*
  711. While the session file is loading, the SessionLoad global variable is set to
  712. 1. Plugins can use this to postpone some work until the SessionLoadPost event
  713. is triggered.
  714. *:mkvie* *:mkview*
  715. :mkvie[w][!] [file] Write a Vim script that restores the contents of the
  716. current window.
  717. When [!] is included, an existing file is overwritten.
  718. When [file] is omitted or is a number from 1 to 9, a
  719. name is generated and 'viewdir' prepended. When the
  720. last path part of 'viewdir' does not exist, this
  721. directory is created. E.g., when 'viewdir' is
  722. "$VIM/vimfiles/view" then "view" is created in
  723. "$VIM/vimfiles".
  724. An existing file is always overwritten then. Use
  725. |:loadview| to load this view again.
  726. When [file] is the name of a file ('viewdir' is not
  727. used), a command to edit the file is added to the
  728. generated file.
  729. The output of ":mkview" contains these items:
  730. 1. The argument list used in the window. When the global argument list is
  731. used, it is reset to the global list.
  732. The index in the argument list is also restored.
  733. 2. The file being edited in the window. If there is no file, the window is
  734. made empty.
  735. 3. Restore mappings, abbreviations and options local to the window, if
  736. 'viewoptions' contains "options" or "localoptions". Only option values
  737. that are local to the current buffer and the current window are restored.
  738. When storing the view as part of a session and "options" is in
  739. 'sessionoptions', global values for local options will be stored too.
  740. 4. Restore folds when using manual folding and 'viewoptions' contains
  741. "folds". Restore manually opened and closed folds.
  742. 5. The scroll position and the cursor position in the file. Doesn't work very
  743. well when there are closed folds.
  744. 6. The local current directory, if it is different from the global current
  745. directory and 'viewoptions' contains "curdir".
  746. Note that Views and Sessions are not perfect:
  747. - They don't restore everything. For example, defined functions, autocommands
  748. and ":syntax on" are not included. Things like register contents and
  749. command line history are in ShaDa, not in Sessions or Views.
  750. - Global option values are only set when they differ from the default value.
  751. When the current value is not the default value, loading a Session will not
  752. set it back to the default value. Local options will be set back to the
  753. default value though.
  754. - Existing mappings will be overwritten without warning. An existing mapping
  755. may cause an error for ambiguity.
  756. - When storing manual folds and when storing manually opened/closed folds,
  757. changes in the file between saving and loading the view will mess it up.
  758. - The Vim script is not very efficient. But still faster than typing the
  759. commands yourself!
  760. *:lo* *:loadview*
  761. :lo[adview] [nr] Load the view for the current file. When [nr] is
  762. omitted, the view stored with ":mkview" is loaded.
  763. When [nr] is specified, the view stored with ":mkview
  764. [nr]" is loaded.
  765. The combination of ":mkview" and ":loadview" can be used to store up to ten
  766. different views of a file. These are remembered in the directory specified
  767. with the 'viewdir' option. The views are stored using the file name. If a
  768. file is renamed or accessed through a (symbolic) link, the view will not be
  769. found.
  770. You might want to clean up your 'viewdir' directory now and then.
  771. To automatically save and restore views for `*.c` files: >
  772. au BufWinLeave *.c mkview
  773. au BufWinEnter *.c silent! loadview
  774. ==============================================================================
  775. Shada ("shared data") file *shada* *shada-file*
  776. If you exit Vim and later start it again, you would normally lose a lot of
  777. information. The ShaDa file can be used to remember that information, which
  778. enables you to continue where you left off. Its name is the abbreviation of
  779. SHAred DAta because it is used for sharing data between Nvim sessions.
  780. This is introduced in section |21.3| of the user manual.
  781. The ShaDa file is used to store:
  782. - The command line history.
  783. - The search string history.
  784. - The input-line history.
  785. - Contents of non-empty registers.
  786. - Marks for several files.
  787. - File marks, pointing to locations in files.
  788. - Last search/substitute pattern (for 'n' and '&').
  789. - The buffer list.
  790. - Global variables.
  791. You could also use a Session file. The difference is that the ShaDa file
  792. does not depend on what you are working on. There normally is only one
  793. ShaDa file. Session files are used to save the state of a specific editing
  794. Session. You could have several Session files, one for each project you are
  795. working on. ShaDa and Session files together can be used to effectively
  796. enter Vim and directly start working in your desired setup. |session-file|
  797. *shada-read*
  798. When Vim is started and the 'shada' option is non-empty, the contents of
  799. the ShaDa file are read and the info can be used in the appropriate places.
  800. The |v:oldfiles| variable is filled. The marks are not read in at startup
  801. (but file marks are). See |initialization| for how to set the 'shada'
  802. option upon startup.
  803. *shada-write*
  804. When Vim exits and 'shada' is non-empty, the info is stored in the ShaDa file
  805. (it's actually merged with the existing one, if one exists |shada-merging|).
  806. The 'shada' option is a string containing information about what info should
  807. be stored, and contains limits on how much should be stored (see 'shada').
  808. Notes for Unix:
  809. - The file protection for the ShaDa file will be set to prevent other users
  810. from being able to read it, because it may contain any text or commands that
  811. you have worked with.
  812. - If you want to share the ShaDa file with other users (e.g. when you "su"
  813. to another user), you can make the file writable for the group or everybody.
  814. Vim will preserve this when writing new ShaDa files. Be careful, don't
  815. allow just anybody to read and write your ShaDa file!
  816. - Vim will not overwrite a ShaDa file that is not writable by the current
  817. "real" user. This helps for when you did "su" to become root, but your
  818. $HOME is still set to a normal user's home directory. Otherwise, Vim would
  819. create a ShaDa file owned by root that nobody else can read.
  820. - The ShaDa file cannot be a symbolic link. This is to avoid security
  821. issues.
  822. Marks are stored for each file separately. When a file is read and 'shada'
  823. is non-empty, the marks for that file are read from the ShaDa file. NOTE:
  824. The marks are only written when exiting Vim, which is fine because marks are
  825. remembered for all the files you have opened in the current editing session,
  826. unless ":bdel" is used. If you want to save the marks for a file that you are
  827. about to abandon with ":bdel", use ":wsh". The '[' and ']' marks are not
  828. stored, but the '"' mark is. The '"' mark is very useful for jumping to the
  829. cursor position when the file was last exited. No marks are saved for files
  830. that start with any string given with the "r" flag in 'shada'. This can be
  831. used to avoid saving marks for files on removable media (for MS-Windows you
  832. would use "ra:,rb:").
  833. The |v:oldfiles| variable is filled with the file names that the ShaDa file
  834. has marks for.
  835. *shada-file-marks*
  836. Uppercase marks ('A to 'Z) are stored when writing the ShaDa file. The
  837. numbered marks ('0 to '9) are a bit special. When the ShaDa file is written
  838. (when exiting or with the |:wshada| command), '0 is set to the current cursor
  839. position and file. The old '0 is moved to '1, '1 to '2, etc. This
  840. resembles what happens with the "1 to "9 delete registers. If the current
  841. cursor position is already present in '0 to '9, it is moved to '0, to avoid
  842. having the same position twice. The result is that with "'0", you can jump
  843. back to the file and line where you exited Vim. To do that right away, try
  844. using this command: >
  845. vim -c "normal '0"
  846. In a C shell descendant, you could make an alias for it: >
  847. alias lvim vim -c '"'normal "'"0'"'
  848. For a Bash-like shell: >
  849. alias lvim='vim -c "normal '\''0"'
  850. Use the "r" flag in 'shada' to specify for which files no marks should be
  851. remembered.
  852. MERGING *shada-merging*
  853. When writing ShaDa files with |:wshada| without bang or at regular exit
  854. information in the existing ShaDa file is merged with information from current
  855. Nvim instance. For this purpose ShaDa files store timestamps associated
  856. with ShaDa entries. Specifically the following is being done:
  857. 1. History lines are merged, ordered by timestamp. Maximum amount of items in
  858. ShaDa file is defined by 'shada' option (|shada-/|, |shada-:|, |shada-@|,
  859. etc: one suboption for each character that represents history name
  860. (|:history|)).
  861. 2. Local marks and changes for files that were not opened by Nvim are copied
  862. to new ShaDa file. Marks for files that were opened by Nvim are merged,
  863. changes to files opened by Nvim are ignored. |shada-'|
  864. 3. Jump list is merged: jumps are ordered by timestamp, identical jumps
  865. (identical position AND timestamp) are squashed.
  866. 4. Search patterns and substitute strings are not merged: search pattern or
  867. substitute string which has greatest timestamp will be the only one copied
  868. to ShaDa file.
  869. 5. For each register entity with greatest timestamp is the only saved.
  870. |shada-<|
  871. 6. All saved variables are saved from current Nvim instance. Additionally
  872. existing variable values are copied, meaning that the only way to remove
  873. variable from a ShaDa file is either removing it by hand or disabling
  874. writing variables completely. |shada-!|
  875. 7. For each global mark entity with greatest timestamp is the only saved.
  876. 8. Buffer list and header are the only entries which are not merged in any
  877. fashion: the only header and buffer list present are the ones from the
  878. Nvim instance which was last writing the file. |shada-%|
  879. COMPATIBILITY *shada-compatibility*
  880. ShaDa files are forward and backward compatible. This means that
  881. 1. Entries which have unknown type (i.e. that hold unidentified data) are
  882. ignored when reading and blindly copied when writing.
  883. 2. Register entries with unknown register name are ignored when reading and
  884. blindly copied when writing. Limitation: only registers that use name with
  885. code in interval [1, 255] are supported. |registers|
  886. 3. Register entries with unknown register type are ignored when reading and
  887. merged as usual when writing. |getregtype()|
  888. 4. Local and global mark entries with unknown mark names are ignored when
  889. reading. When writing global mark entries are blindly copied and local mark
  890. entries are also blindly copied, but only if file they are attached to fits
  891. in the |shada-'| limit. Unknown local mark entry's timestamp is also taken
  892. into account when calculating which files exactly should fit into this
  893. limit. Limitation: only marks that use name with code in interval [1, 255]
  894. are supported. |mark-motions|
  895. 5. History entries with unknown history type are ignored when reading and
  896. blindly copied when writing. Limitation: there can be only up to 256
  897. history types. |history|
  898. 6. Unknown keys found in register, local mark, global mark, change, jump and
  899. search pattern entries are saved internally and dumped when writing.
  900. Entries created during Nvim session never have such additions.
  901. 7. Additional elements found in replacement string and history entries are
  902. saved internally and dumped. Entries created during Nvim session never
  903. have such additions.
  904. 8. Additional elements found in variable entries are simply ignored when
  905. reading. When writing new variables they will be preserved during merging,
  906. but that's all. Variable values dumped from current Nvim session never
  907. have additional elements, even if variables themselves were obtained by
  908. reading ShaDa files.
  909. "Blindly" here means that there will be no attempts to somehow merge them,
  910. even if other entries (with known name/type/etc) are merged. |shada-merging|
  911. SHADA FILE NAME *shada-file-name*
  912. - Default name of the |shada| file is:
  913. Unix: "$XDG_STATE_HOME/nvim/shada/main.shada"
  914. Windows: "$XDG_STATE_HOME/nvim-data/shada/main.shada"
  915. See also |base-directories|.
  916. - To choose a different file name you can use:
  917. - The "n" flag in the 'shada' option.
  918. - The |-i| startup argument. "NONE" means no shada file is ever read or
  919. written. Also not for the commands below!
  920. - The 'shadafile' option. The value from the "-i" argument (if any) is
  921. stored in the 'shadafile' option.
  922. - For the commands below, another file name can be given, overriding the
  923. default and the name given with 'shada' or "-i" (unless it's NONE).
  924. MANUALLY READING AND WRITING *shada-read-write*
  925. Two commands can be used to read and write the ShaDa file manually. This
  926. can be used to exchange registers between two running Vim programs: First
  927. type ":wsh" in one and then ":rsh" in the other. Note that if the register
  928. already contained something, then ":rsh!" would be required. Also note,
  929. however, that this means everything will be overwritten with information from
  930. the first Vim, including the command line history, etc.
  931. The ShaDa file itself can be edited by hand too, although we suggest you
  932. start with an existing one to get the format right. You need to understand
  933. MessagePack (or, more likely, find software that is able to use it) format to
  934. do this. This can be useful in order to create a second file, say
  935. "~/.my.shada", which could contain certain settings that you always want when
  936. you first start Nvim. For example, you can preload registers with
  937. particular data, or put certain commands in the command line history. A line
  938. in your |config| file like >
  939. :rshada! ~/.my.shada
  940. can be used to load this information. You could even have different ShaDa
  941. files for different types of files (e.g., C code) and load them based on the
  942. file name, using the ":autocmd" command (see |:autocmd|). More information on
  943. ShaDa file format is contained in |shada-format| section.
  944. *E136* *E929* *shada-error-handling*
  945. Some errors make Nvim leave temporary file named `{basename}.tmp.X` (X is
  946. any free letter from `a` to `z`) while normally it will create this file,
  947. write to it and then rename `{basename}.tmp.X` to `{basename}`. Such errors
  948. include:
  949. - Errors which make Nvim think that the file being read is not a ShaDa
  950. file at all:
  951. non-ShaDa files are not overwritten for safety reasons to avoid accidentally
  952. destroying an unrelated file. This could happen e.g. when typing "nvim -i
  953. file" in place of "nvim -R file" (yes, somebody did that at least with Vim).
  954. Such errors are listed at |shada-critical-contents-errors|.
  955. - If writing to the temporary file failed: e.g. because of the insufficient
  956. space left.
  957. - If renaming file failed: e.g. because of insufficient permissions.
  958. - If target ShaDa file has different from the Nvim instance's owners (user
  959. and group) and changing them failed. Unix-specific, applies only when
  960. Nvim was launched from root.
  961. Do not forget to remove the temporary file or replace the target file with
  962. temporary one after getting one of the above errors or all attempts to create
  963. a ShaDa file may fail with |E929|. If you got one of them when using
  964. |:wshada| (and not when exiting Nvim: i.e. when you have Nvim session
  965. running) you have additional options:
  966. - First thing which you should consider if you got any error, except failure
  967. to write to the temporary file: remove existing file and replace it with the
  968. temporary file. Do it even if you have running Nvim instance.
  969. - Fix the permissions and/or file ownership, free some space and attempt to
  970. write again. Do not remove the existing file.
  971. - Use |:wshada| with bang. Does not help in case of permission error. If
  972. target file was actually the ShaDa file some information may be lost in this
  973. case. To make the matters slightly better use |:rshada| prior to writing,
  974. but this still will loose buffer-local marks and change list entries for any
  975. file which is not opened in the current Nvim instance.
  976. - Remove the target file from shell and use |:wshada|. Consequences are not
  977. different from using |:wshada| with bang, but "rm -f" works in some cases
  978. when you don't have write permissions.
  979. *:rsh* *:rshada* *E886*
  980. :rsh[ada][!] [file] Read from ShaDa file [file] (default: see above).
  981. If [!] is given, then any information that is
  982. already set (registers, marks, |v:oldfiles|, etc.)
  983. will be overwritten.
  984. *:wsh* *:wshada* *E137*
  985. :wsh[ada][!] [file] Write to ShaDa file [file] (default: see above).
  986. The information in the file is first read in to make
  987. a merge between old and new info. When [!] is used,
  988. the old information is not read first, only the
  989. internal info is written (also disables safety checks
  990. described in |shada-error-handling|). If 'shada' is
  991. empty, marks for up to 100 files will be written.
  992. When you get error "E929: All .tmp.X files exist,
  993. cannot write ShaDa file!", check that no old temp
  994. files were left behind (e.g.
  995. ~/.local/state/nvim/shada/main.shada.tmp*).
  996. Note: Executing :wshada will reset all |'quote| marks.
  997. *:o* *:ol* *:oldfiles*
  998. :o[ldfiles] List the files that have marks stored in the ShaDa
  999. file. This list is read on startup and only changes
  1000. afterwards with `:rshada!`. Also see |v:oldfiles|.
  1001. The number can be used with |c_#<|.
  1002. The output can be filtered with |:filter|, e.g.: >
  1003. filter /\.vim/ oldfiles
  1004. < The filtering happens on the file name.
  1005. :bro[wse] o[ldfiles][!]
  1006. List file names as with |:oldfiles|, and then prompt
  1007. for a number. When the number is valid that file from
  1008. the list is edited.
  1009. If you get the |press-enter| prompt you can press "q"
  1010. and still get the prompt to enter a file number.
  1011. Use [!] to abandon a modified buffer. |abandon|
  1012. SHADA FILE FORMAT *shada-format*
  1013. ShaDa files are concats of MessagePack entries. Each entry is a concat of
  1014. exactly four MessagePack objects:
  1015. 1. First goes type of the entry. Object type must be an unsigned integer.
  1016. Object type must not be equal to zero.
  1017. 2. Second goes entry timestamp. It must also be an unsigned integer.
  1018. 3. Third goes the length of the fourth entry. Unsigned integer as well, used
  1019. for fast skipping without parsing.
  1020. 4. Fourth is actual entry data. All currently used ShaDa entries use
  1021. containers to hold data: either map or array. All string values in those
  1022. containers are either binary (applies to filenames) or UTF-8, yet parser
  1023. needs to expect that invalid bytes may be present in a UTF-8 string.
  1024. Exact format depends on the entry type:
  1025. Entry type (name) Entry data ~
  1026. 1 (Header) Map containing data that describes the generator
  1027. instance that wrote this ShaDa file. It is ignored
  1028. when reading ShaDa files. Contains the following data:
  1029. Key Data ~
  1030. generator Binary, software used to generate ShaDa
  1031. file. Is equal to "nvim" when ShaDa file was
  1032. written by Nvim.
  1033. version Binary, generator version.
  1034. encoding Binary, effective 'encoding' value.
  1035. max_kbyte Integer, effective |shada-s| limit value.
  1036. pid Integer, instance process ID.
  1037. `*` It is allowed to have any number of
  1038. additional keys with any data.
  1039. 2 (SearchPattern) Map containing data describing last used search or
  1040. substitute pattern. Normally ShaDa file contains two
  1041. such entries: one with "ss" key set to true (describes
  1042. substitute pattern, see |:substitute|), and one set to
  1043. false (describes search pattern, see
  1044. |search-commands|). "su" key should be true on one of
  1045. the entries. If key value is equal to default then it
  1046. is normally not present. Keys:
  1047. Key Type Default Description ~
  1048. sm Boolean true Effective 'magic' value.
  1049. sc Boolean false Effective 'smartcase' value.
  1050. sl Boolean true True if search pattern comes
  1051. with a line offset. See
  1052. |search-offset|.
  1053. se Boolean false True if |search-offset|
  1054. requested to place cursor at
  1055. (relative to) the end of the
  1056. pattern.
  1057. so Integer 0 Offset value. |search-offset|
  1058. su Boolean false True if current entry was the
  1059. last used search pattern.
  1060. ss Boolean false True if current entry describes
  1061. |:substitute| pattern.
  1062. sh Boolean false True if |v:hlsearch| is on.
  1063. With |shada-h| or 'nohlsearch'
  1064. this key is always false.
  1065. sp Binary N/A Actual pattern. Required.
  1066. sb Boolean false True if search direction is
  1067. backward.
  1068. `*` any none Other keys are allowed for
  1069. compatibility reasons, see
  1070. |shada-compatibility|.
  1071. 3 (SubString) Array containing last |:substitute| replacement string.
  1072. Contains single entry: binary, replacement string used.
  1073. More entries are allowed for compatibility reasons, see
  1074. |shada-compatibility|.
  1075. 4 (HistoryEntry) Array containing one entry from history. Should have
  1076. two or three entries. First one is history type
  1077. (unsigned integer), second is history line (binary),
  1078. third is the separator character (unsigned integer,
  1079. must be in interval [0, 255]). Third item is only
  1080. valid for search history. Possible history types are
  1081. listed in |hist-names|, here are the corresponding
  1082. numbers: 0 - cmd, 1 - search, 2 - expr, 3 - input,
  1083. 4 - debug.
  1084. 5 (Register) Map describing one register (|registers|). If key
  1085. value is equal to default then it is normally not
  1086. present. Keys:
  1087. Key Type Def Description ~
  1088. rt UInteger 0 Register type:
  1089. No Description ~
  1090. 0 |charwise-register|
  1091. 1 |linewise-register|
  1092. 2 |blockwise-register|
  1093. rw UInteger 0 Register width. Only valid
  1094. for |blockwise-register|s.
  1095. rc Array of binary N/A Register contents. Each
  1096. entry in the array
  1097. represents its own line.
  1098. NUL characters inside the
  1099. line should be represented
  1100. as NL according to
  1101. |NL-used-for-Nul|.
  1102. ru Boolean false Unnamed register. Whether
  1103. the unnamed register had
  1104. pointed to this register.
  1105. n UInteger N/A Register name: character
  1106. code in range [1, 255].
  1107. Example: |quote0| register
  1108. has name 48 (ASCII code for
  1109. zero character).
  1110. * any none Other keys are allowed
  1111. for compatibility reasons,
  1112. see |shada-compatibility|.
  1113. 6 (Variable) Array containing two items: variable name (binary) and
  1114. variable value (any object). Values are converted
  1115. using the same code |msgpackparse()| uses when reading,
  1116. |msgpackdump()| when writing, so there may appear
  1117. |msgpack-special-dict|s. If there are more then two
  1118. entries then the rest are ignored
  1119. (|shada-compatibility|).
  1120. 7 (GlobalMark)
  1121. 8 (Jump)
  1122. 10 (LocalMark)
  1123. 11 (Change) Map containing some position description:
  1124. Entry Position ~
  1125. GlobalMark Global mark position. |'A|
  1126. LocalMark Local mark position. |'a|
  1127. Jump One position from the |jumplist|.
  1128. Change One position from the |changelist|.
  1129. Data contained in the map:
  1130. Key Type Default Description ~
  1131. l UInteger 1 Position line number. Must be
  1132. greater then zero.
  1133. c UInteger 0 Position column number.
  1134. n UInteger 34 ('"') Mark name. Only valid for
  1135. GlobalMark and LocalMark
  1136. entries.
  1137. f Binary N/A File name. Required.
  1138. `*` any none Other keys are allowed for
  1139. compatibility reasons, see
  1140. |shada-compatibility|.
  1141. 9 (BufferList) Array containing maps. Each map in the array
  1142. represents one buffer. Possible keys:
  1143. Key Type Default Description ~
  1144. l UInteger 1 Position line number. Must be
  1145. greater then zero.
  1146. c UInteger 0 Position column number.
  1147. f Binary N/A File name. Required.
  1148. `*` any none Other keys are allowed for
  1149. compatibility reasons, see
  1150. |shada-compatibility|.
  1151. `*` (Unknown) Any other entry type is allowed for compatibility
  1152. reasons, see |shada-compatibility|.
  1153. *E575* *E576*
  1154. Errors in ShaDa file may have two types:
  1155. 1. E575 for “logical” errors.
  1156. 2. E576 for “critical” errors.
  1157. When writing, critical errors trigger behaviour described in
  1158. |shada-error-handling|.
  1159. When reading, critical errors cause the rest of the file to be skipped.
  1160. Critical errors include:
  1161. *shada-critical-contents-errors*
  1162. - Any of first three MessagePack objects being not an unsigned integer.
  1163. - Third object requesting amount of bytes greater then bytes left in the ShaDa
  1164. file.
  1165. - Entry with zero type. I.e. first object being equal to zero.
  1166. - MessagePack parser failing to parse the entry data.
  1167. - MessagePack parser consuming less or requesting greater bytes then described
  1168. in the third object for parsing fourth object. I.e. when fourth object
  1169. either contains more then one MessagePack object or it does not contain
  1170. complete MessagePack object.
  1171. ==============================================================================
  1172. Standard Paths *standard-path*
  1173. Nvim stores configuration, data, and logs in standard locations. Plugins are
  1174. strongly encouraged to follow this pattern also. Use |stdpath()| to get the
  1175. paths.
  1176. *base-directories* *xdg*
  1177. The "base" (root) directories conform to the XDG Base Directory Specification.
  1178. https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
  1179. The $XDG_CONFIG_HOME, $XDG_DATA_HOME, $XDG_RUNTIME_DIR, $XDG_STATE_HOME,
  1180. $XDG_CACHE_HOME, $XDG_CONFIG_DIRS and $XDG_DATA_DIRS environment variables
  1181. are used if defined, else default values (listed below) are used.
  1182. Throughout the help pages these defaults are used as placeholders, e.g.
  1183. "~/.config" is understood to mean "$XDG_CONFIG_HOME or ~/.config".
  1184. CONFIG DIRECTORY (DEFAULT) ~
  1185. *$XDG_CONFIG_HOME* Nvim: stdpath("config")
  1186. Unix: ~/.config ~/.config/nvim
  1187. Windows: ~/AppData/Local ~/AppData/Local/nvim
  1188. DATA DIRECTORY (DEFAULT) ~
  1189. *$XDG_DATA_HOME* Nvim: stdpath("data")
  1190. Unix: ~/.local/share ~/.local/share/nvim
  1191. Windows: ~/AppData/Local ~/AppData/Local/nvim-data
  1192. RUN DIRECTORY (DEFAULT) ~
  1193. *$XDG_RUNTIME_DIR* Nvim: stdpath("run")
  1194. Unix: /tmp/nvim.user/xxx /tmp/nvim.user/xxx
  1195. Windows: $TMP/nvim.user/xxx $TMP/nvim.user/xxx
  1196. STATE DIRECTORY (DEFAULT) ~
  1197. *$XDG_STATE_HOME* Nvim: stdpath("state")
  1198. Unix: ~/.local/state ~/.local/state/nvim
  1199. Windows: ~/AppData/Local ~/AppData/Local/nvim-data
  1200. CACHE DIRECTORY (DEFAULT) ~
  1201. *$XDG_CACHE_HOME* Nvim: stdpath("cache")
  1202. Unix: ~/.cache ~/.cache/nvim
  1203. Windows: ~/AppData/Local/Temp ~/AppData/Local/Temp/nvim-data
  1204. LOG FILE (DEFAULT) ~
  1205. `$NVIM_LOG_FILE` Nvim: stdpath("log")/log
  1206. Unix: ~/.local/state/nvim ~/.local/state/nvim/log
  1207. Windows: ~/AppData/Local/nvim-data ~/AppData/Local/nvim-data/log
  1208. Note that stdpath("log") is currently an alias for stdpath("state").
  1209. ADDITIONAL CONFIGS DIRECTORY (DEFAULT) ~
  1210. *$XDG_CONFIG_DIRS* Nvim: stdpath("config_dirs")
  1211. Unix: /etc/xdg/ /etc/xdg/nvim
  1212. Windows: Not applicable Not applicable
  1213. ADDITIONAL DATA DIRECTORY (DEFAULT) ~
  1214. *$XDG_DATA_DIRS* Nvim: stdpath("data_dirs")
  1215. Unix: /usr/local/share /usr/local/share/nvim
  1216. /usr/share /usr/share/nvim
  1217. Windows: Not applicable Not applicable
  1218. NVIM_APPNAME *$NVIM_APPNAME*
  1219. The standard directories can be further configured by the `$NVIM_APPNAME`
  1220. environment variable. This variable controls the sub-directory that Nvim will
  1221. read from (and auto-create) in each of the base directories. For example,
  1222. setting `$NVIM_APPNAME` to "foo" before starting will cause Nvim to look for
  1223. configuration files in `$XDG_CONFIG_HOME/foo` instead of
  1224. `$XDG_CONFIG_HOME/nvim`. `$NVIM_APPNAME` must be a name, such as "foo", or a
  1225. relative path, such as "foo/bar".
  1226. One use-case for $NVIM_APPNAME is to "isolate" Nvim applications.
  1227. Alternatively, for true isolation, on Linux you can use cgroups namespaces: >
  1228. systemd-run --user -qt -p PrivateUsers=yes -p BindPaths=/home/user/profile_xy:/home/user/.config/nvim nvim
  1229. Note: Throughout the help pages, wherever `$XDG_CONFIG_…/nvim` is mentioned it
  1230. is understood to mean `$XDG_CONFIG_…/$NVIM_APPNAME`.
  1231. LOG FILE *log* *$NVIM_LOG_FILE* *E5430*
  1232. Besides 'debug' and 'verbose', Nvim keeps a general log file for internal
  1233. debugging, plugins and RPC clients. >
  1234. :echo $NVIM_LOG_FILE
  1235. By default, the file is located at stdpath("log")/log ($XDG_STATE_HOME/nvim/log)
  1236. unless that path is inaccessible or if $NVIM_LOG_FILE was set before |startup|.
  1237. vim:noet:tw=78:ts=8:ft=help:norl: