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