comparison runtime/doc/editing.txt @ 7:3fc0f57ecb91 v7.0001

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