starting.txt 63 KB

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