robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
70.8 KiB1806 linesraw
1*editing.txt*   Nvim
2
3
4		  VIM REFERENCE MANUAL	  by Bram Moolenaar
5
6
7Editing files						*edit-files*
8
9                                      Type |gO| to see the table of contents.
10
11==============================================================================
12Introduction						*edit-intro*
13
14Editing a file with Vim means:
15
161. reading the file into a buffer
172. changing the buffer with editor commands
183. writing the buffer into a file
19
20							*current-file*
21As long as you don't write the buffer, the original file remains unchanged.
22If you start editing a file (read a file into the buffer), the file name is
23remembered as the "current file name".  This is also known as the name of the
24current buffer.  It can be used with "%" on the command line |:_%|.
25
26							*alternate-file*
27If there already was a current file name, then that one becomes the alternate
28file name.  It can be used with "#" on the command line |:_#| and you can use
29the |CTRL-^| command to toggle between the current and the alternate file.
30However, the alternate file name is not changed when |:keepalt| is used.
31An alternate file name is remembered for each window.
32
33							*:keepa* *:keepalt*
34:keepa[lt] {cmd}	Execute {cmd} while keeping the current alternate file
35			name.  Note that commands invoked indirectly (e.g.,
36			with a function) may still set the alternate file
37			name.
38
39All file names are remembered in the buffer list.  When you enter a file name,
40for editing (e.g., with ":e filename") or writing (e.g., with ":w filename"),
41the file name is added to the list.  You can use the buffer list to remember
42which files you edited and to quickly switch from one file to another (e.g.,
43to copy text) with the |CTRL-^| command.  First type the number of the file
44and then hit CTRL-^.
45
46
47CTRL-G		or				*CTRL-G* *:f* *:fi* *:file*
48:f[ile]			Prints the current file name (as typed, unless ":cd"
49			was used), the cursor position (unless the 'ruler'
50			option is set), and the file status (readonly,
51			modified, read errors, new file).  See the 'shortmess'
52			option about how to make this message shorter.
53
54:f[ile]!		like |:file|, but don't truncate the name even when
55			'shortmess' indicates this.
56
57{count}CTRL-G		Like CTRL-G, but prints the current file name with
58			full path.  If the count is higher than 1 the current
59			buffer number is also given.
60
61					*g_CTRL-G* *word-count* *byte-count*
62g CTRL-G		Prints the current position of the cursor in five
63			ways: Column, Line, Word, Character and Byte.  If the
64			number of Characters and Bytes is the same then the
65			Character position is omitted.
66
67			If there are characters in the line that take more
68			than one position on the screen (<Tab> or special
69			character), or characters using more than one byte per
70			column (characters above 0x7F when 'encoding' is
71			utf-8), both the byte column and the screen column are
72			shown, separated by a dash.
73
74			Also see the 'ruler' option and the |wordcount()|
75			function.
76
77							*v_g_CTRL-G*
78{Visual}g CTRL-G	Similar to "g CTRL-G", but Word, Character, Line, and
79			Byte counts for the visually selected region are
80			displayed.
81			In Blockwise mode, Column count is also shown.  (For
82			{Visual} see |Visual-mode|.)
83
84							*:file_f*
85:f[ile][!] {name}	Sets the current file name to {name}.  The optional !
86			avoids truncating the message, as with |:file|.
87			If the buffer did have a name, that name becomes the
88			|alternate-file| name.  An unlisted buffer is created
89			to hold the old name.
90
91			See |nvim_buf_set_name()| to avoid filename escaping.
92
93							*:0file*
94:0f[ile][!]		Remove the name of the current buffer.  The optional !
95			avoids truncating the message, as with |:file|.
96
97:buffers
98:files
99:ls			List all the currently known file names.  See
100			|windows.txt| |:files| |:buffers| |:ls|.
101
102Vim will remember the full path name of a file name that you enter.  In most
103cases when the file name is displayed only the name you typed is shown, but
104the full path name is being used if you used the ":cd" command |:cd|.
105
106							*home-replace*
107If the environment variable $HOME is set, and the file name starts with that
108string, it is often displayed with HOME replaced with "~".  This was done to
109keep file names short.  When reading or writing files the full name is still
110used, the "~" is only used when displaying file names.  When replacing the
111file name would result in just "~", "~/" is used instead (to avoid confusion
112between options set to $HOME with 'backupext' set to "~").
113
114When writing the buffer, the default is to use the current file name.  Thus
115when you give the "ZZ" or ":wq" command, the original file will be
116overwritten.  If you do not want this, the buffer can be written into another
117file by giving a file name argument to the ":write" command.  For example: >
118
119	vim testfile
120	[change the buffer with editor commands]
121	:w newfile
122	:q
123
124This will create a file "newfile", that is a modified copy of "testfile".
125The file "testfile" will remain unchanged.  Anyway, if the 'backup' option is
126set, Vim renames or copies the original file before it will be overwritten.
127You can use this file if you discover that you need the original file.  See
128also the 'patchmode' option.  The name of the backup file is normally the same
129as the original file with 'backupext' appended.  The default "~" is a bit
130strange to avoid accidentally overwriting existing files.  If you prefer
131".bak" change the 'backupext' option.  The backup file can be placed in
132another directory by setting 'backupdir'.
133
134When you started editing without giving a file name, "No File" is displayed in
135messages.  If the ":write" command is used with a file name argument, the file
136name for the current file is set to that file name.  This only happens when
137the 'F' flag is included in 'cpoptions' (by default it is included) |cpo-F|.
138This is useful when entering text in an empty buffer and then writing it to a
139file.  If 'cpoptions' contains the 'f' flag (by default it is NOT included)
140|cpo-f| the file name is set for the ":read file" command.  This is useful
141when starting Vim without an argument and then doing ":read file" to start
142editing a file.
143When the file name was set and 'filetype' is empty the filetype detection
144autocommands will be triggered.
145							*not-edited*
146Because the file name was set without really starting to edit that file, you
147are protected from overwriting that file.  This is done by setting the
148"notedited" flag.  You can see if this flag is set with the CTRL-G or ":file"
149command.  It will include "[Not edited]" when the "notedited" flag is set.
150When writing the buffer to the current file name (with ":w!"), the "notedited"
151flag is reset.
152
153							*abandon*
154Vim remembers whether you have changed the buffer.  You are protected from
155losing the changes you made.  If you try to quit without writing, or want to
156start editing another file, Vim will refuse this.  In order to overrule this
157protection, add a '!' to the command.  The changes will then be lost.  For
158example: ":q" will not work if the buffer was changed, but ":q!" will.  To see
159whether the buffer was changed use the "CTRL-G" command.  The message includes
160the string "[Modified]" if the buffer has been changed, or "+" if the 'm' flag
161is in 'shortmess'.
162
163If you want to automatically save the changes without asking, switch on the
164'autowriteall' option.  'autowrite' is the associated Vi-compatible option
165that does not work for all commands.
166
167If you want to keep the changed buffer without saving it, switch on the
168'hidden' option.  See |hidden-buffer|.  Some commands work like this even when
169'hidden' is not set, check the help for the command.
170
171==============================================================================
172Editing a file						*edit-a-file*
173
174							*:e* *:edit* *reload*
175:e[dit][!] [++opt] [+cmd]
176			Edit the current file.  This is useful to re-edit the
177			current file, when it has been changed outside of Vim.
178							*:edit!* *discard*
179			If [!] is given, unsaved changes in the current buffer
180			are discarded. Without [!] the command fails if there
181			are unsaved changes, unless 'autowriteall' is set and
182			the file can be written.
183			Also see |++opt| and |+cmd|.
184
185							*:edit_f*
186:e[dit][!] [++opt] [+cmd] {file}
187			Edit {file}.
188							*:edit!_f*
189			If [!] is given, unsaved changes in the current buffer
190			are discarded. Without [!] the command fails if there
191			are unsaved changes, unless 'hidden' is set or
192			'autowriteall' is set and the file can be written.
193			Also see |++opt| and |+cmd|.
194
195							*:edit_#* *:e#*
196:e[dit] [++opt] [+cmd] #[count]
197			Edit the [count]th buffer (as shown by |:files|).
198			This command does the same as [count] CTRL-^.  But ":e
199			#" doesn't work if the alternate buffer doesn't have a
200			file name, while CTRL-^ still works then.
201			Also see |++opt| and |+cmd|.
202
203							*:ene* *:enew*
204:ene[w]			Edit a new, unnamed buffer.  This fails when changes
205			have been made to the current buffer, unless 'hidden'
206			is set or 'autowriteall' is set and the file can be
207			written.
208			If 'fileformats' is not empty, the first format given
209			will be used for the new buffer.  If 'fileformats' is
210			empty, the 'fileformat' of the current buffer is used.
211
212							*:ene!* *:enew!*
213:ene[w]!		Edit a new, unnamed buffer.  Discard any changes to
214			the current buffer.
215			Set 'fileformat' like |:enew|.
216
217							*:fin* *:find*
218:fin[d][!] [++opt] [+cmd] {file}
219			Find {file} in 'path' and then |:edit| it.
220			See also: 'findfunc'.
221
222:{count}fin[d][!] [++opt] [+cmd] {file}
223			Just like ":find", but use the {count} match in
224			'path'.  Thus ":2find file" will find the second
225			"file" found in 'path'.  When there are fewer matches
226			for the file in 'path' than asked for, you get an
227			error message.
228
229							*:ex*
230:ex [++opt] [+cmd] [file]
231			Same as |:edit|.
232
233							*:vi* *:visual*
234:vi[sual][!] [++opt] [+cmd] [file]
235			When used in Ex mode: Leave |Ex-mode|, go back to
236			Normal mode.  Otherwise same as |:edit|.
237
238							*:vie* *:view*
239:vie[w][!] [++opt] [+cmd] file
240			When used in Ex mode: Leave |Ex-mode|, go back to
241			Normal mode.  Otherwise same as |:edit|, but set
242			'readonly' option for this buffer.
243
244							*CTRL-^* *CTRL-6*
245CTRL-^			Edit the alternate file.  Mostly the alternate file is
246			the previously edited file.  This is a quick way to
247			toggle between two files.  It is equivalent to ":e #",
248			except that it also works when there is no file name.
249
250			If the 'autowrite' or 'autowriteall' option is on and
251			the buffer was changed, write it.
252			Mostly the ^ character is positioned on the 6 key,
253			pressing CTRL and 6 then gets you what we call CTRL-^.
254			But on some non-US keyboards CTRL-^ is produced in
255			another way.
256
257{count}CTRL-^		Edit [count]th file in the buffer list (equivalent to
258			":e #[count]").  This is a quick way to switch between
259			files.
260			See |CTRL-^| above for further details.
261
262							*gf* *E446* *E447*
263[count]gf		Edit the filename at (or after) cursor.
264			Mnemonic: "goto file".
265
266			- The 'isfname' option decides what a filename is.
267			  Trailing punctuation characters ".,:;!" are ignored.
268			  Escaped spaces "\ " are reduced to a single space.
269			- The 'path' option decides where to look for the
270			  file, including relative directories and wildcards.
271			- The 'suffixesadd' option controls which suffixes
272			  (file extensions) are tried when building potential
273			  filepaths.
274			- If the search fails, it is retried after applying
275			  'includeexpr' to the filename.
276			- If a [count] is given, the count'th file that is
277			  found in the 'path' is edited.
278			- If the name is a URL ("type://machine/path"), it is
279			  handled by $VIMRUNTIME/plugin/net.lua
280			- Environment variables are expanded. |expand-env|.
281			- On unix: "~" is expanded.
282
283			This command fails if Vim refuses to |abandon| the
284			current file.
285			See |CTRL-W_CTRL-F| to edit the file in a new window.
286
287			If you do want to edit a new file, use: >
288				:e <cfile>
289<
290
291							*v_gf*
292{Visual}[count]gf	Same as "gf", but the highlighted text is used as the
293			name of the file to edit.  'isfname' is ignored.
294			Leading blanks are skipped, otherwise all blanks and
295			special characters are included in the file name.
296			(For {Visual} see |Visual-mode|.)
297
298							*gF*
299[count]gF		Same as "gf", except if a number follows the file
300			name, then the cursor is positioned on that line in
301			the file.
302			The file name and the number must be separated by a
303			non-filename (see 'isfname') and non-numeric
304			character.  " line " is also recognized, like it is
305			used in the output of `:verbose command UserCmd`
306			White space between the filename, the separator and
307			the number is ignored.
308			Examples:
309				eval.c:10 ~
310				eval.c @ 20 ~
311				eval.c (30) ~
312				eval.c 40 ~
313				eval.c line 50 ~
314
315							*v_gF*
316{Visual}[count]gF	Same as "v_gf", but if a colon and a number appear
317			immediately after the end of the selected text,
318			then the cursor is positioned on that line in the
319			file.  Unlike |gF|, only a colon is recognized as
320			separator.
321
322These commands are used to start editing a single file.  This means that the
323file is read into the buffer and the current file name is set.  The file that
324is opened depends on the current directory, see |:cd|.
325
326See |read-messages| for an explanation of the message that is given after the
327file has been read.
328
329You can use the ":e!" command if you messed up the buffer and want to start
330all over again.  The ":e" command is only useful if you have changed the
331current file name.
332
333							*:filename* *{file}*
334Besides the things mentioned here, more special items for where a filename is
335expected are mentioned at |cmdline-special|.
336
337When using a command that accepts a single file name (like ":edit file")
338spaces in the file name are allowed, but trailing spaces are ignored.
339Example: The command ":e   Long File Name " will edit the file "Long File
340Name".  When using a command that accepts more than one file name (like ":next
341file1 file2") embedded spaces must be escaped with a backslash.
342
343						*wildcard* *wildcards*
344Wildcards in {file} are expanded, but as with file completion, 'wildignore'
345and 'suffixes' apply.  Which wildcards are supported depends on the system.
346These are the common ones:
347	`?`	matches one character
348	`*`	matches anything, including nothing
349	`**`	matches anything, including nothing, recurses into directories
350	[abc]	match 'a', 'b' or 'c'
351
352To avoid the special meaning of the wildcards prepend a backslash.  However,
353on MS-Windows the backslash is a path separator and "path\[abc]" is still seen
354as a wildcard when "[" is in the 'isfname' option.  A simple way to avoid this
355is to use "path\[[]abc]", this matches the file "path\[abc]".
356
357					*starstar-wildcard*
358Expanding "**" is possible on Unix, Win32, macOS and a few other systems (but
359it may depend on your 'shell' setting on Unix and macOS.  It's known to work
360correctly for zsh; for bash this requires at least bash version >= 4.X).
361This allows searching a directory tree.  This goes up to 100 directories deep.
362Note there are some commands where this works slightly differently, see
363|file-searching|.
364Example: >
365	:n **/*.txt
366Finds files: >
367	aaa.txt
368	subdir/bbb.txt
369	a/b/c/d/ccc.txt
370When non-wildcard characters are used right before or after "**" these are
371only matched in the top directory.  They are not used for directories further
372down in the tree.  For example: >
373	:n /usr/inc**/types.h
374Finds files: >
375	/usr/include/types.h
376	/usr/include/sys/types.h
377	/usr/inc/old/types.h
378Note that the path with "/sys" is included because it does not need to match
379"/inc".  Thus it's like matching "/usr/inc*/*/*...", not
380"/usr/inc*/inc*/inc*".
381
382					*backtick-expansion* *`-expansion*
383On Unix and a few other systems you can also use backticks for the file name
384argument, for example: >
385	:next `find . -name ver\\*.c -print`
386	:view `ls -t *.patch  \| head -n1`
387Vim will run the command in backticks using the 'shell' and use the standard
388output as argument for the given Vim command (error messages from the shell
389command will be discarded).
390To see what shell command Vim is running, set the 'verbose' option to 4.  When
391the shell command returns a non-zero exit code, an error message will be
392displayed and the Vim command will be aborted.  To avoid this make the shell
393always return zero like so: >
394       :next `find . -name ver\\*.c -print \|\| true`
395
396The backslashes before the star are required to prevent the shell from
397expanding "ver*.c" prior to execution of the find program.  The backslash
398before the shell pipe symbol "|" prevents Vim from parsing it as command
399termination.
400This also works for most other systems, with the restriction that the
401backticks must be around the whole item.  It is not possible to have text
402directly before the first or just after the last backtick.
403
404							*`=*
405You can have the backticks expanded as a Vim expression, instead of as an
406external command, by putting an equal sign right after the first backtick,
407e.g.: >
408	:e `=tempname()`
409The expression can contain just about anything, thus this can also be used to
410avoid the special meaning of '"', "|", '%' and '#'.  However, 'wildignore'
411does apply like to other wildcards.
412
413Environment variables in the expression are expanded when evaluating the
414expression, thus this works: >
415	:e `=$HOME .. '/.vimrc'`
416This uses $HOME inside a string and it will be used literally, most likely not
417what you intended: >
418	:e `='$HOME' .. '/.vimrc'`
419
420If the expression returns a string then names are to be separated with line
421breaks.  When the result is a |List| then each item is used as a name.  Line
422breaks also separate names.
423Note that such expressions are only supported in places where a filename is
424expected as an argument to an Ex-command.
425
426							*++opt* *[++opt]*
427The [++opt] argument can be used to set some options for one command, and to
428specify the behavior for bad characters.  The form is: >
429	++{optname}
430Or: >
431	++{optname}={value}
432
433Where {optname} is one of:	    *++ff* *++enc* *++bin* *++nobin* *++edit*
434    ff     or  fileformat   overrides 'fileformat'
435    enc    or  encoding	    overrides 'fileencoding'
436    bin    or  binary	    sets 'binary'
437    nobin  or  nobinary	    resets 'binary'
438    bad			    specifies behavior for bad characters
439    edit		    for |:read|: keeps options as if editing a file
440    p			    for |:write|: creates the file's parent directory
441
442{value} cannot contain whitespace.  It can be any valid value for the options.
443Examples: >
444	:e ++ff=unix
445This edits the same file again with 'fileformat' set to "unix". >
446
447	:w ++enc=latin1 newfile
448This writes the current buffer to "newfile" in latin1 format.
449
450The message given when writing a file will show "[converted]" when
451'fileencoding' or the value specified with ++enc differs from 'encoding'.
452
453There may be several ++opt arguments, separated by whitespace.  They must all
454appear before any |+cmd| argument.
455
456								*++p*
457The "++p" flag creates the parent directory of the file if it does not exist.
458For example if you edit "foo/bar/file.txt", the ":write ++p" command creates
459"foo/bar/" if necessary before writing the file. >
460
461	:edit foo/bar/file.txt
462	:write ++p
463
464If you want :write (without "++p") to always create missing parent
465directories, add this autocmd to your config: >
466
467	" Auto-create parent directories (except for URIs "://").
468	au BufWritePre,FileWritePre * if @% !~# '\(://\)' | call mkdir(expand('<afile>:p:h'), 'p') | endif
469<
470
471								*++bad*
472The argument of "++bad=" specifies what happens with characters that can't be
473converted and illegal bytes.  It can be one of three things:
474    ++bad=X      A single-byte character that replaces each bad character.
475    ++bad=keep   Keep bad characters without conversion.  Note that this may
476		 result in illegal bytes in your text!
477    ++bad=drop   Remove the bad characters.
478
479The default is like "++bad=?": Replace each bad character with a question
480mark.  In some places an inverted question mark is used (0xBF).
481
482Note that not all commands use the ++bad argument, even though they do not
483give an error when you add it.  E.g. |:write|.
484
485Note that when reading, the 'fileformat' and 'fileencoding' options will be
486set to the used format.  When writing this doesn't happen, thus a next write
487will use the old value of the option.  Same for the 'binary' option.
488
489
490							*+cmd* *[+cmd]*
491The [+cmd] argument can be used to position the cursor in the newly opened
492file, or execute any other command:
493	+		Start at the last line.
494	+{num}		Start at line {num}.
495	+/{pat}		Start at first line containing {pat}.
496	+{command}	Execute {command} after opening the new file.
497			{command} is any Ex command.
498To include a white space in the {pat} or {command}, precede it with a
499backslash.  Double the number of backslashes. >
500	:edit  +/The\ book	     file
501	:edit  +/dir\ dirname\\      file
502	:edit  +set\ dir=c:\\\\temp  file
503Note that in the last example the number of backslashes is halved twice: Once
504for the "+cmd" argument and once for the ":set" command.
505
506							*file-formats*
507The 'fileformat' option sets the <EOL> style for a file:
508'fileformat'    characters	   name				~
509  "dos"		<CR><NL> or <NL>   DOS format		*DOS-format*
510  "unix"	<NL>		   Unix format		*Unix-format*
511  "mac"		<CR>		   Mac format		*Mac-format*
512
513When reading a file, the mentioned characters are interpreted as the <EOL>.
514In DOS format (default for Windows), <CR><NL> and <NL> are both interpreted as
515the <EOL>. Note that when writing the file in DOS format, <CR> characters will
516be added for each single <NL>.  Also see |file-read|.
517
518When writing a file, the mentioned characters are used for <EOL>.  For DOS
519format <CR><NL> is used.  Also see |DOS-format-write|.
520
521You can read a file in DOS format and write it in Unix format.  This will
522replace all <CR><NL> pairs by <NL> (assuming 'fileformats' includes "dos"): >
523	:e file
524	:set fileformat=unix
525	:w
526If you read a file in Unix format and write with DOS format, all <NL>
527characters will be replaced with <CR><NL> (assuming 'fileformats' includes
528"unix"): >
529	:e file
530	:set fileformat=dos
531	:w
532
533If you start editing a new file and the 'fileformats' option is not empty
534(which is the default), Vim will try to detect whether the lines in the file
535are separated by the specified formats.  When set to "unix,dos", Vim will
536check for lines with a single <NL> (as used on Unix) or by a <CR><NL> pair
537(MS-Windows).  Only when ALL lines end in <CR><NL>, 'fileformat' is
538set to "dos", otherwise it is set to "unix".  When 'fileformats' includes
539"mac", and no <NL> characters are found in the file, 'fileformat' is set to
540"mac".
541
542If the 'fileformat' option is set to "dos" on non-MS-Windows systems the
543message "[dos]" is shown to remind you that something unusual is happening.  On
544MS-Windows systems you get the message "[unix]" if 'fileformat' is set to
545"unix".  On all systems you get the message "[mac]" if 'fileformat' is set to
546"mac".
547
548If the 'fileformats' option is empty and DOS format is used, but while reading
549a file some lines did not end in <CR><NL>, "[CR missing]" will be included in
550the file message.
551If the 'fileformats' option is empty and Mac format is used, but while reading
552a file a <NL> was found, "[NL missing]" will be included in the file message.
553
554If the new file does not exist, the 'fileformat' of the current buffer is used
555when 'fileformats' is empty.  Otherwise the first format from 'fileformats' is
556used for the new file.
557
558Before editing binary, executable or Vim script files you should set the
559'binary' option.  A simple way to do this is by starting Vim with the "-b"
560option.  This will avoid the use of 'fileformat'.  Without this you risk that
561single <NL> characters are unexpectedly replaced with <CR><NL>.
562
563END-OF-LINE AND END-OF-FILE				*eol-and-eof*
564
565Vim has several options to control the file format:
566	'fileformat'	the <EOL> style: Unix, DOS, Mac
567	'endofline'	whether the last line ends with a <EOL>
568	'endoffile'	whether the file ends with a CTRL-Z
569	'fixendofline'	whether to fix eol and eof
570
571The first three values are normally detected automatically when reading the
572file and are used when writing the text to a file.  While editing the buffer
573it looks like every line has a line ending and the CTRL-Z isn't there (an
574exception is when 'binary' is set, it works differently then).
575
576The 'fixendofline' option can be used to choose what to write.  You can also
577change the option values to write the file differently than how it was read.
578
579Here are some examples how to use them.
580
581If you want files in Unix format (every line NL terminated): >
582	setl ff=unix fixeol
583You should probably do this on any Unix-like system.  Also modern MS-Windows
584systems tend to work well with this.  It is recommended to always use this
585format for Vim scripts.
586
587If you want to use an old MS-DOS file in a modern environment, fixing line
588endings and dropping CTRL-Z, but keeping the <CR><NL> style <EOL>: >
589	setl ff=dos fixeol
590This is useful for many MS-Windows programs, they regularly expect the
591<CR><NL> line endings.
592
593If you want to drop the final <EOL> and add a final CTRL-Z (e.g. for an old
594system like CP/M): >
595	setl ff=dos nofixeol noeol eof
596
597If you want to preserve the fileformat exactly as-is, including any final
598<EOL> and final CTRL-Z: >
599	setl nofixeol
600
601OPENING FILES PROGRAMMATICALLY			      *buffer-open* *open-file*
602
603When a plugin already has a literal filepath (e.g. from a picker, LSP result,
604or filesystem scan) and just wants to open it, |:edit| is the wrong tool: its
605argument is subject to |cmdline-special| expansion, |wildcard| expansion, etc.
606|fnameescape()| escapes only some of these, and may depend on 'isfname'.
607
608Instead, to open a filepath literally, use `bufadd(vim.fs.normalize(…))`: >lua
609	local buf = vim.fn.bufadd(vim.fs.normalize(path))
610	-- Set 'buflisted'; trigger BufReadPre/BufReadPost/FileType.
611	vim.api.nvim_buf_call(buf, vim.cmd.edit)
612
613Alternatively, |nvim_cmd()| and |vim.cmd()| accept a structured form whose
614`args` are tokenized verbatim. But the argument still goes through |:edit|'s
615filename-expansion phase, so some parts of `path` are still expanded: >lua
616	vim.cmd{ cmd = 'edit',
617	  args = { path },
618	  magic = { file = false, bar = false },
619	}
620<
621
622==============================================================================
623The argument list				*argument-list* *arglist*
624
625If you give more than one file name when starting Vim, this list is remembered
626as the argument list.  You can jump to each file in this list.
627
628Do not confuse this with the buffer list, which you can see with the
629|:buffers| command.  The argument list was already present in Vi, the buffer
630list is new in Vim.  Every file name in the argument list will also be present
631in the buffer list (unless it was deleted with |:bdel| or |:bwipe|).  But it's
632common that names in the buffer list are not in the argument list.
633
634This subject is introduced in section |07.2| of the user manual.
635
636There is one global argument list, which is used for all windows by default.
637It is possible to create a new argument list local to a window, see
638|:arglocal|.
639
640You can use the argument list with the following commands, and with the
641expression functions |argc()| and |argv()|.  These all work on the argument
642list of the current window.
643
644							*:ar* *:arg* *:args*
645:ar[gs]			Print the argument list, with the current file in
646			square brackets.
647
648:ar[gs] [++opt] [+cmd] {arglist}			*:args_f*
649			Define {arglist} as the new argument list and edit
650			the first one.  This fails when changes have been made
651			and Vim does not want to |abandon| the current buffer.
652			Also see |++opt| and |+cmd|.
653
654:ar[gs]! [++opt] [+cmd] {arglist}			*:args_f!*
655			Define {arglist} as the new argument list and edit
656			the first one.  Discard any changes to the current
657			buffer.
658			Also see |++opt| and |+cmd|.
659
660:[count]arge[dit][!] [++opt] [+cmd] {name} ...		*:arge* *:argedit*
661			Add {name}s to the argument list and edit it.
662			There is no check for duplicates, it is possible to
663			add a file to the argument list twice |:argded|.
664			This is like using |:argadd| and then |:edit| (with
665			the small exception that |:edit| does not change the
666			argument list, so the argument list pointer isn't
667			changed).
668			Spaces in filenames have to be escaped with "\".
669			[count] is used like with |:argadd|.
670			If the current file cannot be |abandon|ed {name}s will
671			still be added to the argument list, but won't be
672			edited.  No check for duplicates is done.
673			Also see |++opt| and |+cmd|.
674
675:[count]arga[dd] {name} ...			*:arga* *:argadd* *E479*
676:[count]arga[dd]						*E1156*
677			Add the {name}s to the argument list.  When {name} is
678			omitted add the current buffer name to the argument
679			list.
680			If [count] is omitted, the {name}s are added just
681			after the current entry in the argument list.
682			Otherwise they are added after the [count]'th file.
683			If the argument list is "a b c", and "b" is the
684			current argument, then these commands result in:
685				command		new argument list ~
686				:argadd x	a  [b]  x  c
687				:0argadd x	x   a  [b] c
688				:1argadd x	a   x  [b] c
689				:$argadd x	a  [b]  c  x
690			And after the last one:
691				:+2argadd y	a  [b]  c  x  y
692			There is no check for duplicates, it is possible to
693			add a file to the argument list twice.  You can use
694			|:argdedupe| to fix it afterwards: >
695				:argadd *.txt | argdedupe
696<			The currently edited file is not changed.
697			Note: you can also use this method: >
698				:args ## x
699<			This will add the "x" item and sort the new list.
700
701:argded[upe]					*:argded* *:argdedupe*
702			Remove duplicate filenames from the argument list.
703			If your current file is a duplicate, your current file
704			will change to the original file index.
705
706:argd[elete] {pattern} ...		*:argd* *:argdelete* *E480* *E610*
707			Delete files from the argument list that match the
708			{pattern}s.  {pattern} is used like a file pattern,
709			see |file-pattern|.  "%" can be used to delete the
710			current entry.
711			This command keeps the currently edited file, also
712			when it's deleted from the argument list.
713			Example: >
714				:argdel *.obj
715
716:[range]argd[elete]	Delete the [range] files from the argument list.
717			Example: >
718				:10,$argdel
719<			Deletes arguments 10 and further, keeping 1-9. >
720				:$argd
721<			Deletes just the last one. >
722				:argd
723				:.argd
724<			Deletes the current argument. >
725				:%argd
726<			Removes all the files from the arglist.
727			When the last number in the range is too high, up to
728			the last argument is deleted.
729
730							*:argu* *:argument*
731:[count]argu[ment] [count] [++opt] [+cmd]
732			Edit file [count] in the argument list.  When [count]
733			is omitted the current entry is used.  This fails
734			when changes have been made and Vim does not want to
735			|abandon| the current buffer.
736			Also see |++opt| and |+cmd|.
737
738:[count]argu[ment]! [count] [++opt] [+cmd]
739			Edit file [count] in the argument list, discard any
740			changes to the current buffer.  When [count] is
741			omitted the current entry is used.
742			Also see |++opt| and |+cmd|.
743
744:[count]n[ext] [++opt] [+cmd]			*:n* *:ne* *:next* *E165* *E163*
745			Edit [count] next file.  This fails when changes have
746			been made and Vim does not want to |abandon| the
747			current buffer.  Also see |++opt| and |+cmd|.
748
749								*]a*
750]a			Mapped to |:next|. |default-mappings|
751
752:[count]n[ext]! [++opt] [+cmd]
753			Edit [count] next file, discard any changes to the
754			buffer.  Also see |++opt| and |+cmd|.
755
756:n[ext] [++opt] [+cmd] {arglist}			*:next_f*
757			Same as |:args_f|.
758
759:n[ext]! [++opt] [+cmd] {arglist}
760			Same as |:args_f!|.
761
762:[count]N[ext] [count] [++opt] [+cmd]			*:Next* *:N* *E164*
763			Edit [count] previous file in argument list.  This
764			fails when changes have been made and Vim does not
765			want to |abandon| the current buffer.
766			Also see |++opt| and |+cmd|.
767
768:[count]N[ext]! [count] [++opt] [+cmd]
769			Edit [count] previous file in argument list.  Discard
770			any changes to the buffer.  Also see |++opt| and
771			|+cmd|.
772
773:[count]prev[ious] [count] [++opt] [+cmd]		*:prev* *:previous*
774			Same as :Next.  Also see |++opt| and |+cmd|.
775
776							*[a*
777[a			Mapped to |:previous|. |default-mappings|
778
779							*:rew* *:rewind*
780:rew[ind] [++opt] [+cmd]
781			Start editing the first file in the argument list.
782			This fails when changes have been made and Vim does
783			not want to |abandon| the current buffer.
784			Also see |++opt| and |+cmd|.
785
786								*[A*
787[A			Mapped to |:rewind|. |default-mappings|
788
789:rew[ind]! [++opt] [+cmd]
790			Start editing the first file in the argument list.
791			Discard any changes to the buffer.  Also see |++opt|
792			and |+cmd|.
793
794							*:fir* *:first*
795:fir[st][!] [++opt] [+cmd]
796			Other name for ":rewind".
797
798							*:la* *:last*
799:la[st] [++opt] [+cmd]
800			Start editing the last file in the argument list.
801			This fails when changes have been made and Vim does
802			not want to |abandon| the current buffer.
803			Also see |++opt| and |+cmd|.
804
805								*]A*
806]A			Mapped to |:last|. |default-mappings|
807
808:la[st]! [++opt] [+cmd]
809			Start editing the last file in the argument list.
810			Discard any changes to the buffer.  Also see |++opt|
811			and |+cmd|.
812
813							*:wn* *:wnext*
814:[count]wn[ext] [++opt]
815			Write current file and start editing the [count]
816			next file.  Also see |++opt| and |+cmd|.
817
818:[count]wn[ext] [++opt] {file}
819			Write current file to {file} and start editing the
820			[count] next file, unless {file} already exists and
821			the 'writeany' option is off.  Also see |++opt| and
822			|+cmd|.
823
824:[count]wn[ext]! [++opt] {file}
825			Write current file to {file} and start editing the
826			[count] next file.  Also see |++opt| and |+cmd|.
827
828:[count]wN[ext][!] [++opt] [file]		*:wN* *:wNext*
829:[count]wp[revious][!] [++opt] [file]		*:wp* *:wprevious*
830			Same as :wnext, but go to previous file instead of
831			next.
832
833The [count] in the commands above defaults to one.  For some commands it is
834possible to use two counts.  The last one (rightmost one) is used.
835
836If no [+cmd] argument is present, the cursor is positioned at the last known
837cursor position for the file.  If 'startofline' is set, the cursor will be
838positioned at the first non-blank in the line, otherwise the last know column
839is used.  If there is no last known cursor position the cursor will be in the
840first line (the last line in Ex mode).
841
842							*{arglist}*
843The wildcards in the argument list are expanded and the file names are sorted.
844Thus you can use the command `vim *.c` to edit all the C files.  From within
845Vim the command `:n *.c` does the same.
846
847White space is used to separate file names.  Put a backslash before a space or
848tab to include it in a file name.  E.g., to edit the single file "foo bar": >
849	:next foo\ bar
850
851On Unix and a few other systems you can also use backticks, for example: >
852	:next `find . -name \\*.c -print`
853The backslashes before the star are required to prevent "*.c" to be expanded
854by the shell before executing the find program.
855
856							*arglist-position*
857When there is an argument list you can see which file you are editing in the
858title of the window (if there is one and 'title' is on) and with the file
859message you get with the "CTRL-G" command.  You will see something like
860	(4 of 11)
861If you are not really editing the file at the current position in the argument
862list it will be
863	((4) of 11)
864This means that you are position 4 in the argument list, but not editing the
865fourth file in the argument list.  This happens when you do ":e file".
866
867
868LOCAL ARGUMENT LIST
869
870							*:arglocal*
871:argl[ocal]		Make a local copy of the global argument list.
872			Doesn't start editing another file.
873
874:argl[ocal][!] [++opt] [+cmd] {arglist}
875			Define a new argument list, which is local to the
876			current window.  Works like |:args_f| otherwise.
877
878							*:argglobal*
879:argg[lobal]		Use the global argument list for the current window.
880			Doesn't start editing another file.
881
882:argg[lobal][!] [++opt] [+cmd] {arglist}
883			Use the global argument list for the current window.
884			Define a new global argument list like |:args_f|.
885			All windows using the global argument list will see
886			this new list.
887
888There can be several argument lists.  They can be shared between windows.
889When they are shared, changing the argument list in one window will also
890change it in the other window.
891
892When a window is split the new window inherits the argument list from the
893current window.  The two windows then share this list, until one of them uses
894|:arglocal| or |:argglobal| to use another argument list.
895
896
897USING THE ARGUMENT LIST
898
899						*:argdo*
900:[range]argdo[!] {cmd}	Execute {cmd} for each file in the argument list or,
901			if [range] is specified, only for arguments in that
902			range.  It works like doing this: >
903				:rewind
904				:{cmd}
905				:next
906				:{cmd}
907				etc.
908<			When the current file can't be |abandon|ed and the [!]
909			is not present, the command fails.
910			When an error is detected on one file, further files
911			in the argument list will not be visited.
912			The last file in the argument list (or where an error
913			occurred) becomes the current file.
914			{cmd} can contain '|' to concatenate several commands.
915			{cmd} must not change the argument list.
916			Note: While this command is executing, the Syntax
917			autocommand event is disabled by adding it to
918			'eventignore'.  This considerably speeds up editing
919			each file.
920			Also see |:windo|, |:tabdo|, |:bufdo|, |:cdo|, |:ldo|,
921			|:cfdo| and |:lfdo|.
922
923Example: >
924	:args *.c
925	:argdo set ff=unix | update
926This sets the 'fileformat' option to "unix" and writes the file if it is now
927changed.  This is done for all `*.c` files.
928
929Example: >
930	:args *.[ch]
931	:argdo %s/\<my_foo\>/My_Foo/ge | update
932This changes the word "my_foo" to "My_Foo" in all "*.c" and "*.h" files.  The "e"
933flag is used for the ":substitute" command to avoid an error for files where
934"my_foo" isn't used.  ":update" writes the file only if changes were made.
935
936==============================================================================
937Writing						*writing* *save-file*
938
939Note: When the 'write' option is off, you are not able to write any file.
940
941							*:w* *:write*
942					*E502* *E503* *E504* *E505*
943					*E512* *E514* *E667* *E949*
944:w[rite] [++opt]	Write the whole buffer to the current file.  This is
945			the normal way to save changes to a file.  Fails when
946			'readonly' is set or when there is another reason why
947			the file can't be written, such as when the parent
948			directory doesn't exist (use |++p| to avoid that).
949			For ++opt see |++opt|, but only ++p, ++bin, ++nobin,
950			++ff and ++enc are effective.
951
952
953:w[rite]! [++opt]	Like ":write", but forcefully write when 'readonly' is
954			set or there is another reason why writing was
955			refused.
956			Note: This may change the permission and ownership of
957			the file and break (symbolic) links.  Add the 'W' flag
958			to 'cpoptions' to avoid this.
959
960:[range]w[rite][!] [++opt]
961			Write the specified lines to the current file.  This
962			is unusual, because the file will not contain all
963			lines in the buffer.
964
965							*:w_f* *:write_f*
966:[range]w[rite] [++opt]	{file}
967			Write the specified lines to {file}, unless it
968			already exists and the 'writeany' option is off.
969
970							*:w!*
971:[range]w[rite]! [++opt] {file}
972			Write the specified lines to {file}.  Overwrite an
973			existing file.
974
975						*:w_a* *:write_a* *E494*
976:[range]w[rite][!] [++opt] >>
977			Append the specified lines to the current file.
978
979:[range]w[rite][!] [++opt] >> {file}
980			Append the specified lines to {file}.  '!' forces the
981			write even if file does not exist.
982
983							*:w_c* *:write_c*
984:[range]w[rite] [++opt] !{cmd}
985			Execute {cmd} with [range] lines as standard input
986			(note the space in front of the '!').  {cmd} is
987			executed like with ":!{cmd}", any '!' is replaced with
988			the previous command |:!|.
989
990The default [range] for the ":w" command is the whole buffer (1,$).  The |'[|
991and |']| marks will be set to the [range] being used for the write command.
992If you write the whole buffer, it is no longer considered changed.  When you
993write it to a different file with ":w somefile" it depends on the "+" flag in
994'cpoptions'.  When included, the write command will reset the 'modified' flag,
995even though the buffer itself may still be different from its file.
996
997If a file name is given with ":w" it becomes the alternate file.  This can be
998used, for example, when the write fails and you want to try again later with
999":w #".  This can be switched off by removing the 'A' flag from the
1000'cpoptions' option.
1001
1002Note that the 'fsync' option matters here.  If it's set it may make writes
1003slower (but safer).
1004
1005							*:sav* *:saveas*
1006:sav[eas][!] [++opt] {file}
1007			Save the current buffer under the name {file} and set
1008			the filename of the current buffer to {file}.  The
1009			previous name is used for the alternate file name.
1010			The [!] is needed to overwrite an existing file.
1011			When 'filetype' is empty filetype detection is done
1012			with the new name, before the file is written.
1013			When the write was successful 'readonly' is reset.
1014
1015							*:up* *:update*
1016:[range]up[date][!] [++opt] [>>] [file]
1017			Like ":write", but only write when the buffer has been
1018			modified, or when the buffer represents a new file
1019			that doesn't exist on disk.
1020
1021
1022WRITING WITH MULTIPLE BUFFERS				*buffer-write*
1023
1024							*:wa* *:wall*
1025:wa[ll]	[++opt]		Write all changed buffers.  Buffers without a file
1026			name cause an error message.  Buffers which are
1027			readonly are not written.
1028			For ++opt see |++opt|, but only ++p is effective, and
1029			applies to each written file.
1030
1031:wa[ll]! [++opt]	Write all changed buffers, even the ones that are
1032			readonly.  Buffers without a file name are not
1033			written and cause an error message.
1034
1035
1036Vim will warn you if you try to overwrite a file that has been changed
1037elsewhere (unless "!" was used).  See |timestamp|.
1038
1039			    *backup* *E207* *E506* *E507* *E508* *E509* *E510*
1040If you write to an existing file (but do not append) while the 'backup',
1041'writebackup' or 'patchmode' option is on, a backup of the original file is
1042made.  The file is either copied or renamed (see 'backupcopy').  After the
1043file has been successfully written and when the 'writebackup' option is on and
1044the 'backup' option is off, the backup file is deleted.  When the 'patchmode'
1045option is on the backup file may be renamed.
1046
1047							*backup-table*
1048'backup' 'writebackup'	action	~
1049   off	     off	no backup made
1050   off	     on		backup current file, deleted afterwards (default)
1051   on	     off	delete old backup, backup current file
1052   on	     on		delete old backup, backup current file
1053
1054When the 'backupskip' pattern matches with the name of the file which is
1055written, no backup file is made.  The values of 'backup' and 'writebackup' are
1056ignored then.
1057
1058When the 'backup' option is on, an old backup file (with the same name as the
1059new backup file) will be deleted.  If 'backup' is not set, but 'writebackup'
1060is set, an existing backup file will not be deleted.  The backup file that is
1061made while the file is being written will have a different name.
1062
1063On some filesystems it's possible that in a crash you lose both the backup and
1064the newly written file (it might be there but contain bogus data).  In that
1065case try recovery, because the swap file is synced to disk and might still be
1066there. |:recover|
1067
1068The directories given with the 'backupdir' option are used to put the backup
1069file in.  (default: same directory as the written file).
1070
1071Whether the backup is a new file, which is a copy of the original file, or the
1072original file renamed depends on the 'backupcopy' option.  See there for an
1073explanation of when the copy is made and when the file is renamed.
1074
1075If the creation of a backup file fails, the write is not done.  If you want
1076to write anyway add a '!' to the command.
1077
1078							*file-watcher*
1079When you notice issues with programs, that act upon when a buffer is written
1080(like inotify, entr or fswatch) or when external applications execute Vim to
1081edit the file (like git) and those programs do not seem to notice that the
1082original file has been changed, you may want to consider switching the
1083'backupcopy' option value to "yes".  This makes sure, Vim writes to the same
1084file, that those watcher programs expect, without creating a new file (which
1085prevents them from detecting that the file has changed).  See also |crontab|
1086
1087							*write-permissions*
1088When writing a new file the permissions are read-write.  For unix the mask is
10890o666 with additionally umask applied.  When writing a file that was read Vim
1090will preserve the permissions, but clear the s-bit.
1091
1092							*write-readonly*
1093When the 'cpoptions' option contains 'W', Vim will refuse to overwrite a
1094readonly file.  When 'W' is not present, ":w!" will overwrite a readonly file,
1095if the system allows it (the directory must be writable).
1096
1097							*write-fail*
1098If the writing of the new file fails, you have to be careful not to lose
1099your changes AND the original file.  If there is no backup file and writing
1100the new file failed, you have already lost the original file!  DON'T EXIT VIM
1101UNTIL YOU WRITE OUT THE FILE!  If a backup was made, it is put back in place
1102of the original file (if possible).  If you exit Vim, and lose the changes
1103you made, the original file will mostly still be there.  If putting back the
1104original file fails, there will be an error message telling you that you
1105lost the original file.
1106
1107						*DOS-format-write*
1108If the 'fileformat' is "dos", <CR><NL> is used for <EOL>.  This is default
1109for Windows. On other systems the message "[dos]" is shown to
1110remind you that an unusual <EOL> was used.
1111						*Unix-format-write*
1112If the 'fileformat' is "unix", <NL> is used for <EOL>.  On Windows
1113the message "[unix]" is shown.
1114						*Mac-format-write*
1115If the 'fileformat' is "mac", <CR> is used for <EOL>.  The
1116message "[mac]" is shown.
1117
1118See also |file-formats| and the 'fileformat' and 'fileformats' options.
1119
1120						*ACL*
1121ACL stands for Access Control List.  It is an advanced way to control access
1122rights for a file.  It is used on new MS-Windows and Unix systems, but only
1123when the filesystem supports it.
1124   Vim attempts to preserve the ACL info when writing a file.  The backup file
1125will get the ACL info of the original file.
1126   The ACL info is also used to check if a file is read-only (when opening the
1127file).
1128
1129					*xattr* *E1506* *E1508* *E1509*
1130xattr stands for Extended Attributes.  It is an advanced way to save metadata
1131alongside the file in the filesystem.  It depends on the actual filesystem
1132being used and Vim supports it only on a Linux system.
1133   Vim attempts to preserve the extended attribute info when writing a file.
1134The backup file will get the extended attribute of the original file.
1135
1136						*read-only-share*
1137When MS-Windows shares a drive on the network it can be marked as read-only.
1138This means that even if the file read-only attribute is absent, and the ACL
1139settings on NT network shared drives allow writing to the file, you can still
1140not write to the file.  Vim on Win32 platforms will detect read-only network
1141drives and will mark the file as read-only.  You will not be able to override
1142it with |:write|.
1143
1144						*write-device*
1145When the file name is actually a device name, Vim will not make a backup (that
1146would be impossible).  You need to use "!", since the device already exists.
1147Example for Unix: >
1148	:w! /dev/lpt0
1149and MS-Windows: >
1150	:w! lpt0
1151For Unix a device is detected when the name doesn't refer to a normal file or
1152a directory.  A fifo or named pipe also looks like a device to Vim.
1153For MS-Windows the device is detected by its name:
1154	CON
1155	CLOCK$
1156	NUL
1157	PRN
1158	COMn	n=1,2,3... etc
1159	LPTn	n=1,2,3... etc
1160The names can be in upper- or lowercase.
1161
1162==============================================================================
1163Writing and quitting					*write-quit*
1164
1165							*:q* *:quit*
1166:q[uit]			Quit the current window.  Quit Vim if this is the last
1167			|edit-window|.  This fails when changes have been made
1168			and Vim refuses to |abandon| the current buffer, and
1169			when the last file in the argument list has not been
1170			edited.
1171			If there are other tabpages and quitting the last
1172			window in the current |tabpage|, the current tabpage is
1173			closed.
1174			Triggers the |QuitPre| autocommand event.
1175			See |CTRL-W_q| for quitting another window.
1176
1177:conf[irm] q[uit]	Quit, but give prompt when changes have been made, or
1178			the last file in the argument list has not been
1179			edited.  See |:confirm| and 'confirm'.
1180
1181:q[uit]!		Quit without writing, also when the current buffer has
1182			changes.  The buffer is unloaded, also when it has
1183			'hidden' set.
1184			If this is the last window and there is a modified
1185			hidden buffer, the current buffer is abandoned and the
1186			first changed hidden buffer becomes the current
1187			buffer.
1188			Use ":qall!" to exit always.
1189
1190:cq[uit]		Quit always, without writing, and return an error
1191			code.  See |:cq|.
1192
1193							*:wq*
1194:wq [++opt]		Write the current file and close the window.  If this
1195			was the last |edit-window| Vim quits.
1196			Writing fails when the file is read-only or the buffer
1197			does not have a name.  Quitting fails when the last
1198			file in the argument list has not been edited.
1199
1200:wq! [++opt]		Write the current file and close the window.  If this
1201			was the last |edit-window| Vim quits.  Writing fails
1202			when the current buffer does not have a name.
1203
1204:wq [++opt] {file}	Write to {file} and close the window.  If this was the
1205			last |edit-window| Vim quits.  Quitting fails when the
1206			last file in the argument list has not been edited.
1207
1208:wq! [++opt] {file}	Write to {file} and close the current window.  Quit
1209			Vim if this was the last |edit-window|.
1210
1211:[range]wq[!] [++opt] [file]
1212			Same as above, but only write the lines in [range].
1213
1214							*:x* *:xit*
1215:[range]x[it][!] [++opt] [file]
1216			Like ":wq", but write only when changes have been
1217			made.
1218			When 'hidden' is set and there are more windows, the
1219			current buffer becomes hidden, after writing the file.
1220
1221							*:exi* *:exit*
1222:[range]exi[t][!] [++opt] [file]
1223			Same as :xit.
1224
1225							*ZZ*
1226ZZ			Write current file, if modified, and close the current
1227			window (same as ":x").
1228			If there are several windows for the current file,
1229			only the current window is closed.
1230
1231							*ZQ*
1232ZQ			Quit without checking for changes (same as ":q!").
1233
1234							*ZR*
1235[count]ZR		Performs |:restart|. If a [count] of [1-8] is given,
1236			the session is not restored (":restart! +qall"). If a
1237			[count] of 9 is given, restarts without restoring the
1238			session or checking for changes (":restart! +qall!").
1239
1240MULTIPLE WINDOWS AND BUFFERS				*window-exit*
1241
1242							*:qa* *:qall*
1243:qa[ll]		Exit Vim, unless there are some buffers which have been
1244		changed.  (Use ":bmod" to go to the next modified buffer).
1245		When 'autowriteall' is set all changed buffers will be
1246		written, like |:wqall|.
1247
1248:conf[irm] qa[ll]
1249		Exit Vim.  Bring up a prompt when some buffers have been
1250		changed.  See |:confirm|.
1251
1252:qa[ll]!	Exit Vim.  Any changes to buffers are lost.
1253		Also see |:cquit|, it does the same but exits with a non-zero
1254		value.
1255
1256							*:quita* *:quitall*
1257:quita[ll][!]	Same as ":qall".
1258
1259:wqa[ll] [++opt]				*:wqa* *:wqall* *:xa* *:xall*
1260:xa[ll]		Write all changed buffers and exit Vim.  If there are buffers
1261		without a file name, which are readonly or which cannot be
1262		written for another reason, Vim will not quit.
1263
1264:conf[irm] wqa[ll] [++opt]
1265:conf[irm] xa[ll]
1266		Write all changed buffers and exit Vim.  Bring up a prompt
1267		when some buffers are readonly or cannot be written for
1268		another reason.  See |:confirm|.
1269
1270:wqa[ll]! [++opt]
1271:xa[ll]!	Write all changed buffers, even the ones that are readonly,
1272		and exit Vim.  If there are buffers without a file name or
1273		which cannot be written for another reason, Vim will not quit.
1274
1275==============================================================================
1276Dialogs							*edit-dialogs*
1277
1278							*:confirm* *:conf*
1279:conf[irm] {command}	Execute {command}, and use a dialog when an
1280			operation has to be confirmed.  Can be used on the
1281			|:edit|, |:restart|, |:q|, |:qa| and |:w| commands
1282			(the latter to override a read-only setting), and any
1283			commands that can fail because of unsaved changes,
1284			such as |:only|, |:buffer|, |:bdelete|, etc.
1285
1286Examples: >
1287  :confirm w foo
1288<	Will ask for confirmation when "foo" already exists. >
1289  :confirm q
1290<	Will ask for confirmation when there are changes. >
1291  :confirm qa
1292<	If any modified, unsaved buffers exist, you will be prompted to save
1293	or abandon each one.  There are also choices to "save all" or "abandon
1294	all".
1295
1296If you want to always use ":confirm", set the 'confirm' option.
1297
1298							*:browse* *:bro*
1299:bro[wse] {command} [file]
1300			Without [file]: opens the |current-directory| (with
1301			the |dir| browser by default; see |dir-disable|).
1302
1303			{command} must be one of: |:edit|, |:split|,
1304			|:vsplit|, |:tabedit|, |:tabnew|.
1305
1306			With a [file] argument, or if {command} does not
1307			support browsing: executes {command}.
1308
1309Examples: >
1310	:browse edit
1311<		Open the current directory. >
1312	:browse vsplit
1313<		Open the current directory in a vertical split.
1314
1315			See |:oldfiles| for ":browse oldfiles".
1316
1317							*browsefilter*
1318For MS-Windows you can modify the filters that are used in the browse
1319dialog.  By setting the g:browsefilter or b:browsefilter variables, you can
1320change the filters globally or locally to the buffer.  The variable is set to
1321a string in the format "{filter label}\t{pattern};{pattern}\n" where "{filter
1322label}" is the text that appears in the "Files of Type" comboBox, and {pattern}
1323is the pattern which filters the filenames.  Several patterns can be given,
1324separated by ';'.
1325
1326For example, to have only Vim files in the dialog, you could use the following
1327command: >
1328
1329     let g:browsefilter = "Vim scripts\t*.vim\nVim Startup Files\t*vimrc\n"
1330
1331You can override the filter setting on a per-buffer basis by setting the
1332b:browsefilter variable.  You would most likely set b:browsefilter in a
1333filetype plugin, so that the browse dialog would contain entries related to
1334the type of file you are currently editing.  Disadvantage: This makes it
1335difficult to start editing a file of a different type.  To overcome this, you
1336can add the following as the final filter on Windows: >
1337
1338	All Files\t(*.*)\t*\n
1339<
1340Or the following on other platforms, so that the user can still access any
1341desired file: >
1342
1343	All Files\t(*)\t*\n
1344<
1345
1346To avoid setting browsefilter when Vim does not actually support it, you can
1347use has("browsefilter"): >
1348
1349	if has("browsefilter")
1350	   let g:browsefilter = "whatever"
1351	endif
1352
1353==============================================================================
1354The current directory					*current-directory*
1355
1356The "effective working directory" affects anything that operates on relative
1357paths, e.g. ":edit ./foo.txt" or shell commands like ":!ls" or ":te ls". There
1358are four current-directory "scopes": global, tab, window and buffer. You can
1359use |:cd|, |:tcd|, |:lcd| and |:bcd| to change to a directory at a given scope.
1360
1361The precedence of scopes is ordered from narrowest to widest: >
1362
1363	buffer > window > tab > global
1364
1365Use |getcwd()| to get the effective directory, and `:verbose pwd` to also see
1366which scope it came from.
1367
1368Setting a directory at a higher scope clears the lower ones: |:tcd| clears the
1369window-local directory and |:cd| clears both.  But the buffer-local directory
1370is never cleared, except by |:bcd| or |:bcd!|.
1371
1372
1373:chd[ir]					*:cd* *:chd* *:chdir* *E747* *E472*
1374:cd			Change the current directory to the home directory,
1375			unsetting the same directories as ":cd {path}".
1376
1377			If 'cdhome' is disabled this only prints the name.
1378			Use |:pwd| to print it regardless of 'cdhome'.
1379
1380:cd {path}		Change the current directory to {path}, resolved
1381			against 'cdpath' (if {path} is relative). On
1382			MS-Windows this also changes the active drive.
1383
1384			Clears the window-local and tab-local directories (on
1385			the current window/tab), but not the buffer-local one.
1386
1387			To change to the directory of the current file: >
1388				:cd %:h
1389<
1390			Does not change the meaning of an already opened file,
1391			because its full path name is remembered.  Files from
1392			the |arglist| may change though!
1393
1394							*:cd-* *E186*
1395:cd -			Change to previous current-directory (before the last
1396			":cd {path}" command).
1397
1398:tch[dir]						*:tc* *:tcd* *:tch* *:tchdir*
1399:tc[d] [path]		Like |:cd|, but only set the directory for the current
1400			tab. Clears the window-local directory of the current
1401			window, but not the buffer-local one.
1402
1403			Does not change the current directory for other tabs,
1404			nor any other window or buffer with its own local
1405			directory.
1406
1407			"Sticky" behavior: a new tab inherits the current
1408			tab-local directory.
1409
1410							*:tcd-*
1411:tc[d] -		Change to previous tab-local directory (before the
1412			last ":tcd {path}" command).
1413
1414:lch[dir]						*:lc* *:lcd* *:lch* *:lchdir*
1415:lc[d] [path]		Like |:cd|, but only set the directory for the current
1416			window.  Does not change the current directory for
1417			other tabs, windows or buffers.
1418
1419			The specified directory becomes the current directory
1420			whenever that window is entered, unless its current
1421			buffer has a buffer-local (:bcd) directory.
1422
1423			"Sticky" behavior: a new window inherits the current
1424			window-local directory.
1425
1426
1427							*:lcd-*
1428:lc[d] -		Change to previous window-local directory (before the
1429			last ":lcd {path}" command).
1430
1431:bch[dir]						*:bc* *:bcd* *:bch* *:bchdir*
1432:bc[d] [path]		Like |:cd|, but only set the directory for the current
1433			buffer.  Does not change the current directory for
1434			tabs, windows or other buffers.
1435
1436			Not "sticky": unlike :lcd and :tcd, a new window or
1437			buffer (|:edit|, |:enew|, …) will not "inherit" the
1438			current buffer-local directory. Use |:tcd| or |:lcd|
1439			if you want "sticky" behavior.
1440
1441			See also |project-dir|.
1442
1443							*:bcd-*
1444:bc[d] -		Change to previous buffer-local directory (before the
1445			last ":bcd {path}" command).
1446
1447						*:lcd!* *:tcd!* *:bcd!*
1448:lc[d]!			Unset the window-local current-directory.
1449:tc[d]!			Unset the tab-local current-directory.
1450:bc[d]!			Unset the buffer-local current-directory.
1451
1452			Each unsets only its own scope, so the next-higher
1453			scope takes effect. No-op if the scope has no local
1454			directory.
1455
1456			The global directory always exists, so ":cd!" is the
1457			same as |:cd|.
1458
1459							*:pw* *:pwd* *E187*
1460:pw[d]			Print the current directory name.
1461			See also |getcwd()|.
1462							*:pwd-verbose*
1463			When 'verbose' is non-zero, |:pwd| will also display
1464			what scope the current directory was set.  Example: >
1465
1466				" Set by :cd
1467				:verbose pwd
1468				[global] /path/to/current
1469
1470				" Set by :tcd
1471				:verbose pwd
1472				[tabpage] /path/to/current
1473
1474
1475------------------------------------------------------------------------------
1476Project directory				       *project-dir* *workspace-dir*
1477
1478You can use |:bcd| to assign a "workspace" (or "project directory") to each
1479buffer, so commands like |:make|, |:grep| and |:terminal| always run relative
1480to the buffer's "workspace".
1481
1482Example: change to the project root (found by |vim.fs.root()|) of each buffer: >lua
1483
1484	vim.api.nvim_create_autocmd('BufReadPost', {
1485	  callback = function(ev)
1486	    local root = vim.fs.root(ev.buf, { '.git', 'Makefile' })
1487	    if root then
1488	      vim.cmd.bcd(root)
1489	    end
1490	  end,
1491	})
1492<
1493See also:
1494- |lsp-buf-working-dir|
1495- |terminal-osc7|
1496
1497==============================================================================
1498Editing binary files					*edit-binary*
1499
1500Although Vim was made to edit text files, it is possible to edit binary
1501files.  The |-b| Vim argument (b for binary) makes Vim do file I/O in binary
1502mode, and sets some options for editing binary files ('binary' on, 'textwidth'
1503to 0, 'modeline' off, 'expandtab' off).  Setting the 'binary' option has the
1504same effect.  Don't forget to do this before reading the file.
1505
1506There are a few things to remember when editing binary files:
1507- When editing executable files the number of bytes must not change.
1508  Use only the "R" or "r" command to change text.  Do not delete characters
1509  with "x" or by backspacing.
1510- Set the 'textwidth' option to 0.  Otherwise lines will unexpectedly be
1511  split in two.
1512- When there are not many <EOL>s, the lines will become very long.  If you
1513  want to edit a line that does not fit on the screen reset the 'wrap' option.
1514  Horizontal scrolling is used then.  If a line becomes too long (see |limits|)
1515  you cannot edit that line.  The line will be split when reading the file.
1516  It is also possible that you get an "out of memory" error when reading the
1517  file.
1518- Make sure the 'binary' option is set BEFORE loading the
1519  file.  Otherwise both <CR><NL> and <NL> are considered to end a line
1520  and when the file is written the <NL> will be replaced with <CR><NL>.
1521- <Nul> characters are shown on the screen as ^@.  You can enter them with
1522  "CTRL-V CTRL-@" or "CTRL-V 000".
1523- To insert a <NL> character in the file split a line.  When writing the
1524  buffer to a file a <NL> will be written for the <EOL>.
1525- Vim normally appends an <EOL> at the end of the file if there is none.
1526  Setting the 'binary' option prevents this.  If you want to add the final
1527  <EOL>, set the 'endofline' option.  You can also read the value of this
1528  option to see if there was an <EOL> for the last line (you cannot see this
1529  in the text).
1530
1531==============================================================================
1532Encryption						*encryption*
1533
1534					                *:X* *E817* *E818* *E819* *E820*
1535Support for editing encrypted files has been removed.
1536	https://github.com/neovim/neovim/issues/694
1537	https://github.com/neovim/neovim/issues/701
1538
1539==============================================================================
1540Timestamps					*timestamp* *timestamps*
1541
1542Vim remembers the modification timestamp, mode and size of a file when you
1543begin editing it.  This is used to avoid that you have two different versions
1544of the same file (without you knowing this).
1545
1546After a shell command (|:!cmd| |suspend| |:read!| |K|) or |:terminal| job
1547exits: timestamps, file modes and file sizes are compared for all buffers
1548in a window.  Nvim will run |FileChangedShell| autocommands or display
1549a warning for any files that changed.
1550
1551							*E321* *E462*
1552If you want to automatically reload a file when it has been changed outside of
1553Vim, set the 'autoread' option.  This doesn't work at the moment you write the
1554file though, only when the file wasn't changed inside of Vim.
1555
1556Nvim uses file system watchers to detect external changes in real-time for
1557all loaded buffers when 'autoread' is set.  This means files are reloaded
1558promptly without waiting for |FocusGained| or |:checktime|.  The watchers
1559are managed automatically: started when a buffer is loaded, restarted after
1560|:write|, and stopped when the buffer is deleted or 'autoread' is disabled.
1561							*ignore-timestamp*
1562If you do not want to be asked or automatically reload the file, you can use
1563this: >
1564	set buftype=nofile
1565
1566Or, when starting gvim from a shell: >
1567	gvim file.log -c "set buftype=nofile"
1568
1569Note that if a FileChangedShell autocommand is defined you will not get a
1570warning message or prompt.  The autocommand is expected to handle this.
1571
1572There is no warning for a directory.  But you do get warned if you started
1573editing a new file and it was created as a directory later.
1574
1575When Vim notices the timestamp of a file has changed, and the file is being
1576edited in a buffer but has not changed, Vim checks if the contents of the file
1577is equal.  This is done by reading the file again (into a hidden buffer, which
1578is immediately deleted again) and comparing the text.  If the text is equal,
1579you will get no warning.
1580
1581If you don't get warned often enough you can use the following command.
1582
1583							*:checkt* *:checktime*
1584:checkt[ime]		Check if any buffers were changed outside of Vim.
1585			This checks and warns you if you would end up with two
1586			versions of a file.
1587			If this is called from an autocommand, a ":global"
1588			command or is not typed the actual check is postponed
1589			until a moment the side effects (reloading the file)
1590			would be harmless.
1591			Each loaded buffer is checked for its associated file
1592			being changed.  If the file was changed Vim will take
1593			action.  If there are no changes in the buffer and
1594			'autoread' is set, the buffer is reloaded.  Otherwise,
1595			you are offered the choice of reloading the file.  If
1596			the file was deleted you get an error message.
1597			If the file previously didn't exist you get a warning
1598			if it exists now.
1599			Once a file has been checked the timestamp is reset,
1600			you will not be warned again.
1601			Syntax highlighting, marks, diff status,
1602			'fileencoding', 'fileformat' and 'binary' options
1603			are not changed.  See |v:fcs_choice| to reload these
1604			too (for example, if a code formatting tools has
1605			changed the file).
1606
1607:[N]checkt[ime] {filename}
1608:[N]checkt[ime] [N]
1609			Check the timestamp of a specific buffer.  The buffer
1610			may be specified by name, number or with a pattern.
1611
1612
1613							*E813* *E814*
1614Vim will reload the buffer if you chose to.  If a window is visible that
1615contains this buffer, the reloading will happen in the context of this window.
1616Otherwise a special window is used, so that most autocommands will work.  You
1617can't close this window.  A few other restrictions apply.  Best is to make
1618sure nothing happens outside of the current buffer.  E.g., setting
1619window-local options may end up in the wrong window.  Splitting the window,
1620doing something there and closing it should be OK (if there are no side
1621effects from other autocommands).  Closing unrelated windows and buffers will
1622get you into trouble.
1623
1624Before writing a file, the timestamp is checked (unless "!" was used).
1625If it has changed, Vim will ask if you really want to overwrite the file:
1626
1627	WARNING: The file has been changed since reading it!!!
1628	Do you really want to write to it (y/n)?
1629
1630If you hit 'y' Vim will continue writing the file.  If you hit 'n' the write
1631is aborted.  If you used ":wq" or "ZZ" Vim will not exit, you will get another
1632chance to write the file.
1633
1634The message would normally mean that somebody has written to the file after
1635the edit session started.  This could be another person, in which case you
1636probably want to check if your changes to the file and the changes from the
1637other person should be merged.  Write the file under another name and check
1638for differences (the "diff" program can be used for this).
1639
1640It is also possible that you modified the file yourself, from another edit
1641session or with another command (e.g., a filter command).  Then you will know
1642which version of the file you want to keep.
1643
1644The accuracy of the time check depends on the filesystem.  On Unix it is
1645usually sub-second.  With old file systems and on MS-Windows it is normally
1646one second.  Use `has('nanotime')` to check if sub-second time stamp checks
1647are available.
1648
1649There is one situation where you get the message while there is nothing wrong:
1650On a Win32 system on the day daylight saving time starts.  There is something
1651in the Win32 libraries that confuses Vim about the hour time difference.  The
1652problem goes away the next day.
1653
1654==============================================================================
1655File Searching						*file-searching*
1656
1657The file searching is currently used for the 'path', 'cdpath' and 'tags'
1658options, for |finddir()| and |findfile()|.  Other commands use |wildcards|
1659which is slightly different.
1660
1661There are three different types of searching:
1662
16631) Downward search:					*starstar*
1664   Downward search uses the wildcards "*", "**" and possibly others
1665   supported by your operating system.  "*" and "**" are handled inside Vim,
1666   so they work on all operating systems.  Note that "**" only acts as a
1667   special wildcard when it is at the start of a name.
1668
1669   The usage of "*" is quite simple: It matches 0 or more characters.  In a
1670   search pattern this would be `.*`.  Note that the "." is not used for file
1671   searching.
1672
1673   "**" is more sophisticated:
1674      - It ONLY matches directories.
1675      - It matches up to 30 directories deep by default, so you can use it to
1676	search an entire directory tree
1677      - The maximum number of levels matched can be given by appending a
1678	number to "**".
1679	Thus '/usr/**2' can match: >
1680		/usr
1681		/usr/include
1682		/usr/include/sys
1683		/usr/include/g++
1684		/usr/lib
1685		/usr/lib/X11
1686		....
1687<	It does NOT match '/usr/include/g++/std' as this would be three
1688	levels.
1689	The allowed number range is 0 ("**0" is removed) to 100
1690	If the given number is smaller than 0 it defaults to 30, if it's
1691	bigger than 100 then 100 is used.  The system also has a limit on the
1692	path length, usually 256 or 1024 bytes.
1693      - "**" can only be at the end of the path or be followed by a path
1694	separator or by a number and a path separator.
1695
1696   You can combine "*" and "**" in any order: >
1697	/usr/**/sys/*
1698	/usr/*tory/sys/**
1699	/usr/**2/sys/*
1700
17012) Upward search:
1702   Here you can give a directory and then search the directory tree upward for
1703   a file.  You could give stop-directories to limit the upward search.  The
1704   stop-directories are appended to the path (for the 'path' option) or to
1705   the filename (for the 'tags' option) with a ';'.  If you want several
1706   stop-directories separate them with ';'.  If you want no stop-directory
1707   ("search upward till the root directory") just use ';'. >
1708	/usr/include/sys;/usr
1709<   will search in: >
1710	   /usr/include/sys
1711	   /usr/include
1712	   /usr
1713<
1714   If you use a relative path the upward search is started in Vim's current
1715   directory or in the directory of the current file (if the relative path
1716   starts with './' and 'd' is not included in 'cpoptions').
1717
1718   If Vim's current path is /u/user_x/work/release and you do >
1719	:set path=include;/u/user_x
1720<   and then search for a file with |gf| the file is searched in: >
1721	/u/user_x/work/release/include
1722	/u/user_x/work/include
1723	/u/user_x/include
1724
1725<   Note: If your 'path' setting includes a non-existing directory, Vim will
1726   skip the non-existing directory, and also does not search in the parent of
1727   the non-existing directory if upwards searching is used.
1728
17293) Combined up/downward search:
1730   If Vim's current path is /u/user_x/work/release and you do >
1731	set path=**;/u/user_x
1732<   and then search for a file with |gf| the file is searched in: >
1733	/u/user_x/work/release/**
1734	/u/user_x/work/**
1735	/u/user_x/**
1736<
1737   BE CAREFUL!  This might consume a lot of time, as the search of
1738   '/u/user_x/**' includes '/u/user_x/work/**' and
1739   '/u/user_x/work/release/**'.  So '/u/user_x/work/release/**' is searched
1740   three times and '/u/user_x/work/**' is searched twice.
1741
1742   In the above example you might want to set path to: >
1743	:set path=**,/u/user_x/**
1744<   This searches: >
1745	/u/user_x/work/release/**
1746	/u/user_x/**
1747<   This searches the same directories, but in a different order.
1748
1749   Note that completion for ":find", ":sfind", and ":tabfind" commands do not
1750   currently work with 'path' items that contain a URL or use the double star
1751   with depth limiter (/usr/**2) or upward search (;) notations.
1752
1753==============================================================================
1754Trusted Files							*trust*
1755
1756Nvim executes arbitrary code found on the filesystem if 'exrc' is enabled. To
1757prevent executing malicious code, only "trusted files" are executed. You can
1758mark a file as trusted or untrusted using the |:trust| command or the
1759|vim.secure.read()| function.
1760
1761							*:trust* *E5570*
1762:trust [++deny] [++remove] [file]
1763
1764			Manage trusted files. Without ++ options, :trust marks
1765			the current buffer (or [file], but see WARNING below)
1766			as trusted, keyed on a hash of its contents. The trust
1767			list is stored on disk, Nvim will re-use it after
1768			restarting.
1769
1770			WARNING: `:trust [file]` has a TOCTOU risk, so for
1771			security you should view the file, inspect its
1772			contents, and run `:trust` (without [file] arg).
1773
1774			[++deny] marks the current buffer or [file] as
1775			untrusted: it will never be executed, 'exrc' will
1776			ignore it.
1777
1778			[++remove] removes the current buffer or [file] from
1779			the trust list. When the file is discovered by 'exrc'
1780			or |vim.secure.read()|, the user will be prompted to
1781			trust or deny it.
1782
1783==============================================================================
1784Log Files							*log-files*
1785
1786Nvim keeps log files in `stdpath("log")`. See |standard-path| for where that
1787location is on your system.
1788
1789							*:log* *E5200*
1790:log [logname]
1791			Open a log file that exists in `stdpath("log")`.
1792			`[logname]` is the name of the file with the extension
1793			".log" removed.
1794
1795			Without a provided `[logname]`, opens the log
1796			directory.
1797
1798Examples: >
1799	:log nvim
1800<		Open the general |log| file for Nvim. >
1801	:log lsp
1802<		Open the |lsp-log| file. >
1803	:log nvim-pack
1804<		Open the |vim.pack| log file.
1805
1806 vim:tw=78:ts=8:noet:ft=help:norl: