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