xref: /vim-8.2.3635/runtime/doc/editing.txt (revision 69a7cb47)
1*editing.txt*   For Vim version 7.0aa.  Last change: 2004 Jun 17
2
3
4		  VIM REFERENCE MANUAL    by Bram Moolenaar
5
6
7Editing files						*edit-files*
8
91.  Introduction		|edit-intro|
102.  Editing a file		|edit-a-file|
113.  Dialogs			|edit-dialogs|
124.  The current directory	|current-directory|
135.  The argument list		|argument-list|
146.  Writing			|writing|
157.  Writing and quitting	|write-quit|
168.  Editing binary files	|edit-binary|
179.  Encryption			|encryption|
1810. Timestamps			|timestamps|
19
20==============================================================================
211. Introduction						*edit-intro*
22
23Editing a file with Vim means:
24
251. reading the file into the internal buffer
262. changing the buffer with editor commands
273. writing the buffer into a file
28
29							*current-file*
30As long as you don't write the buffer, the original file remains unchanged.
31If you start editing a file (read a file into the buffer), the file name is
32remembered as the "current file name".
33
34							*alternate-file*
35If there already was a current file name, then that one becomes the alternate
36file name.  All file names are remembered in the file list.  When you enter a
37file name, for editing (e.g., with ":e filename") or writing (e.g., with (:w
38file name"), the file name is added to the list.  You can use this list to
39remember which files you edited and to quickly switch from one file to
40another with the CTRL-^ command (e.g., to copy text).  First type the number
41of the file and then hit CTRL-^.  {Vi: only one alternate file name}
42
43CTRL-G		or				*CTRL-G* *:f* *:fi* *:file*
44:f[ile]			Prints the current file name (as typed), the
45			cursor position (unless the 'ruler' option is set),
46			and the file status (readonly, modified, read errors,
47			new file)).  See the 'shortmess' option about how tho
48			make this message shorter.  {Vi does not include
49			column number}
50
51{count}CTRL-G		Like CTRL-G, but prints the current file name with
52			full path.  If the count is higher than 1 the current
53			buffer number is also given.  {not in Vi}
54
55					*g_CTRL-G* *word-count* *byte-count*
56g CTRL-G		Prints the current position of the cursor in four
57			ways: Column, Line, Word and Byte.  If there are
58			characters in the line that take more than one
59			position on the screen (<Tab> or special character),
60			both the "real" column and the screen column are
61			shown, separated with a dash.  See also 'ruler'
62			option.  {not in Vi}
63
64							*v_g_CTRL-G*
65{Visual}g CTRL-G	Similar to "g CTRL-G", but Word, Line, and Byte counts
66			for the visually selected region are displayed.  In
67			Blockwise mode, Column count is also shown.  (For
68			{Visual} see |Visual-mode|.)
69			{not in VI}
70
71							*:file_f*
72:f[ile] {name}		Sets the current file name to {name}.
73
74:buffers
75:files
76:ls			List all the currently known file names.  See
77			'windows.txt' |:files| |:buffers| |:ls|.  {not in
78			Vi}
79
80Vim will remember the full path name of a file name that you enter.  In most
81cases when the file name is displayed only the name you typed is shown, but
82the full path name is being used if you used the ":cd" command |:cd|.
83
84							*home-replace*
85If the environment variable $HOME is set, and the file name starts with that
86string, it is often displayed with HOME replaced with "~".  This was done to
87keep file names short.  When reading or writing files the full name is still
88used, the "~" is only used when displaying file names.  When replacing the
89file name would result in just "~", "~/" is used instead (to avoid confusion
90with 'backupext' set to "~").
91
92When writing the buffer, the default is to use the current file name.  Thus
93when you give the "ZZ" or ":wq" command, the original file will be
94overwritten.  If you do not want this, the buffer can be written into another
95file by giving a file name argument to the ":write" command.  For example: >
96
97	vim testfile
98	[change the buffer with editor commands]
99	:w newfile
100	:q
101
102This will create a file "newfile", that is a modified copy of "testfile".
103The file "testfile" will remain unchanged.  Anyway, if the 'backup' option is
104set, Vim renames or copies the original file before it will be overwritten.
105You can use this file if you discover that you need the original file.  See
106also the 'patchmode' option.  The name of the backup file is normally the same
107as the original file with 'backupext' appended.  The default "~" is a bit
108strange to avoid accidentally overwriting existing files.  If you prefer ".bak"
109change the 'backupext' option.  Extra dots are replaced with '_' on MS-DOS
110machines, when Vim has detected that an MS-DOS-like filesystem is being used
111(e.g., messydos or crossdos) or when the 'shortname' option is on.  The
112backup file can be placed in another directory by setting 'backupdir'.
113
114							*auto-shortname*
115Technical: On the Amiga you can use 30 characters for a file name.  But on an
116	   MS-DOS-compatible filesystem only 8 plus 3 characters are
117	   available.  Vim tries to detect the type of filesystem when it is
118	   creating the .swp file.  If an MS-DOS-like filesystem is suspected,
119	   a flag is set that has the same effect as setting the 'shortname'
120	   option.  This flag will be reset as soon as you start editing a
121	   new file.  The flag will be used when making the file name for the
122	   ".swp" and ".~" files for the current file.  But when you are
123	   editing a file in a normal filesystem and write to an MS-DOS-like
124	   filesystem the flag will not have been set.  In that case the
125	   creation of the ".~" file may fail and you will get an error
126	   message.  Use the 'shortname' option in this case.
127
128When you started editing without giving a file name, "No File" is displayed in
129messages.  If the ":write" command is used with a file name argument, the file
130name for the current file is set to that file name.  This only happens when
131the 'F' flag is included in 'cpoptions' (by default it is included).  This is
132useful when entering text in an empty buffer and then writing it to a file.
133If 'cpoptions' contains the 'f' flag (by default it is NOT included) the file
134name is set for the ":read file" command.  This is useful when starting Vim
135without an argument and then doing ":read file" to start editing a file.
136							*not-edited*
137Because the file name was set without really starting to edit that file, you
138are protected from overwriting that file.  This is done by setting the
139"notedited" flag.  You can see if this flag is set with the CTRL-G or ":file"
140command.  It will include "[Not edited]" when the "notedited" flag is set.
141When writing the buffer to the current file name (with ":w!"), the "notedited"
142flag is reset.
143
144							*abandon*
145Vim remembers whether you have changed the buffer.  You are protected from
146losing the changes you made.  If you try to quit without writing, or want to
147start editing another file, Vim will refuse this.  In order to overrule this
148protection, add a '!' to the command.  The changes will then be lost.  For
149example: ":q" will not work if the buffer was changed, but ":q!" will.  To see
150whether the buffer was changed use the "CTRL-G" command.  The message includes
151the string "[Modified]" if the buffer has been changed.
152
153If you want to automatically save the changes without asking, switch on the
154'autowriteall' option.  'autowrite' is the associated Vi-compatible option
155that does not work for all commands.
156
157If you want to keep the changed buffer without saving it, switch on the
158'hidden' option.  See |hidden-buffer|.
159
160==============================================================================
1612. Editing a file					*edit-a-file*
162
163							*:e* *:edit*
164:e[dit] [++opt] [+cmd]	Edit the current file.  This is useful to re-edit the
165			current file, when it has been changed outside of Vim.
166			This fails when changes have been made to the current
167			buffer and 'autowriteall' isn't set or the file can't
168			be written.
169			Also see |++opt| and |+cmd|.
170			{Vi: no ++opt}
171
172							*:edit!*
173:e[dit]! [++opt] [+cmd]
174			Edit the current file always.  Discard any changes to
175			the current buffer.  This is useful if you want to
176			start all over again.
177			Also see |++opt| and |+cmd|.
178			{Vi: no ++opt}
179
180							*:edit_f*
181:e[dit] [++opt] [+cmd] {file}
182			Edit {file}.
183			This fails when changes have been made to the current
184			buffer, unless 'hidden' is set or 'autowriteall' is
185			set and the file can be written.
186			Also see |++opt| and |+cmd|.
187			{Vi: no ++opt}
188
189							*:edit!_f*
190:e[dit]! [++opt] [+cmd] {file}
191			Edit {file} always.  Discard any changes to the
192			current buffer.
193			Also see |++opt| and |+cmd|.
194			{Vi: no ++opt}
195
196:e[dit] [++opt] [+cmd] #[count]
197			Edit the [count]th alternate file name (as shown by
198			:files).  This command does the same as
199			[count] CTRL-^.  But ":e #" doesn't work if the
200			alternate buffer doesn't have a file name, while
201			CTRL-^ still works then.
202			Also see |++opt| and |+cmd|.
203			{Vi: no ++opt}
204
205							*:ene* *:enew*
206:ene[w]			Edit a new, unnamed buffer.  This fails when changes
207			have been made to the current buffer, unless 'hidden'
208			is set or 'autowriteall' is set and the file can be
209			written.
210			If 'fileformats' is not empty, the first format given
211			will be used for the new buffer.  If 'fileformats' is
212			empty, the 'fileformat' of the current buffer is used.
213			{not in Vi}
214
215							*:ene!* *:enew!*
216:ene[w]!		Edit a new, unnamed buffer.  Discard any changes to
217			the current buffer.
218			Set 'fileformat' like |:enew|.
219			{not in Vi}
220
221							*:fin* *:find*
222:fin[d][!] [++opt] [+cmd] {file}
223			Find {file} in 'path' and then |:edit| it.
224			{not in Vi} {not available when the |+file_in_path|
225			feature was disabled at compile time}
226
227:{count}fin[d][!] [++opt] [+cmd] {file}
228			Just like ":find", but use the {count} match in
229			'path'.  Thus ":2find file" will find the second
230			"file" found in 'path'.  When there are fewer matches
231			for the file in 'path' than asked for, you get an
232			error message.
233
234							*:ex*
235:ex [++opt] [+cmd] [file]
236			Same as |:edit|.
237
238							*:vi* *:visual*
239:vi[sual][!] [++opt] [+cmd] [file]
240			When entered in Ex mode: Leave |Ex-mode|, go back to
241			Normal mode.  Otherwise same as |:edit|.
242
243							*:vie* *:view*
244:vie[w] [++opt] [+cmd] file
245			When entered in Ex mode: Leave Ex mode, go back to
246			Normal mode.  Otherwise same as |:edit|, but set
247			'readonly' option for this buffer.  {not in Vi}
248
249							*CTRL-^* *CTRL-6*
250[count]CTRL-^		Edit [count]th alternate file (equivalent to ":e
251			#[count]").  Without count this gets you to the
252			previously edited file.  This is a quick way to toggle
253			between two (or more) files.
254			If the 'autowrite' or 'autowriteall' option is on and
255			the buffer was changed, write it.
256			Mostly the ^ character is positioned on the 6 key,
257			pressing CTRL and 6 then gets you what we call CTRL-^.
258			But on some non-US keyboards CTRL-^ is produced in
259			another way.
260
261[count]]f						*]f* *[f*
262[count][f		Same as "gf".  Deprecated.
263
264							*gf* *E446* *E447*
265[count]gf		Edit the file whose name is under or after the cursor.
266			Mnemonic: "goto file".
267			Uses the 'isfname' option to find out which characters
268			are supposed to be in a file name.  Trailing
269			punctuation characters ".,:;!" are ignored.
270			Uses the 'path' option as a list of directory names
271			to look for the file.  Also looks for the file
272			relative to the current file.
273			Uses the 'suffixesadd' option to check for file names
274			with a suffix added.
275			If the file can't be found, 'includeexpr' is used to
276			modify the name and another attempt is done.
277			If a [count] is given, the count'th file that is found
278			in the 'path' is edited.
279			This command fails if Vim refuses to |abandon| the
280			current file.
281			If you do want to edit a new file, use: >
282				:e <cfile>
283<			To make gf always work like that: >
284				:map gf :e <cfile><CR>
285<			If the name is a hypertext link, that looks like
286			"type://machine/path", you need the |netrw| plugin.
287			For Unix the '~' character is expanded, like in
288			"~user/file".  Environment variables are expanded too
289			|expand-env|.
290			{not in Vi}
291			{not available when the |+file_in_path| feature was
292			disabled at compile time}
293
294							*v_gf*
295{Visual}[count]gf	Same as "gf", but the highlighted text is used as the
296			name of the file to edit.  'isfname' is ignored.
297			Leading blanks are skipped, otherwise all blanks and
298			special characters are included in the file name.
299			(For {Visual} see |Visual-mode|.)
300			{not in VI}
301
302These commands are used to start editing a single file.  This means that the
303file is read into the buffer and the current file name is set.  The file that
304is opened depends on the current directory, see |:cd|.
305
306See |read-messages| for an explanation of the message that is given after the
307file has been read.
308
309You can use the ":e!" command if you messed up the buffer and want to start
310all over again.  The ":e" command is only useful if you have changed the
311current file name.
312
313							*:filename* *{file}*
314Note for systems other than Unix and MS-DOS: When using a command that
315accepts a single file name (like ":edit file") spaces in the file name are
316allowed, but trailing spaces are ignored.  This is useful on systems that
317allow file names with embedded spaces (like the Amiga).  Example: The command
318":e   Long File Name " will edit the file "Long File Name".  When using a
319command that accepts more than one file name (like ":next file1 file2")
320embedded spaces must be escaped with a backslash.
321
322Wildcards in {file} are expanded.  Which wildcards are supported depends on
323the system.  These are the common ones:
324	*	matches anything, including nothing
325	?	matches one character
326	[abc]	match 'a', 'b' or 'c'
327To avoid the special meaning of the wildcards prepend a backslash.  However,
328on MS-Windows the backslash is a path separator and "path\[abc]" is still seen
329as a wildcard when "[" is in the 'isfname' option.  A simple way to avoid this
330is to use "path\[[]abc]".  Then the file "path[abc]" literally.
331
332					*backtick-expansion* *`-expansion*
333On Unix you can also use backticks in the file name, for example: >
334	:e `find . -name ver\\*.c -print`
335The backslashes before the star are required to prevent "ver*.c" to be
336expanded by the shell before executing the find program.
337This also works for most other systems, with the restriction that the
338backticks must be around the whole item.  It is not possible to have text
339directly before the first or just after the last backtick.
340
341							*`=*
342You can have the backticks expanded as a Vim expression, instead of
343an external command, by using the syntax `={expr}` e.g.: >
344	:let foo='bar'
345	:e `=foo . ".c" `
346This will edit "bar.c".  The expression can contain just about anything, thus
347this can also be used to avoid the special meaning of '"', '|', '%' and '#'.
348
349							*++opt* *[++opt]*
350The [++opt] argument can be used to force the value of 'fileformat' or
351'fileencoding' to a value for one command.  The form is: >
352	++{optname}={value}
353
354Where {optname} is one of:		*++ff* *++enc* *++bin* *++nobin*
355    ff     or  fileformat   overrides 'fileformat'
356    enc    or  encoding	    overrides 'fileencoding'
357    bin    or  binary	    sets 'binary'
358    nobin  or  nobinary	    resets 'binary'
359
360{value} cannot contain white space.  It can be any valid value for these
361options.  Examples: >
362	:e ++ff=unix
363This edits the same file again with 'fileformat' set to "unix". >
364
365	:w ++enc=latin1 newfile
366This writes the current buffer to "newfile" in latin1 format.
367
368Note that when reading, the 'fileformat' and 'fileencoding' options will be
369set to the used format.  When writing this doesn't happen, thus a next write
370will use the old value of the option.  Same for the 'binary' option.
371
372There may be several ++opt arguments, separated by white space.  They must all
373appear before any |+cmd| argument.
374
375							*+cmd* *[+cmd]*
376The [+cmd] argument can be used to position the cursor in the newly opened
377file, or execute any other command:
378	+		Start at the last line.
379	+{num}		Start at line {num}.
380	+/{pat}		Start at first line containing {pat}.
381	+{command}	Execute {command} after opening the new file.
382			{command} is any Ex command.
383To include a white space in the {pat} or {command}, precede it with a
384backslash.  Double the number of backslashes. >
385	:edit  +/The\ book	     file
386	:edit  +/dir\ dirname\\      file
387	:edit  +set\ dir=c:\\\\temp  file
388Note that in the last example the number of backslashes is halved twice: Once
389for the "+cmd" argument and once for the ":set" command.
390
391							*file-formats*
392The 'fileformat' option sets the <EOL> style for a file:
393'fileformat'    characters	   name				~
394  "dos"		<CR><NL> or <NL>   DOS format		*DOS-format*
395  "unix"	<NL>		   Unix format		*Unix-format*
396  "mac"		<CR>		   Mac format		*Mac-format*
397Previously 'textmode' was used.  It is obsolete now.
398
399When reading a file, the mentioned characters are interpreted as the <EOL>.
400In DOS format (default for MS-DOS, OS/2 and Win32), <CR><NL> and <NL> are both
401interpreted as the <EOL>.  Note that when writing the file in DOS format,
402<CR> characters will be added for each single <NL>.  Also see |file-read|.
403
404When writing a file, the mentioned characters are used for <EOL>.  For DOS
405format <CR><NL> is used.  Also see |DOS-format-write|.
406
407You can read a file in DOS format and write it in Unix format.  This will
408replace all <CR><NL> pairs by <NL> (assuming 'fileformats' includes "dos"): >
409	:e file
410	:set fileformat=unix
411	:w
412If you read a file in Unix format and write with DOS format, all <NL>
413characters will be replaced with <CR><NL> (assuming 'fileformats' includes
414"unix"): >
415	:e file
416	:set fileformat=dos
417	:w
418
419If you start editing a new file and the 'fileformats' option is not empty
420(which is the default), Vim will try to detect whether the lines in the file
421are separated by the specified formats.  When set to "unix,dos", Vim will
422check for lines with a single <NL> (as used on Unix and Amiga) or by a <CR>
423<NL> pair (MS-DOS).  Only when ALL lines end in <CR><NL>, 'fileformat' is set
424to "dos", otherwise it is set to "unix".  When 'fileformats' includes "mac",
425and no <NL> characters are found in the file, 'fileformat' is set to "mac".
426
427If the 'fileformat' option is set to "dos" on non-MS-DOS systems the message
428"[dos format]" is shown to remind you that something unusual is happening.  On
429MS-DOS systems you get the message "[unix format]" if 'fileformat' is set to
430"unix".  On all systems but the Macintosh you get the message "[mac format]"
431if 'fileformat' is set to "mac".
432
433If the 'fileformats' option is empty and DOS format is used, but while reading
434a file some lines did not end in <CR><NL>, "[CR missing]" will be included in
435the file message.
436If the 'fileformats' option is empty and Mac format is used, but while reading
437a file a <NL> was found, "[NL missing]" will be included in the file message.
438
439If the new file does not exist, the 'fileformat' of the current buffer is used
440when 'fileformats' is empty.  Otherwise the first format from 'fileformats' is
441used for the new file.
442
443Before editing binary, executable or Vim script files you should set the
444'binary' option.  A simple way to do this is by starting Vim with the "-b"
445option.  This will avoid the use of 'fileformat'.  Without this you risk that
446single <NL> characters are unexpectedly replaced with <CR><NL>.
447
448You can encrypt files that are written by setting the 'key' option.  This
449provides some security against others reading your files. |encryption|
450
451
452File Searching						*file-searching*
453
454{not available when compiled without the |+path_extra| feature}
455
456The file searching is currently used for the 'path', 'cdpath' and 'tags'
457options.  There are three different types of searching:
458
4591) Downward search:
460   Downward search uses the wildcards '*', '**' and possibly others
461   supported by your operating system. '*' and '**' are handled inside Vim, so
462   they work on all operating systems.
463
464   The usage of '*' is quite simple: It matches 0 or more characters.
465
466   '**' is more sophisticated:
467      - It ONLY matches directories.
468      - It matches up to 30  directories deep, so you can use it to search an
469	entire directory tree
470      - The maximum number of levels matched can be given by appending a number
471	to '**'.
472	Thus '/usr/**2' can match: >
473		/usr
474		/usr/include
475		/usr/include/sys
476		/usr/include/g++
477		/usr/lib
478		/usr/lib/X11
479		....
480<	It does NOT match '/usr/include/g++/std' as this would be three
481	levels.
482	The allowed number range is 0 ('**0' is removed) to 255.
483	If the given number is smaller than 0 it defaults to 30, if it's
484	bigger than 255 it defaults to 255.
485      - '**' can only be at the end of the path or be followed by a path
486	separator or by a number and a path separator.
487
488   You can combine '*' and '**' in any order: >
489	/usr/**/sys/*
490	/usr/*/sys/**
491	/usr/**2/sys/*
492
4932) Upward search:
494   Here you can give a directory and then search the directory tree upward for
495   a file. You could give stop-directories to limit the upward search. The
496   stop-directories are appended to the path (for the 'path' option) or to
497   the filename (for the 'tags' option) with a ';'. If you want several
498   stop-directories separate them with ';'. If you want no stop-directory
499   ("search upward till the root directory) just use ';'. >
500	/usr/include/sys;/usr
501<   will search in: >
502	   /usr/include/sys
503	   /usr/include
504	   /usr
505<
506   If you use a relative path the upward search is started in Vim's current
507   directory or in the directory of the current file (if the relative path
508   starts with './' and 'd' is not included in 'cpoptions').
509
510   If Vim's current path is /u/user_x/work/release and you do >
511	:set path=include;/u/user_x
512<  and then search for a file with |gf| the file is searched in: >
513	/u/user_x/work/release/include
514	/u/user_x/work/include
515	/u/user_x/include
516
5173) Combined up/downward search
518   If Vim's current path is /u/user_x/work/release and you do >
519	set path=**;/u/user_x
520<  and then search for a file with |gf| the file is searched in: >
521	/u/user_x/work/release/**
522	/u/user_x/work/**
523	/u/user_x/**
524<
525   BE CAREFUL! This might consume a lot of time, as the search of
526   '/u/user_x/**' includes '/u/user_x/work/**' and
527   '/u/user_x/work/release/**'.  So '/u/user_x/work/release/**' is searched
528   three and '/u/user_x/work/**' is searched two times.
529
530   In the above example you might want to set path to: >
531	:set path=**,/u/user_x/**
532<   This searches: >
533	/u/user_x/work/release/**
534	/u/user_x/**
535<   This searches the same directories, but in a different order.
536
537==============================================================================
5383. Dialogs						*edit-dialogs*
539
540							*:confirm* *:conf*
541:conf[irm] {command}	Execute {command}, and use a dialog when an
542			operation has to be confirmed.  Can be used on the
543			":q", ":qa" and ":w" commands (the latter to over-ride
544			a read-only setting).
545
546Examples: >
547  :confirm w foo
548<	Will ask for confirmation when "foo" already exists. >
549  :confirm q
550<	Will ask for confirmation when there are changes. >
551  :confirm qa
552<	If any modified, unsaved buffers exist, you will be prompted to save
553	or abandon each one.  There are also choices to "save all" or "abandon
554	all".
555
556If you want to always use ":confirm", set the 'confirm' option.
557
558			*:browse* *:bro* *E338* *E614* *E615* *E616* *E578*
559:bro[wse] {command}	Open a file selection dialog for an argument to
560			{command}.  At present this works for |:e|, |:w|,
561			|:r|, |:saveas|, |:sp|, |:mkexrc|, |:mkvimrc| and
562			|:mksession|.
563			{only in Win32, Athena, Motif, GTK and Mac GUI}
564			When ":browse" is not possible you get an error
565			message.  If the |+browse| feature is missing or the
566			{command} doesn't support browsing, the {command} is
567			executed without a dialog.
568			":browse set" works like |:options|.
569
570The syntax is best shown via some examples: >
571	:browse e $vim/foo
572<		Open the browser in the $vim/foo directory, and edit the
573		file chosen. >
574	:browse e
575<		Open the browser in the directory specified with 'browsedir',
576		and edit the file chosen. >
577	:browse w
578<		Open the browser in the directory of the current buffer,
579		with the current buffer filename as default, and save the
580		buffer under the filename chosen. >
581	:browse w C:/bar
582<		Open the browser in the C:/bar directory, with the current
583		buffer filename as default, and save the buffer under the
584		filename chosen.
585Also see the |'browsedir'| option.
586For versions of Vim where browsing is not supported, the command is executed
587unmodified.
588
589							*browsefilter*
590For MS Windows, you can modify the filters that are used in the browse dialog.
591By setting the g:browsefilter or b:browsefilter variables, you can change the
592filters globally or locally to the buffer.  The variable is set to a string in
593the format "{filter label}\t{pattern};{pattern}\n" where {filter label} is the
594text that appears in the "Files of Type" comboBox, and {pattern} is the
595pattern which filters the filenames.  Several patterns can be given, separated
596by ';'.
597
598For Motif the same format is used, but only the very first pattern is actually
599used (Motif only offers one pattern, but you can edit it).
600
601For example, to have only Vim files in the dialog, you could use the following
602command: >
603
604     let g:browsefilter="Vim Scripts\t*.vim\nVim Startup Files\t*vimrc\n"
605
606You can override the filter setting on a per-buffer basis by setting the
607b:browsefilter variable.  You would most likely set b:browsefilter in a
608filetype plugin, so that the browse dialog would contain entries related to
609the type of file you are currently editing.  Disadvantage: This makes it
610difficult to start editing a file of a different type.  To overcome this, you
611may want to add "All Files\t*.*\n" as the final filter, so that the user can
612still access any desired file.
613
614==============================================================================
6154. The current directory				*current-directory*
616
617You may use the |:cd| and |:lcd| commands to change to another directory, so
618you will not have to type that directory name in front of the file names.  It
619also makes a difference for executing external commands, e.g. ":!ls".
620
621							*:cd* *E472*
622:cd			On non-Unix systems: Print the current directory
623			name.  On Unix systems: Change the current directory
624			to the home directory.  Use |:pwd| to print the
625			current directory on all systems.
626
627:cd {path}		Change the current directory to {path}.
628			If {path} is relative, it is searched for in the
629			directories listed in |'cdpath'|.
630			Does not change the meaning of an already opened file,
631			because its full path name is remembered.  Files from
632			the |arglist| may change though!
633			On MS-DOS this also changes the active drive.
634			To change to the directory of the current file: >
635				:cd %:h
636<
637							*:cd-* *E186*
638:cd -			Change to the previous current directory (before the
639			previous ":cd {path}" command). {not in Vi}
640
641							*:chd* *:chdir*
642:chd[ir] [path]		Same as |:cd|.
643
644							*:lc* *:lcd*
645:lc[d] {path}		Like |:cd|, but only set the current directory for the
646			current window.  The current directory for other
647			windows is not changed. {not in Vi}
648
649							*:lch* *:lchdir*
650:lch[dir]		Same as |:lcd|. {not in Vi}
651
652							*:pw* *:pwd* *E187*
653:pw[d]			Print the current directory name.  {Vi: no pwd}
654			Also see |getcwd()|.
655
656So long as no |:lcd| command has been used, all windows share the same current
657directory.  Using a command to jump to another window doesn't change anything
658for the current directory.
659When a |:lcd| command has been used for a window, the specified directory
660becomes the current directory for that window.  Windows where the |:lcd|
661command has not been used stick to the global current directory.  When jumping
662to another window the current directory will become the last specified local
663current directory.  If none was specified, the global current directory is
664used.
665When a |:cd| command is used, the current window will lose his local current
666directory and will use the global current directory from now on.
667
668After using |:cd| the full path name will be used for reading and writing
669files.  On some networked file systems this may cause problems.  The result of
670using the full path name is that the file names currently in use will remain
671referring to the same file.  Example: If you have a file a:test and a
672directory a:vim the commands ":e test" ":cd vim" ":w" will overwrite the file
673a:test and not write a:vim/test.  But if you do ":w test" the file a:vim/test
674will be written, because you gave a new file name and did not refer to a
675filename before the ":cd".
676
677==============================================================================
6785. The argument list				*argument-list* *arglist*
679
680If you give more than one file name when starting Vim, this list is remembered
681as the argument list.  You can jump to each file in this list.
682
683Do not confuse this with the buffer list, which you can see with the
684|:buffers| command.  The argument list was already present in Vi, the buffer
685list is new in Vim.  A file name in the argument list will also be present in
686the buffer list (unless it was deleted with ":bdel").
687
688This subject is introduced in section |07.2| of the user manual.
689
690There is one global argument list, which is used for all windows by default.
691It is possible to create a new argument list local to a window, see
692|:arglocal|.
693
694You can use the argument list with the following commands, and with the
695expression functions |argc()| and |argv()|.  These all work on the argument
696list of the current window.
697
698							*:ar* *:args*
699:ar[gs]			Print the argument list, with the current file in
700			square brackets.
701
702:ar[gs] [++opt] [+cmd] {arglist}			*:args_f*
703			Define {arglist} as the new argument list and edit
704			the first one.  This fails when changes have been made
705			and Vim does not want to |abandon| the current buffer.
706			Also see |++opt| and |+cmd|.
707			{Vi: no ++opt}
708
709:ar[gs]! [++opt] [+cmd] {arglist}			*:args_f!*
710			Define {arglist} as the new argument list and edit
711			the first one.  Discard any changes to the current
712			buffer.
713			Also see |++opt| and |+cmd|.
714			{Vi: no ++opt}
715
716:[count]arge[dit][!] [++opt] [+cmd] {name}		*:arge* *:argedit*
717			Add {name} to the argument list and edit it.
718			When {name} already exists in the argument list, this
719			entry is edited.
720			This is like using |:argadd| and then |:edit|.
721			Note that only one file name is allowed, and spaces
722			inside the file name are allowed, like with |:edit|.
723			[count] is used like with |:argadd|.
724			[!] is required if the current file cannot be
725			|abandon|ed.
726			Also see |++opt| and |+cmd|.
727			{not in Vi}
728
729:[count]arga[dd] {name} ..			*:arga* *:argadd* *E479*
730			Add the {name}s to the argument list.
731			If [count] is omitted, the {name}s are added just
732			after the current entry in the argument list.
733			Otherwise they are added after the [count]'th file.
734			If the argument list is "a b c", and "b" is the
735			current argument, then these commands result in:
736				command		new argument list ~
737				:argadd x	a b x c
738				:0argadd x	x a b c
739				:1argadd x	a x b c
740				:99argadd x	a b c x
741			There is no check for duplicates, it is possible to
742			add a file to the argument list twice.
743			The currently edited file is not changed.
744			{not in Vi} {not available when compiled without the
745			|+listcmds| feature}
746			Note: you can also use this method: >
747				:args ## x
748<			This will add the "x" item and sort the new list.
749
750:argd[elete] {pattern} ..			*:argd* *:argdelete* *E480*
751			Delete files from the argument list that match the
752			{pattern}s.  {pattern} is used like a file pattern,
753			see |file-pattern|.  "%" can be used to delete the
754			current entry.
755			This command keeps the currently edited file, also
756			when it's deleted from the argument list.
757			{not in Vi} {not available when compiled without the
758			|+listcmds| feature}
759
760:{range}argd[elete]	Delete the {range} files from the argument list.
761			When the last number in the range is too high, up to
762			the last argument is deleted.  Example: >
763				:10,1000argdel
764<			Deletes arguments 10 and further, keeping 1-9.
765			{not in Vi} {not available when compiled without the
766			|+listcmds| feature}
767
768							*:argu* *:argument*
769:[count]argu[ment] [count] [++opt] [+cmd]
770			Edit file [count] in the argument list.  When [count]
771			is omitted the current entry is used.  This fails
772			when changes have been made and Vim does not want to
773			|abandon| the current buffer.
774			Also see |++opt| and |+cmd|.
775			{not in Vi} {not available when compiled without the
776			|+listcmds| feature}
777
778:[count]argu[ment]! [count] [++opt] [+cmd]
779			Edit file [count] in the argument list, discard any
780			changes to the current buffer.  When [count] is
781			omitted the current entry is used.
782			Also see |++opt| and |+cmd|.
783			{not in Vi} {not available when compiled without the
784			|+listcmds| feature}
785
786:[count]n[ext] [++opt] [+cmd]			*:n* *:ne* *:next* *E165* *E163*
787			Edit [count] next file.  This fails when changes have
788			been made and Vim does not want to |abandon| the
789			current buffer.  Also see |++opt| and |+cmd|.  {Vi: no
790			count or ++opt}.
791
792:[count]n[ext]! [++opt] [+cmd]
793			Edit [count] next file, discard any changes to the
794			buffer.  Also see |++opt| and |+cmd|.  {Vi: no count
795			or ++opt}.
796
797:n[ext] [++opt] [+cmd] {arglist}			*:next_f*
798			Same as |:args_f|.
799
800:n[ext]! [++opt] [+cmd] {arglist}
801			Same as |:args_f!|.
802
803:[count]N[ext] [count] [++opt] [+cmd]			*:Next* *:N* *E164*
804			Edit [count] previous file in argument list.  This
805			fails when changes have been made and Vim does not
806			want to |abandon| the current buffer.
807			Also see |++opt| and |+cmd|.  {Vi: no count or ++opt}.
808
809:[count]N[ext]! [count] [++opt] [+cmd]
810			Edit [count] previous file in argument list.  Discard
811			any changes to the buffer.  Also see |++opt| and
812			|+cmd|.  {Vi: no count or ++opt}.
813
814:[count]prev[ious] [count] [++opt] [+cmd]		*:prev* *:previous*
815			Same as :Next.  Also see |++opt| and |+cmd|.  {Vi:
816			only in some versions}
817
818							*:rew* *:rewind*
819:rew[ind] [++opt] [+cmd]
820			Start editing the first file in the argument list.
821			This fails when changes have been made and Vim does
822			not want to |abandon| the current buffer.
823			Also see |++opt| and |+cmd|. {Vi: no ++opt}
824
825:rew[ind]! [++opt] [+cmd]
826			Start editing the first file in the argument list.
827			Discard any changes to the buffer.  Also see |++opt|
828			and |+cmd|. {Vi: no ++opt}
829
830							*:fir* *:first*
831:fir[st][!] [++opt] [+cmd]
832			Other name for ":rewind". {not in Vi}
833
834							*:la* *:last*
835:la[st] [++opt] [+cmd]
836			Start editing the last file in the argument list.
837			This fails when changes have been made and Vim does
838			not want to |abandon| the current buffer.
839			Also see |++opt| and |+cmd|.  {not in Vi}
840
841:la[st]! [++opt] [+cmd]
842			Start editing the last file in the argument list.
843			Discard any changes to the buffer.  Also see |++opt|
844			and |+cmd|.  {not in Vi}
845
846							*:wn* *:wnext*
847:[count]wn[ext] [++opt] [+cmd]
848			Write current file and start editing the [count]
849			next file.  Also see |++opt| and |+cmd|.  {not in Vi}
850
851:[count]wn[ext] [++opt] [+cmd] {file}
852			Write current file to {file} and start editing the
853			[count] next file, unless {file} already exists and
854			the 'writeany' option is off.  Also see |++opt| and
855			|+cmd|.  {not in Vi}
856
857:[count]wn[ext]! [++opt] [+cmd] {file}
858			Write current file to {file} and start editing the
859			[count] next file.  Also see |++opt| and |+cmd|.  {not
860			in Vi}
861
862:[count]wN[ext][!] [++opt] [+cmd] [file]		*:wN* *:wNext*
863:[count]wp[revous][!] [++opt] [+cmd] [file]		*:wp* *:wprevious*
864			Same as :wnext, but go to previous file instead of
865			next.  {not in Vi}
866
867The [count] in the commands above defaults to one.  For some commands it is
868possible to use two counts.  The last one (rightmost one) is used.
869
870If no [+cmd] argument is present, the cursor is positioned at the last known
871cursor position for the file.  If 'startofline' is set, the cursor will be
872positioned at the first non-blank in the line, otherwise the last know column
873is used.  If there is no last known cursor position the cursor will be in the
874first line (the last line in Ex mode).
875
876The wildcards in the argument list are expanded and the file names are sorted.
877Thus you can use the command "vim *.c" to edit all the C files.  From within
878Vim the command ":n *.c" does the same.  On Unix you can also use backticks,
879for example: >
880	:n `find . -name \\*.c -print`
881The backslashes before the star are required to prevent "*.c" to be expanded
882by the shell before executing the find program.
883
884							*arglist-position*
885When there is an argument list you can see which file you are editing in the
886title of the window (if there is one and 'title' is on) and with the file
887message you get with the "CTRL-G" command.  You will see something like
888	(file 4 of 11)
889If 'shortmess' contains 'f' it will be
890	(4 of 11)
891If you are not really editing the file at the current position in the argument
892list it will be
893	(file (4) of 11)
894This means that you are position 4 in the argument list, but not editing the
895fourth file in the argument list.  This happens when you do ":e file".
896
897
898LOCAL ARGUMENT LIST
899
900{not in Vi}
901{not available when compiled without the |+windows| or |+listcmds| feature}
902
903							*:arglocal*
904:argl[ocal]		Make a local copy of the global argument list.
905			Doesn't start editing another file.
906
907:argl[ocal][!] [++opt] [+cmd] {arglist}
908			Define a new argument list, which is local to the
909			current window.  Works like |:args_f| otherwise.
910
911							*:argglobal*
912:argg[lobal]		Use the global argument list for the current window.
913			Doesn't start editing another file.
914
915:argg[lobal][!] [++opt] [+cmd] {arglist}
916			Use the global argument list for the current window.
917			Define a new global argument list like |:args_f|.
918			All windows using the global argument list will see
919			this new list.
920
921There can be several argument lists.  They can be shared between windows.
922When they are shared, changing the argument list in one window will also
923change it in the other window.
924
925When a window is split the new window inherits the argument list from the
926current window.  The two windows then share this list, until one of them uses
927|:arglocal| or |:argglobal| to use another argument list.
928
929
930USING THE ARGUMENT LIST
931
932						*:argdo*
933:argdo[!] {cmd}		Execute {cmd} for each file in the argument list.
934			It works like doing this: >
935				:rewind
936				:{cmd}
937				:next
938				:{cmd}
939				etc.
940<			When the current file can't be |abandon|ed and the [!]
941			is not present, the command fails.
942			When an error is detected on one file, further files
943			in the argument list will not be visited.
944			The last file in the argument list (or where an error
945			occurred) becomes the current file.
946			{cmd} can contain '|' to concatenate several commands.
947			{cmd} must not change the argument list.
948			Note: While this command is executing, the Syntax
949			autocommand event is disabled by adding it to
950			'eventignore'.  This considerably speeds up editing
951			each file.
952			{not in Vi} {not available when compiled without the
953			|+listcmds| feature}
954			Also see |:windo| and |:bufdo|.
955
956Example: >
957	:args *.c
958	:argdo set ff=unix | update
959This sets the 'fileformat' option to "unix" and writes the file if is now
960changed.  This is done for all *.c files.
961
962Example: >
963	:args *.[ch]
964	:argdo %s/\<my_foo\>/My_Foo/ge | update
965This changes the word "my_foo" to "My_Foo" in all *.c and *.h files.  The "e"
966flag is used for the ":substitute" command to avoid an error for files where
967"my_foo" isn't used.  ":update" writes the file only if changes were made.
968
969==============================================================================
9706. Writing					*writing* *save-file*
971
972Note: When the 'write' option is off, you are not able to write any file.
973
974							*:w* *:write*
975						*E502* *E503* *E504* *E505*
976						*E512* *E514* *E667*
977:w[rite]		Write the whole buffer to the current file.  This is
978			the normal way to save changes to a file.  It fails
979			when the 'readonly' option is set or when there is
980			another reason why the file can't be written.
981
982:w[rite]!		Like ":write", but forcefully write when 'readonly' is
983			set or there is another reason why writing was
984			refused.
985			Note: This may change the permission and ownership of
986			the file and break (symbolic) links.  Add the 'W' flag
987			to 'cpoptions' to avoid this.
988
989:[range]w[rite][!]	Write the specified lines to the current file.  This
990			is unusual, because the file will not contain all
991			lines in the buffer.
992
993							*:w_f* *:write_f*
994:[range]w[rite]	{file}	Write the specified lines to {file}, unless it
995			already exists and the 'writeany' option is off.
996
997							*:w!*
998:[range]w[rite]! {file}	Write the specified lines to {file}.  Overwrite an
999			existing file.
1000
1001						*:w_a* *:write_a* *E494*
1002:[range]w[rite][!] >>	Append the specified lines to the current file.
1003
1004:[range]w[rite][!] >> {file}
1005			Append the specified lines to {file}.  '!' forces the
1006			write even if file does not exist.
1007
1008							*:w_c* *:write_c*
1009:[range]w[rite] !{cmd}	Execute {cmd} with [range] lines as standard input
1010			(note the space in front of the '!').  {cmd} is
1011			executed like with ":!{cmd}", any '!' is replaced with
1012			the previous command |:!|.
1013
1014The default [range] for the ":w" command is the whole buffer (1,$).
1015If a file name is given with ":w" it becomes the alternate file.  This can be
1016used, for example, when the write fails and you want to try again later with
1017":w #".  This can be switched off by removing the 'A' flag from the
1018'cpoptions' option.
1019
1020							*:sav* *:saveas*
1021:sav[eas][!] {file}	Save the current buffer under the name {file} and set
1022			the filename of the current buffer to {file}.  The
1023			previous name is used for the alternate file name.
1024			The [!] is needed to overwrite an existing file.
1025			{not in Vi}
1026
1027							*:up* *:update*
1028:[range]up[date][!] [>>] [file]
1029			Like ":write", but only write when the buffer has been
1030			modified.  {not in Vi}
1031
1032
1033WRITING WITH MULTIPLE BUFFERS				*buffer-write*
1034
1035							*:wa* *:wall*
1036:wa[ll]			Write all changed buffers.  Buffers without a file
1037			name or which are readonly are not written. {not in
1038			Vi}
1039
1040:wa[ll]!		Write all changed buffers, even the ones that are
1041			readonly.  Buffers without a file name are not
1042			written. {not in Vi}
1043
1044
1045Vim will warn you if you try to overwrite a file that has been changed
1046elsewhere.  See |timestamp|.
1047
1048			    *backup* *E207* *E506* *E507* *E508* *E509* *E510*
1049If you write to an existing file (but do not append) while the 'backup',
1050'writebackup' or 'patchmode' option is on, a backup of the original file is
1051made.  The file is either copied or renamed (see 'backupcopy').  After the
1052file has been successfully written and when the 'writebackup' option is on and
1053the 'backup' option is off, the backup file is deleted.  When the 'patchmode'
1054option is on the backup file may be renamed.
1055
1056							*backup-table*
1057'backup' 'writebackup'	action	~
1058   off	     off	no backup made
1059   off	     on		backup current file, deleted afterwards (default)
1060   on	     off	delete old backup, backup current file
1061   on	     on		delete old backup, backup current file
1062
1063When the 'backupskip' pattern matches with the name of the file which is
1064written, no backup file is made.  The values of 'backup' and 'writebackup' are
1065ignored then.
1066
1067When the 'backup' option is on, an old backup file (with the same name as the
1068new backup file) will be deleted.  If 'backup' is not set, but 'writebackup'
1069is set, an existing backup file will not be deleted.  The backup file that is
1070made while the file is being written will have a different name.
1071
1072On some filesystems it's possible that in a crash you lose both the backup and
1073the newly written file (it might be there but contain bogus data).  In that
1074case try recovery, because the swap file is synced to disk and might still be
1075there. |:recover|
1076
1077The directories given with the 'backupdir' option is used to put the backup
1078file in.  (default: same directory as the written file).
1079
1080Whether the backup is a new file, which is a copy of the original file, or the
1081original file renamed depends on the 'backupcopy' option.  See there for an
1082explanation of when the copy is made and when the file is renamed.
1083
1084If the creation of a backup file fails, the write is not done.  If you want
1085to write anyway add a '!' to the command.
1086
1087							*write-readonly*
1088When the 'cpoptions' option contains 'W', Vim will refuse to overwrite a
1089readonly file.  When 'W' is not present, ":w!" will overwrite a readonly file,
1090if the system allows it (the directory must be writable).
1091
1092							*write-fail*
1093If the writing of the new file fails, you have to be careful not to lose
1094your changes AND the original file.  If there is no backup file and writing
1095the new file failed, you have already lost the original file! DON'T EXIT VIM
1096UNTIL YOU WRITE OUT THE FILE! If a backup was made, it is put back in place
1097of the original file (if possible).  If you exit Vim, and lose the changes
1098you made, the original file will mostly still be there.  If putting back the
1099original file fails, there will be an error message telling you that you
1100lost the original file.
1101
1102						*DOS-format-write*
1103If the 'fileformat' is "dos", <CR> <NL> is used for <EOL>.  This is default
1104for MS-DOS, Win32 and OS/2.  On other systems the message "[dos format]" is
1105shown to remind you that an unusual <EOL> was used.
1106						*Unix-format-write*
1107If the 'fileformat' is "unix", <NL> is used for <EOL>.  On MS-DOS, Win32 and
1108OS/2 the message "[unix format]" is shown.
1109						*Mac-format-write*
1110If the 'fileformat' is "mac", <CR> is used for <EOL>.  On non-Mac systems the
1111message "[mac format]" is shown.
1112
1113See also |file-formats| and the 'fileformat' and 'fileformats' options.
1114
1115						*ACL*
1116ACL stands for Access Control List.  It is an advanced way to control access
1117rights for a file.  It is used on new MS-Windows and Unix systems, but only
1118when the filesystem supports it.
1119   Vim attempts to preserve the ACL info when writing a file.  The backup file
1120will get the ACL info of the original file.
1121   The ACL info is also used to check if a file is read-only (when opening the
1122file).
1123
1124						*read-only-share*
1125When MS-Windows shares a drive on the network it can be marked as read-only.
1126This means that even if the file read-only attribute is absent, and the ACL
1127settings on NT network shared drives allow writing to the file, you can still
1128not write to the file.  Vim on Win32 platforms will detect read-only network
1129drives and will mark the file as read-only.  You will not be able to override
1130it with |:write|.
1131
1132						*write-device*
1133When the file name is actually a device name, Vim will not make a backup (that
1134would be impossible).  You need to use "!", since the device already exists.
1135Example for Unix: >
1136	:w! /dev/lpt0
1137and for MS-DOS or MS-Windows: >
1138	:w! lpt0
1139For Unix a device is detected when the name doesn't refer to a normal file or
1140a directory.  A fifo or named pipe also looks like a device to Vim.
1141For MS-DOS and MS-Windows the device is detected by its name:
1142	AUX
1143	CON
1144	CLOCK$
1145	NUL
1146	PRN
1147	COMn	n=1,2,3... etc
1148	LPTn	n=1,2,3... etc
1149The names can be in upper- or lowercase.
1150
1151==============================================================================
11527. Writing and quitting					*write-quit*
1153
1154							*:q* *:quit*
1155:q[uit]			Quit the current window.  Quit Vim if this is the last
1156			window.  This fails when changes have been made and
1157			Vim refuses to |abandon| the current buffer, and when
1158			the last file in the argument list has not been
1159			edited.
1160
1161:conf[irm] q[uit]	Quit, but give prompt when changes have been made, or
1162			the last file in the argument list has not been
1163			edited.  See |:confirm| and 'confirm'.  {not in Vi}
1164
1165:q[uit]!		Quit without writing, also when visible buffers have
1166			changes.  Does not exit when there are changed hidden
1167			buffers.  Use ":qall!" to exit always.
1168
1169:cq[uit]		Quit always, without writing, and return an error
1170			code.  See |:cq|.  Used for Manx's QuickFix mode (see
1171			|quickfix|).  {not in Vi}
1172
1173							*:wq*
1174:wq			Write the current file and quit.  Writing fails when
1175			the file is read-only or the buffer does not have a
1176			name.  Quitting fails when the last file in the
1177			argument list has not been edited.
1178
1179:wq!			Write the current file and quit.  Writing fails when
1180			the current buffer does not have a name.
1181
1182:wq {file}		Write to {file} and quit.  Quitting fails when the
1183			last file in the argument list has not been edited.
1184
1185:wq! {file}		Write to {file} and quit.
1186
1187:[range]wq[!] [file]	Same as above, but only write the lines in [range].
1188
1189							*:x* *:xit*
1190:[range]x[it][!] [file]
1191			Like ":wq", but write only when changes have been
1192			made.
1193			When 'hidden' is set and there are more windows, the
1194			current buffer becomes hidden, after writing the file.
1195
1196							*:exi* *:exit*
1197:[range]exi[t][!] [file]
1198			Same as :xit.
1199
1200							*ZZ*
1201ZZ			Write current file, if modified, and quit (same as
1202			":x").  (Note: If there are several windows for the
1203			current file, the file is written if it was modified
1204			and the window is closed).
1205
1206							*ZQ*
1207ZQ			Quit without checking for changes (same as ":q!").
1208			{not in Vi}
1209
1210MULTIPLE WINDOWS AND BUFFERS				*window-exit*
1211
1212							*:qa* *:qall*
1213:qa[ll]		Exit Vim, unless there are some buffers which have been
1214		changed.  (Use ":bmod" to go to the next modified buffer).
1215		When 'autowriteall' is set all changed buffers will be
1216		written, like |:wqall|. {not in Vi}
1217
1218:conf[irm] qa[ll]
1219		Exit Vim.  Bring up a prompt when some buffers have been
1220		changed.  See |:confirm|. {not in Vi}
1221
1222:qa[ll]!	Exit Vim.  Any changes to buffers are lost. {not in Vi}
1223
1224							*:quita* *:quitall*
1225:quita[ll][!]	Same as ":qall". {not in Vi}
1226
1227:wqa[ll]					*:wqa* *:wqall* *:xa* *:xall*
1228:xa[ll]		Write all changed buffers and exit Vim.  If there are buffers
1229		without a file name, which are readonly or which cannot be
1230		written for another reason, Vim will not quit. {not in Vi}
1231
1232:conf[irm] wqa[ll]
1233:conf[irm] xa[ll]
1234		Write all changed buffers and exit Vim.  Bring up a prompt
1235		when some buffers are readonly or cannot be written for
1236		another reason.  See |:confirm|. {not in Vi}
1237
1238:wqa[ll]!
1239:xa[ll]!	Write all changed buffers, even the ones that are readonly,
1240		and exit Vim.  If there are buffers without a file name or
1241		which cannot be written for another reason, Vim will not quit.
1242		{not in Vi}
1243
1244==============================================================================
12458. Editing binary files					*edit-binary*
1246
1247Although Vim was made to edit text files, it is possible to edit binary
1248files.  The |-b| Vim argument (b for binary) makes Vim do file I/O in binary
1249mode, and sets some options for editing binary files ('binary' on, 'textwidth'
1250to 0, 'modeline' off, 'expandtab' off).  Setting the 'binary' option has the
1251same effect.  Don't forget to do this before reading the file.
1252
1253There are a few things to remember when editing binary files:
1254- When editing executable files the number of characters must not change.
1255  Use only the "R" or "r" command to change text.  Do not delete characters
1256  with "x" or by backspacing.
1257- Set the 'textwidth' option to 0.  Otherwise lines will unexpectedly be
1258  split in two.
1259- When there are not many <EOL>s, the lines will become very long.  If you
1260  want to edit a line that does not fit on the screen reset the 'wrap' option.
1261  Horizontal scrolling is used then.  If a line becomes too long (more than
1262  about 32767 characters on the Amiga, much more on 32-bit systems, see
1263  |limits|) you cannot edit that line.  The line will be split when reading
1264  the file.  It is also possible that you get an "out of memory" error when
1265  reading the file.
1266- Make sure the 'binary' option is set BEFORE loading the
1267  file.  Otherwise both <CR> <NL> and <NL> are considered to end a line
1268  and when the file is written the <NL> will be replaced with <CR> <NL>.
1269- <Nul> characters are shown on the screen as ^@.  You can enter them with
1270  "CTRL-V CTRL-@" or "CTRL-V 000" {Vi cannot handle <Nul> characters in the
1271  file}
1272- To insert a <NL> character in the file split up a line.  When writing the
1273  buffer to a file a <NL> will be written for the <EOL>.
1274- Vim normally appends an <EOL> at the end of the file if there is none.
1275  Setting the 'binary' option prevents this.  If you want to add the final
1276  <EOL>, set the 'endofline' option.  You can also read the value of this
1277  option to see if there was an <EOL> for the last line (you cannot see this
1278  in the text).
1279
1280==============================================================================
12819. Encryption						*encryption*
1282
1283Vim is able to write files encrypted, and read them back.  The encrypted text
1284cannot be read without the right key.
1285
1286Note: The swapfile and text in memory is not encrypted.  A system
1287administrator will be able to see your text while you are editing it.
1288When filtering text with ":!filter" or using ":w !command" the text is not
1289encrypted, this may reveal it to others.
1290
1291WARNING: If you make a typo when entering the key and then write the file and
1292exit, the text will be lost!
1293
1294The normal way to work with encryption, is to use the ":X" command, which will
1295ask you to enter a key.  A following write command will use that key to
1296encrypt the file.  If you later edit the same file, Vim will ask you to enter
1297a key.  If you type the same key as that was used for writing, the text will
1298be readable again.  If you use a wrong key, it will be a mess.
1299
1300							*:X*
1301:X	Prompt for an encryption key.  The typing is done without showing the
1302	actual text, so that someone looking at the display won't see it.
1303	The typed key is stored in the 'key' option, which is used to encrypt
1304	the file when it is written.  The file will remain unchanged until you
1305	write it.  See also |-x|.
1306
1307The value of the 'key' options is used when text is written.  When the option
1308is not empty, the written file will be encrypted, using the value as the
1309encryption key.  A magic number is prepended, so that Vim can recognize that
1310the file is encrypted.
1311
1312To disable the encryption, reset the 'key' option to an empty value: >
1313	:set key=
1314
1315When reading a file that has been encrypted and this option is not empty, it
1316will be used for decryption.  If the value is empty, you will be prompted to
1317enter the key.  If you don't enter a key, the file is edited without being
1318decrypted.
1319
1320If want to start reading a file that uses a different key, set the 'key'
1321option to an empty string, so that Vim will prompt for a new one.  Don't use
1322the ":set" command to enter the value, other people can read the command over
1323your shoulder.
1324
1325Since the value of the 'key' option is supposed to be a secret, its value can
1326never be viewed.  You should not set this option in a vimrc file.
1327
1328An encrypted file can be recognized by the "file" command, if you add this
1329line to "/etc/magic", "/usr/share/misc/magic" or wherever your system has the
1330"magic" file: >
1331     0	string	VimCrypt~	Vim encrypted file
1332
1333Notes:
1334- Encryption is not possible when doing conversion with 'charconvert'.
1335- Text you copy or delete goes to the numbered registers.  The registers can
1336  be saved in the .viminfo file, where they could be read.  Change your
1337  'viminfo' option to be safe.
1338- Someone can type commands in Vim when you walk away for a moment, he should
1339  not be able to get the key.
1340- If you make a typing mistake when entering the key, you might not be able to
1341  get your text back!
1342- If you type the key with a ":set key=value" command, it can be kept in the
1343  history, showing the 'key' value in a viminfo file.
1344- There is never 100% safety.  The encryption in Vim has not been tested for
1345  robustness.
1346- The algorithm used is breakable.  A 4 character key in about one hour, a 6
1347  character key in one day (on a Pentium 133 PC).  This requires that you know
1348  some text that must appear in the file.  An expert can break it for any key.
1349  When the text has been decrypted, this also means that the key can be
1350  revealed, and other files encrypted with the same key can be decrypted.
1351- Pkzip uses the same encryption, and US Govt has no objection to its export.
1352  Pkzip's public file APPNOTE.TXT describes this algorithm in detail.
1353- Vim originates from the Netherlands.  That is where the sources come from.
1354  Thus the encryption code is not exported from the USA.
1355
1356==============================================================================
135710. Timestamps					*timestamp* *timestamps*
1358
1359Vim remembers the modification timestamp of a file when you begin editing it.
1360This is used to avoid that you have two different versions of the same file
1361(without you knowing this).
1362
1363After a shell command is run (|:!cmd| |suspend| |:read!| |K|) timestamps are
1364compared for all buffers in a window.   Vim will run any associated
1365|FileChangedShell| autocommands or display a warning for any files that have
1366changed.  In the GUI this happens when Vim regains input focus.
1367
1368							*E321* *E462*
1369If you want to automatically reload a file when it has been changed outside of
1370Vim, set the 'autoread' option.  This doesn't work at the moment you write the
1371file though, only when the file wasn't changed inside of Vim.
1372
1373Note that if a FileChangedShell autocommand is defined you will not get a
1374warning message or prompt.  The autocommand is expected to handle this.
1375
1376There is no warning for a directory (e.g., in the |file-explorer|).  But you
1377do get warned if you started editing a new file and it was created as a
1378directory later.
1379
1380When Vim notices the timestamp of a file has changed, and the file is being
1381edited in a buffer but has not changed, Vim checks if the contents of the file
1382is equal.  This is done by reading the file again (into a hidden buffer, which
1383is immediately deleted again) and comparing the text.  If the text is equal,
1384you will get no warning.
1385
1386If you don't get warned often enough you can use the following command.
1387
1388							*:checkt* *:checktime*
1389:checkt[ime]		Check if any buffers were changed outside of Vim.
1390			This checks and warns you if you would end up with two
1391			versions of a file.
1392			If this is called from an autocommand, a ":global"
1393			command or is not typed the actual check is postponed
1394			until a moment the side effects (reloading the file)
1395			would be harmless.
1396			Each loaded buffer is checked for its associated file
1397			being changed.  If the file was changed Vim will take
1398			action.  If there are no changes in the buffer and
1399			'autoread' is set, the buffer is reloaded.  Otherwise,
1400			you are offered the choice of reloading the file.  If
1401			the file was deleted you get an error message.
1402			If the file previously didn't exist you get a warning
1403			if it exists now.
1404			Once a file has been checked the timestamp is reset,
1405			you will not be warned again.
1406
1407:[N]checkt[ime] {filename}
1408:[N]checkt[ime] [N]
1409			Check the timestamp of a specific buffer.  The buffer
1410			may be specified by name, number or with a pattern.
1411
1412
1413Before writing a file the timestamp is checked.  If it has changed, Vim will
1414ask if you really want to overwrite the file:
1415
1416	WARNING: The file has been changed since reading it!!!
1417	Do you really want to write to it (y/n)?
1418
1419If you hit 'y' Vim will continue writing the file.  If you hit 'n' the write is
1420aborted.  If you used ":wq" or "ZZ" Vim will not exit, you will get another
1421chance to write the file.
1422
1423The message would normally mean that somebody has written to the file after
1424the edit session started.  This could be another person, in which case you
1425probably want to check if your changes to the file and the changes from the
1426other person should be merged.  Write the file under another name and check for
1427differences (the "diff" program can be used for this).
1428
1429It is also possible that you modified the file yourself, from another edit
1430session or with another command (e.g., a filter command).  Then you will know
1431which version of the file you want to keep.
1432
1433
1434 vim:tw=78:ts=8:ft=help:norl:
1435