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