editing.txt (71174B)
1 *editing.txt* Nvim 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7 Editing files *edit-files* 8 9 Type |gO| to see the table of contents. 10 11 ============================================================================== 12 1. Introduction *edit-intro* 13 14 Editing a file with Vim means: 15 16 1. reading the file into a buffer 17 2. changing the buffer with editor commands 18 3. writing the buffer into a file 19 20 *current-file* 21 As long as you don't write the buffer, the original file remains unchanged. 22 If you start editing a file (read a file into the buffer), the file name is 23 remembered as the "current file name". This is also known as the name of the 24 current buffer. It can be used with "%" on the command line |:_%|. 25 26 *alternate-file* 27 If there already was a current file name, then that one becomes the alternate 28 file name. It can be used with "#" on the command line |:_#| and you can use 29 the |CTRL-^| command to toggle between the current and the alternate file. 30 However, the alternate file name is not changed when |:keepalt| is used. 31 An alternate file name is remembered for each window. 32 33 *:keepa* *:keepalt* 34 :keepa[lt] {cmd} Execute {cmd} while keeping the current alternate file 35 name. Note that commands invoked indirectly (e.g., 36 with a function) may still set the alternate file 37 name. 38 39 All file names are remembered in the buffer list. When you enter a file name, 40 for editing (e.g., with ":e filename") or writing (e.g., with ":w filename"), 41 the file name is added to the list. You can use the buffer list to remember 42 which files you edited and to quickly switch from one file to another (e.g., 43 to copy text) with the |CTRL-^| command. First type the number of the file 44 and then hit CTRL-^. 45 46 47 CTRL-G or *CTRL-G* *:f* *:fi* *:file* 48 :f[ile] Prints the current file name (as typed, unless ":cd" 49 was used), the cursor position (unless the 'ruler' 50 option is set), and the file status (readonly, 51 modified, read errors, new file). See the 'shortmess' 52 option about how to make this message shorter. 53 54 :f[ile]! like |:file|, but don't truncate the name even when 55 'shortmess' indicates this. 56 57 {count}CTRL-G Like CTRL-G, but prints the current file name with 58 full path. If the count is higher than 1 the current 59 buffer number is also given. 60 61 *g_CTRL-G* *word-count* *byte-count* 62 g CTRL-G Prints the current position of the cursor in five 63 ways: Column, Line, Word, Character and Byte. If the 64 number of Characters and Bytes is the same then the 65 Character position is omitted. 66 67 If there are characters in the line that take more 68 than one position on the screen (<Tab> or special 69 character), or characters using more than one byte per 70 column (characters above 0x7F when 'encoding' is 71 utf-8), both the byte column and the screen column are 72 shown, separated by a dash. 73 74 Also see the 'ruler' option and the |wordcount()| 75 function. 76 77 *v_g_CTRL-G* 78 {Visual}g CTRL-G Similar to "g CTRL-G", but Word, Character, Line, and 79 Byte counts for the visually selected region are 80 displayed. 81 In Blockwise mode, Column count is also shown. (For 82 {Visual} see |Visual-mode|.) 83 84 *:file_f* 85 :f[ile][!] {name} Sets the current file name to {name}. The optional ! 86 avoids truncating the message, as with |:file|. 87 If the buffer did have a name, that name becomes the 88 |alternate-file| name. An unlisted buffer is created 89 to hold the old name. 90 91 See |nvim_buf_set_name()| to avoid filename escaping. 92 93 *:0file* 94 :0f[ile][!] Remove the name of the current buffer. The optional ! 95 avoids truncating the message, as with |:file|. 96 97 :buffers 98 :files 99 :ls List all the currently known file names. See 100 |windows.txt| |:files| |:buffers| |:ls|. 101 102 Vim will remember the full path name of a file name that you enter. In most 103 cases when the file name is displayed only the name you typed is shown, but 104 the full path name is being used if you used the ":cd" command |:cd|. 105 106 *home-replace* 107 If the environment variable $HOME is set, and the file name starts with that 108 string, it is often displayed with HOME replaced with "~". This was done to 109 keep file names short. When reading or writing files the full name is still 110 used, the "~" is only used when displaying file names. When replacing the 111 file name would result in just "~", "~/" is used instead (to avoid confusion 112 between options set to $HOME with 'backupext' set to "~"). 113 114 When writing the buffer, the default is to use the current file name. Thus 115 when you give the "ZZ" or ":wq" command, the original file will be 116 overwritten. If you do not want this, the buffer can be written into another 117 file by giving a file name argument to the ":write" command. For example: > 118 119 vim testfile 120 [change the buffer with editor commands] 121 :w newfile 122 :q 123 124 This will create a file "newfile", that is a modified copy of "testfile". 125 The file "testfile" will remain unchanged. Anyway, if the 'backup' option is 126 set, Vim renames or copies the original file before it will be overwritten. 127 You can use this file if you discover that you need the original file. See 128 also the 'patchmode' option. The name of the backup file is normally the same 129 as the original file with 'backupext' appended. The default "~" is a bit 130 strange to avoid accidentally overwriting existing files. If you prefer 131 ".bak" change the 'backupext' option. The backup file can be placed in 132 another directory by setting 'backupdir'. 133 134 When you started editing without giving a file name, "No File" is displayed in 135 messages. If the ":write" command is used with a file name argument, the file 136 name for the current file is set to that file name. This only happens when 137 the 'F' flag is included in 'cpoptions' (by default it is included) |cpo-F|. 138 This is useful when entering text in an empty buffer and then writing it to a 139 file. If 'cpoptions' contains the 'f' flag (by default it is NOT included) 140 |cpo-f| the file name is set for the ":read file" command. This is useful 141 when starting Vim without an argument and then doing ":read file" to start 142 editing a file. 143 When the file name was set and 'filetype' is empty the filetype detection 144 autocommands will be triggered. 145 *not-edited* 146 Because the file name was set without really starting to edit that file, you 147 are protected from overwriting that file. This is done by setting the 148 "notedited" flag. You can see if this flag is set with the CTRL-G or ":file" 149 command. It will include "[Not edited]" when the "notedited" flag is set. 150 When writing the buffer to the current file name (with ":w!"), the "notedited" 151 flag is reset. 152 153 *abandon* 154 Vim remembers whether you have changed the buffer. You are protected from 155 losing the changes you made. If you try to quit without writing, or want to 156 start editing another file, Vim will refuse this. In order to overrule this 157 protection, add a '!' to the command. The changes will then be lost. For 158 example: ":q" will not work if the buffer was changed, but ":q!" will. To see 159 whether the buffer was changed use the "CTRL-G" command. The message includes 160 the string "[Modified]" if the buffer has been changed, or "+" if the 'm' flag 161 is in 'shortmess'. 162 163 If you want to automatically save the changes without asking, switch on the 164 'autowriteall' option. 'autowrite' is the associated Vi-compatible option 165 that does not work for all commands. 166 167 If you want to keep the changed buffer without saving it, switch on the 168 'hidden' option. See |hidden-buffer|. Some commands work like this even when 169 'hidden' is not set, check the help for the command. 170 171 ============================================================================== 172 2. Editing a file *edit-a-file* 173 174 *:e* *:edit* *reload* 175 :e[dit][!] [++opt] [+cmd] 176 Edit the current file. This is useful to re-edit the 177 current file, when it has been changed outside of Vim. 178 *:edit!* *discard* 179 If [!] is given, unsaved changes in the current buffer 180 are discarded. Without [!] the command fails if there 181 are unsaved changes, unless 'autowriteall' is set and 182 the file can be written. 183 Also see |++opt| and |+cmd|. 184 185 *:edit_f* 186 :e[dit][!] [++opt] [+cmd] {file} 187 Edit {file}. 188 *:edit!_f* 189 If [!] is given, unsaved changes in the current buffer 190 are discarded. Without [!] the command fails if there 191 are unsaved changes, unless 'hidden' is set or 192 'autowriteall' is set and the file can be written. 193 Also see |++opt| and |+cmd|. 194 195 *:edit_#* *:e#* 196 :e[dit] [++opt] [+cmd] #[count] 197 Edit the [count]th buffer (as shown by |:files|). 198 This command does the same as [count] CTRL-^. But ":e 199 #" doesn't work if the alternate buffer doesn't have a 200 file name, while CTRL-^ still works then. 201 Also see |++opt| and |+cmd|. 202 203 *:ene* *:enew* 204 :ene[w] Edit a new, unnamed buffer. This fails when changes 205 have been made to the current buffer, unless 'hidden' 206 is set or 'autowriteall' is set and the file can be 207 written. 208 If 'fileformats' is not empty, the first format given 209 will be used for the new buffer. If 'fileformats' is 210 empty, the 'fileformat' of the current buffer is used. 211 212 *:ene!* *:enew!* 213 :ene[w]! Edit a new, unnamed buffer. Discard any changes to 214 the current buffer. 215 Set 'fileformat' like |:enew|. 216 217 *:fin* *:find* 218 :fin[d][!] [++opt] [+cmd] {file} 219 Find {file} in 'path' and then |:edit| it. 220 See also: 'findfunc'. 221 222 :{count}fin[d][!] [++opt] [+cmd] {file} 223 Just like ":find", but use the {count} match in 224 'path'. Thus ":2find file" will find the second 225 "file" found in 'path'. When there are fewer matches 226 for the file in 'path' than asked for, you get an 227 error message. 228 229 *:ex* 230 :ex [++opt] [+cmd] [file] 231 Same as |:edit|. 232 233 *:vi* *:visual* 234 :vi[sual][!] [++opt] [+cmd] [file] 235 When used in Ex mode: Leave |Ex-mode|, go back to 236 Normal mode. Otherwise same as |:edit|. 237 238 *:vie* *:view* 239 :vie[w][!] [++opt] [+cmd] file 240 When used in Ex mode: Leave |Ex-mode|, go back to 241 Normal mode. Otherwise same as |:edit|, but set 242 'readonly' option for this buffer. 243 244 *CTRL-^* *CTRL-6* 245 CTRL-^ Edit the alternate file. Mostly the alternate file is 246 the previously edited file. This is a quick way to 247 toggle between two files. It is equivalent to ":e #", 248 except that it also works when there is no file name. 249 250 If the 'autowrite' or 'autowriteall' option is on and 251 the buffer was changed, write it. 252 Mostly the ^ character is positioned on the 6 key, 253 pressing CTRL and 6 then gets you what we call CTRL-^. 254 But on some non-US keyboards CTRL-^ is produced in 255 another way. 256 257 {count}CTRL-^ Edit [count]th file in the buffer list (equivalent to 258 ":e #[count]"). This is a quick way to switch between 259 files. 260 See |CTRL-^| above for further details. 261 262 *gf* *E446* *E447* 263 [count]gf Edit the file whose name is under or after the cursor. 264 Mnemonic: "goto file". 265 Uses the 'isfname' option to find out which characters 266 are supposed to be in a file name. Trailing 267 punctuation characters ".,:;!" are ignored. Escaped 268 spaces "\ " are reduced to a single space. 269 Uses the 'path' option as a list of directory names to 270 look for the file. See the 'path' option for details 271 about relative directories and wildcards. 272 Uses the 'suffixesadd' option to check for file names 273 with a suffix added. 274 If the file can't be found, 'includeexpr' is used to 275 modify the name and another attempt is done. 276 If a [count] is given, the count'th file that is found 277 in the 'path' is edited. 278 This command fails if Vim refuses to |abandon| the 279 current file. 280 If you want to edit the file in a new window use 281 |CTRL-W_CTRL-F|. 282 If you do want to edit a new file, use: > 283 :e <cfile> 284 < To make gf always work like that: > 285 :map gf :e <cfile><CR> 286 < If the name is a hypertext link, that looks like 287 "type://machine/path", you need the |netrw| plugin. 288 For Unix the '~' character is expanded, like in 289 "~user/file". Environment variables are expanded too 290 |expand-env|. 291 292 *v_gf* 293 {Visual}[count]gf Same as "gf", but the highlighted text is used as the 294 name of the file to edit. 'isfname' is ignored. 295 Leading blanks are skipped, otherwise all blanks and 296 special characters are included in the file name. 297 (For {Visual} see |Visual-mode|.) 298 299 *gF* 300 [count]gF Same as "gf", except if a number follows the file 301 name, then the cursor is positioned on that line in 302 the file. 303 The file name and the number must be separated by a 304 non-filename (see 'isfname') and non-numeric 305 character. " line " is also recognized, like it is 306 used in the output of `:verbose command UserCmd` 307 White space between the filename, the separator and 308 the number are ignored. 309 Examples: 310 eval.c:10 ~ 311 eval.c @ 20 ~ 312 eval.c (30) ~ 313 eval.c 40 ~ 314 315 *v_gF* 316 {Visual}[count]gF Same as "v_gf". 317 318 These commands are used to start editing a single file. This means that the 319 file is read into the buffer and the current file name is set. The file that 320 is opened depends on the current directory, see |:cd|. 321 322 See |read-messages| for an explanation of the message that is given after the 323 file has been read. 324 325 You can use the ":e!" command if you messed up the buffer and want to start 326 all over again. The ":e" command is only useful if you have changed the 327 current file name. 328 329 *:filename* *{file}* 330 Besides the things mentioned here, more special items for where a filename is 331 expected are mentioned at |cmdline-special|. 332 333 Note for systems other than Unix: When using a command that accepts a single 334 file name (like ":edit file") spaces in the file name are allowed, but 335 trailing spaces are ignored. This is useful on systems that regularly embed 336 spaces in file names (like MS-Windows). Example: The command ":e Long File 337 Name " will edit the file "Long File Name". When using a command that accepts 338 more than one file name (like ":next file1 file2") embedded spaces must be 339 escaped with a backslash. 340 341 *wildcard* *wildcards* 342 Wildcards in {file} are expanded, but as with file completion, 'wildignore' 343 and 'suffixes' apply. Which wildcards are supported depends on the system. 344 These are the common ones: 345 `?` matches one character 346 `*` matches anything, including nothing 347 `**` matches anything, including nothing, recurses into directories 348 [abc] match 'a', 'b' or 'c' 349 350 To avoid the special meaning of the wildcards prepend a backslash. However, 351 on MS-Windows the backslash is a path separator and "path\[abc]" is still seen 352 as a wildcard when "[" is in the 'isfname' option. A simple way to avoid this 353 is to use "path\[[]abc]", this matches the file "path\[abc]". 354 355 *starstar-wildcard* 356 Expanding "**" is possible on Unix, Win32, macOS and a few other systems (but 357 it may depend on your 'shell' setting on Unix and macOS. It's known to work 358 correctly for zsh; for bash this requires at least bash version >= 4.X). 359 This allows searching a directory tree. This goes up to 100 directories deep. 360 Note there are some commands where this works slightly differently, see 361 |file-searching|. 362 Example: > 363 :n **/*.txt 364 Finds files: 365 aaa.txt ~ 366 subdir/bbb.txt ~ 367 a/b/c/d/ccc.txt ~ 368 When non-wildcard characters are used right before or after "**" these are 369 only matched in the top directory. They are not used for directories further 370 down in the tree. For example: > 371 :n /usr/inc**/types.h 372 Finds files: 373 /usr/include/types.h ~ 374 /usr/include/sys/types.h ~ 375 /usr/inc/old/types.h ~ 376 Note that the path with "/sys" is included because it does not need to match 377 "/inc". Thus it's like matching "/usr/inc*/*/*...", not 378 "/usr/inc*/inc*/inc*". 379 380 *backtick-expansion* *`-expansion* 381 On Unix and a few other systems you can also use backticks for the file name 382 argument, for example: > 383 :next `find . -name ver\\*.c -print` 384 :view `ls -t *.patch \| head -n1` 385 Vim will run the command in backticks using the 'shell' and use the standard 386 output as argument for the given Vim command (error messages from the shell 387 command will be discarded). 388 To see what shell command Vim is running, set the 'verbose' option to 4. When 389 the shell command returns a non-zero exit code, an error message will be 390 displayed and the Vim command will be aborted. To avoid this make the shell 391 always return zero like so: > 392 :next `find . -name ver\\*.c -print \|\| true` 393 394 The backslashes before the star are required to prevent the shell from 395 expanding "ver*.c" prior to execution of the find program. The backslash 396 before the shell pipe symbol "|" prevents Vim from parsing it as command 397 termination. 398 This also works for most other systems, with the restriction that the 399 backticks must be around the whole item. It is not possible to have text 400 directly before the first or just after the last backtick. 401 402 *`=* 403 You can have the backticks expanded as a Vim expression, instead of as an 404 external command, by putting an equal sign right after the first backtick, 405 e.g.: > 406 :e `=tempname()` 407 The expression can contain just about anything, thus this can also be used to 408 avoid the special meaning of '"', "|", '%' and '#'. However, 'wildignore' 409 does apply like to other wildcards. 410 411 Environment variables in the expression are expanded when evaluating the 412 expression, thus this works: > 413 :e `=$HOME .. '/.vimrc'` 414 This uses $HOME inside a string and it will be used literally, most likely not 415 what you intended: > 416 :e `='$HOME' .. '/.vimrc'` 417 418 If the expression returns a string then names are to be separated with line 419 breaks. When the result is a |List| then each item is used as a name. Line 420 breaks also separate names. 421 Note that such expressions are only supported in places where a filename is 422 expected as an argument to an Ex-command. 423 424 *++opt* *[++opt]* 425 The [++opt] argument can be used to set some options for one command, and to 426 specify the behavior for bad characters. The form is: > 427 ++{optname} 428 Or: > 429 ++{optname}={value} 430 431 Where {optname} is one of: *++ff* *++enc* *++bin* *++nobin* *++edit* 432 ff or fileformat overrides 'fileformat' 433 enc or encoding overrides 'fileencoding' 434 bin or binary sets 'binary' 435 nobin or nobinary resets 'binary' 436 bad specifies behavior for bad characters 437 edit for |:read|: keeps options as if editing a file 438 p for |:write|: creates the file's parent directory 439 440 {value} cannot contain whitespace. It can be any valid value for the options. 441 Examples: > 442 :e ++ff=unix 443 This edits the same file again with 'fileformat' set to "unix". > 444 445 :w ++enc=latin1 newfile 446 This writes the current buffer to "newfile" in latin1 format. 447 448 The message given when writing a file will show "[converted]" when 449 'fileencoding' or the value specified with ++enc differs from 'encoding'. 450 451 There may be several ++opt arguments, separated by whitespace. They must all 452 appear before any |+cmd| argument. 453 454 *++p* 455 The "++p" flag creates the parent directory of the file if it does not exist. 456 For example if you edit "foo/bar/file.txt", the ":write ++p" command creates 457 "foo/bar/" if necessary before writing the file. > 458 459 :edit foo/bar/file.txt 460 :write ++p 461 462 If you want :write (without "++p") to always create missing parent 463 directories, add this autocmd to your config: > 464 465 " Auto-create parent directories (except for URIs "://"). 466 au BufWritePre,FileWritePre * if @% !~# '\(://\)' | call mkdir(expand('<afile>:p:h'), 'p') | endif 467 < 468 469 *++bad* 470 The argument of "++bad=" specifies what happens with characters that can't be 471 converted and illegal bytes. It can be one of three things: 472 ++bad=X A single-byte character that replaces each bad character. 473 ++bad=keep Keep bad characters without conversion. Note that this may 474 result in illegal bytes in your text! 475 ++bad=drop Remove the bad characters. 476 477 The default is like "++bad=?": Replace each bad character with a question 478 mark. In some places an inverted question mark is used (0xBF). 479 480 Note that not all commands use the ++bad argument, even though they do not 481 give an error when you add it. E.g. |:write|. 482 483 Note that when reading, the 'fileformat' and 'fileencoding' options will be 484 set to the used format. When writing this doesn't happen, thus a next write 485 will use the old value of the option. Same for the 'binary' option. 486 487 488 *+cmd* *[+cmd]* 489 The [+cmd] argument can be used to position the cursor in the newly opened 490 file, or execute any other command: 491 + Start at the last line. 492 +{num} Start at line {num}. 493 +/{pat} Start at first line containing {pat}. 494 +{command} Execute {command} after opening the new file. 495 {command} is any Ex command. 496 To include a white space in the {pat} or {command}, precede it with a 497 backslash. Double the number of backslashes. > 498 :edit +/The\ book file 499 :edit +/dir\ dirname\\ file 500 :edit +set\ dir=c:\\\\temp file 501 Note that in the last example the number of backslashes is halved twice: Once 502 for the "+cmd" argument and once for the ":set" command. 503 504 *file-formats* 505 The 'fileformat' option sets the <EOL> style for a file: 506 'fileformat' characters name ~ 507 "dos" <CR><NL> or <NL> DOS format *DOS-format* 508 "unix" <NL> Unix format *Unix-format* 509 "mac" <CR> Mac format *Mac-format* 510 511 When reading a file, the mentioned characters are interpreted as the <EOL>. 512 In DOS format (default for Windows), <CR><NL> and <NL> are both interpreted as 513 the <EOL>. Note that when writing the file in DOS format, <CR> characters will 514 be added for each single <NL>. Also see |file-read|. 515 516 When writing a file, the mentioned characters are used for <EOL>. For DOS 517 format <CR><NL> is used. Also see |DOS-format-write|. 518 519 You can read a file in DOS format and write it in Unix format. This will 520 replace all <CR><NL> pairs by <NL> (assuming 'fileformats' includes "dos"): > 521 :e file 522 :set fileformat=unix 523 :w 524 If you read a file in Unix format and write with DOS format, all <NL> 525 characters will be replaced with <CR><NL> (assuming 'fileformats' includes 526 "unix"): > 527 :e file 528 :set fileformat=dos 529 :w 530 531 If you start editing a new file and the 'fileformats' option is not empty 532 (which is the default), Vim will try to detect whether the lines in the file 533 are separated by the specified formats. When set to "unix,dos", Vim will 534 check for lines with a single <NL> (as used on Unix) or by a <CR><NL> pair 535 (MS-Windows). Only when ALL lines end in <CR><NL>, 'fileformat' is 536 set to "dos", otherwise it is set to "unix". When 'fileformats' includes 537 "mac", and no <NL> characters are found in the file, 'fileformat' is set to 538 "mac". 539 540 If the 'fileformat' option is set to "dos" on non-MS-Windows systems the 541 message "[dos]" is shown to remind you that something unusual is happening. On 542 MS-Windows systems you get the message "[unix]" if 'fileformat' is set to 543 "unix". On all systems you get the message "[mac]" if 'fileformat' is set to 544 "mac". 545 546 If the 'fileformats' option is empty and DOS format is used, but while reading 547 a file some lines did not end in <CR><NL>, "[CR missing]" will be included in 548 the file message. 549 If the 'fileformats' option is empty and Mac format is used, but while reading 550 a file a <NL> was found, "[NL missing]" will be included in the file message. 551 552 If the new file does not exist, the 'fileformat' of the current buffer is used 553 when 'fileformats' is empty. Otherwise the first format from 'fileformats' is 554 used for the new file. 555 556 Before editing binary, executable or Vim script files you should set the 557 'binary' option. A simple way to do this is by starting Vim with the "-b" 558 option. This will avoid the use of 'fileformat'. Without this you risk that 559 single <NL> characters are unexpectedly replaced with <CR><NL>. 560 561 END OF LINE AND END OF FILE *eol-and-eof* 562 563 Vim has several options to control the file format: 564 'fileformat' the <EOL> style: Unix, DOS, Mac 565 'endofline' whether the last line ends with a <EOL> 566 'endoffile' whether the file ends with a CTRL-Z 567 'fixendofline' whether to fix eol and eof 568 569 The first three values are normally detected automatically when reading the 570 file and are used when writing the text to a file. While editing the buffer 571 it looks like every line has a line ending and the CTRL-Z isn't there (an 572 exception is when 'binary' is set, it works differently then). 573 574 The 'fixendofline' option can be used to choose what to write. You can also 575 change the option values to write the file differently than how it was read. 576 577 Here are some examples how to use them. 578 579 If you want files in Unix format (every line NL terminated): > 580 setl ff=unix fixeol 581 You should probably do this on any Unix-like system. Also modern MS-Windows 582 systems tend to work well with this. It is recommended to always use this 583 format for Vim scripts. 584 585 If you want to use an old MS-DOS file in a modern environment, fixing line 586 endings and dropping CTRL-Z, but keeping the <CR><NL> style <EOL>: > 587 setl ff=dos fixeol 588 This is useful for many MS-Windows programs, they regularly expect the 589 <CR><NL> line endings. 590 591 If you want to drop the final <EOL> and add a final CTRL-Z (e.g. for an old 592 system like CP/M): > 593 setl ff=dos nofixeol noeol eof 594 595 If you want to preserve the fileformat exactly as-is, including any final 596 <EOL> and final CTRL-Z: > 597 setl nofixeol 598 599 ============================================================================== 600 3. The argument list *argument-list* *arglist* 601 602 If you give more than one file name when starting Vim, this list is remembered 603 as the argument list. You can jump to each file in this list. 604 605 Do not confuse this with the buffer list, which you can see with the 606 |:buffers| command. The argument list was already present in Vi, the buffer 607 list is new in Vim. Every file name in the argument list will also be present 608 in the buffer list (unless it was deleted with |:bdel| or |:bwipe|). But it's 609 common that names in the buffer list are not in the argument list. 610 611 This subject is introduced in section |07.2| of the user manual. 612 613 There is one global argument list, which is used for all windows by default. 614 It is possible to create a new argument list local to a window, see 615 |:arglocal|. 616 617 You can use the argument list with the following commands, and with the 618 expression functions |argc()| and |argv()|. These all work on the argument 619 list of the current window. 620 621 *:ar* *:arg* *:args* 622 :ar[gs] Print the argument list, with the current file in 623 square brackets. 624 625 :ar[gs] [++opt] [+cmd] {arglist} *:args_f* 626 Define {arglist} as the new argument list and edit 627 the first one. This fails when changes have been made 628 and Vim does not want to |abandon| the current buffer. 629 Also see |++opt| and |+cmd|. 630 631 :ar[gs]! [++opt] [+cmd] {arglist} *:args_f!* 632 Define {arglist} as the new argument list and edit 633 the first one. Discard any changes to the current 634 buffer. 635 Also see |++opt| and |+cmd|. 636 637 :[count]arge[dit][!] [++opt] [+cmd] {name} ... *:arge* *:argedit* 638 Add {name}s to the argument list and edit it. 639 There is no check for duplicates, it is possible to 640 add a file to the argument list twice |:argded|. 641 This is like using |:argadd| and then |:edit| (with 642 the small exception that |:edit| does not change the 643 argument list, so the argument list pointer isn't 644 changed). 645 Spaces in filenames have to be escaped with "\". 646 [count] is used like with |:argadd|. 647 If the current file cannot be |abandon|ed {name}s will 648 still be added to the argument list, but won't be 649 edited. No check for duplicates is done. 650 Also see |++opt| and |+cmd|. 651 652 :[count]arga[dd] {name} ... *:arga* *:argadd* *E479* 653 :[count]arga[dd] *E1156* 654 Add the {name}s to the argument list. When {name} is 655 omitted add the current buffer name to the argument 656 list. 657 If [count] is omitted, the {name}s are added just 658 after the current entry in the argument list. 659 Otherwise they are added after the [count]'th file. 660 If the argument list is "a b c", and "b" is the 661 current argument, then these commands result in: 662 command new argument list ~ 663 :argadd x a [b] x c 664 :0argadd x x a [b] c 665 :1argadd x a x [b] c 666 :$argadd x a [b] c x 667 And after the last one: 668 :+2argadd y a [b] c x y 669 There is no check for duplicates, it is possible to 670 add a file to the argument list twice. You can use 671 |:argdedupe| to fix it afterwards: > 672 :argadd *.txt | argdedupe 673 < The currently edited file is not changed. 674 Note: you can also use this method: > 675 :args ## x 676 < This will add the "x" item and sort the new list. 677 678 :argded[upe] *:argded* *:argdedupe* 679 Remove duplicate filenames from the argument list. 680 If your current file is a duplicate, your current file 681 will change to the original file index. 682 683 :argd[elete] {pattern} ... *:argd* *:argdelete* *E480* *E610* 684 Delete files from the argument list that match the 685 {pattern}s. {pattern} is used like a file pattern, 686 see |file-pattern|. "%" can be used to delete the 687 current entry. 688 This command keeps the currently edited file, also 689 when it's deleted from the argument list. 690 Example: > 691 :argdel *.obj 692 693 :[range]argd[elete] Delete the [range] files from the argument list. 694 Example: > 695 :10,$argdel 696 < Deletes arguments 10 and further, keeping 1-9. > 697 :$argd 698 < Deletes just the last one. > 699 :argd 700 :.argd 701 < Deletes the current argument. > 702 :%argd 703 < Removes all the files from the arglist. 704 When the last number in the range is too high, up to 705 the last argument is deleted. 706 707 *:argu* *:argument* 708 :[count]argu[ment] [count] [++opt] [+cmd] 709 Edit file [count] in the argument list. When [count] 710 is omitted the current entry is used. This fails 711 when changes have been made and Vim does not want to 712 |abandon| the current buffer. 713 Also see |++opt| and |+cmd|. 714 715 :[count]argu[ment]! [count] [++opt] [+cmd] 716 Edit file [count] in the argument list, discard any 717 changes to the current buffer. When [count] is 718 omitted the current entry is used. 719 Also see |++opt| and |+cmd|. 720 721 :[count]n[ext] [++opt] [+cmd] *:n* *:ne* *:next* *E165* *E163* 722 Edit [count] next file. This fails when changes have 723 been made and Vim does not want to |abandon| the 724 current buffer. Also see |++opt| and |+cmd|. 725 726 *]a* 727 ]a Mapped to |:next|. |default-mappings| 728 729 :[count]n[ext]! [++opt] [+cmd] 730 Edit [count] next file, discard any changes to the 731 buffer. Also see |++opt| and |+cmd|. 732 733 :n[ext] [++opt] [+cmd] {arglist} *:next_f* 734 Same as |:args_f|. 735 736 :n[ext]! [++opt] [+cmd] {arglist} 737 Same as |:args_f!|. 738 739 :[count]N[ext] [count] [++opt] [+cmd] *:Next* *:N* *E164* 740 Edit [count] previous file in argument list. This 741 fails when changes have been made and Vim does not 742 want to |abandon| the current buffer. 743 Also see |++opt| and |+cmd|. 744 745 :[count]N[ext]! [count] [++opt] [+cmd] 746 Edit [count] previous file in argument list. Discard 747 any changes to the buffer. Also see |++opt| and 748 |+cmd|. 749 750 :[count]prev[ious] [count] [++opt] [+cmd] *:prev* *:previous* 751 Same as :Next. Also see |++opt| and |+cmd|. 752 753 *[a* 754 [a Mapped to |:previous|. |default-mappings| 755 756 *:rew* *:rewind* 757 :rew[ind] [++opt] [+cmd] 758 Start editing the first file in the argument list. 759 This fails when changes have been made and Vim does 760 not want to |abandon| the current buffer. 761 Also see |++opt| and |+cmd|. 762 763 *[A* 764 [A Mapped to |:rewind|. |default-mappings| 765 766 :rew[ind]! [++opt] [+cmd] 767 Start editing the first file in the argument list. 768 Discard any changes to the buffer. Also see |++opt| 769 and |+cmd|. 770 771 *:fir* *:first* 772 :fir[st][!] [++opt] [+cmd] 773 Other name for ":rewind". 774 775 *:la* *:last* 776 :la[st] [++opt] [+cmd] 777 Start editing the last file in the argument list. 778 This fails when changes have been made and Vim does 779 not want to |abandon| the current buffer. 780 Also see |++opt| and |+cmd|. 781 782 *]A* 783 ]A Mapped to |:last|. |default-mappings| 784 785 :la[st]! [++opt] [+cmd] 786 Start editing the last file in the argument list. 787 Discard any changes to the buffer. Also see |++opt| 788 and |+cmd|. 789 790 *:wn* *:wnext* 791 :[count]wn[ext] [++opt] 792 Write current file and start editing the [count] 793 next file. Also see |++opt| and |+cmd|. 794 795 :[count]wn[ext] [++opt] {file} 796 Write current file to {file} and start editing the 797 [count] next file, unless {file} already exists and 798 the 'writeany' option is off. Also see |++opt| and 799 |+cmd|. 800 801 :[count]wn[ext]! [++opt] {file} 802 Write current file to {file} and start editing the 803 [count] next file. Also see |++opt| and |+cmd|. 804 805 :[count]wN[ext][!] [++opt] [file] *:wN* *:wNext* 806 :[count]wp[revious][!] [++opt] [file] *:wp* *:wprevious* 807 Same as :wnext, but go to previous file instead of 808 next. 809 810 The [count] in the commands above defaults to one. For some commands it is 811 possible to use two counts. The last one (rightmost one) is used. 812 813 If no [+cmd] argument is present, the cursor is positioned at the last known 814 cursor position for the file. If 'startofline' is set, the cursor will be 815 positioned at the first non-blank in the line, otherwise the last know column 816 is used. If there is no last known cursor position the cursor will be in the 817 first line (the last line in Ex mode). 818 819 *{arglist}* 820 The wildcards in the argument list are expanded and the file names are sorted. 821 Thus you can use the command `vim *.c` to edit all the C files. From within 822 Vim the command `:n *.c` does the same. 823 824 White space is used to separate file names. Put a backslash before a space or 825 tab to include it in a file name. E.g., to edit the single file "foo bar": > 826 :next foo\ bar 827 828 On Unix and a few other systems you can also use backticks, for example: > 829 :next `find . -name \\*.c -print` 830 The backslashes before the star are required to prevent "*.c" to be expanded 831 by the shell before executing the find program. 832 833 *arglist-position* 834 When there is an argument list you can see which file you are editing in the 835 title of the window (if there is one and 'title' is on) and with the file 836 message you get with the "CTRL-G" command. You will see something like 837 (4 of 11) 838 If you are not really editing the file at the current position in the argument 839 list it will be 840 ((4) of 11) 841 This means that you are position 4 in the argument list, but not editing the 842 fourth file in the argument list. This happens when you do ":e file". 843 844 845 LOCAL ARGUMENT LIST 846 847 *:arglocal* 848 :argl[ocal] Make a local copy of the global argument list. 849 Doesn't start editing another file. 850 851 :argl[ocal][!] [++opt] [+cmd] {arglist} 852 Define a new argument list, which is local to the 853 current window. Works like |:args_f| otherwise. 854 855 *:argglobal* 856 :argg[lobal] Use the global argument list for the current window. 857 Doesn't start editing another file. 858 859 :argg[lobal][!] [++opt] [+cmd] {arglist} 860 Use the global argument list for the current window. 861 Define a new global argument list like |:args_f|. 862 All windows using the global argument list will see 863 this new list. 864 865 There can be several argument lists. They can be shared between windows. 866 When they are shared, changing the argument list in one window will also 867 change it in the other window. 868 869 When a window is split the new window inherits the argument list from the 870 current window. The two windows then share this list, until one of them uses 871 |:arglocal| or |:argglobal| to use another argument list. 872 873 874 USING THE ARGUMENT LIST 875 876 *:argdo* 877 :[range]argdo[!] {cmd} Execute {cmd} for each file in the argument list or, 878 if [range] is specified, only for arguments in that 879 range. It works like doing this: > 880 :rewind 881 :{cmd} 882 :next 883 :{cmd} 884 etc. 885 < When the current file can't be |abandon|ed and the [!] 886 is not present, the command fails. 887 When an error is detected on one file, further files 888 in the argument list will not be visited. 889 The last file in the argument list (or where an error 890 occurred) becomes the current file. 891 {cmd} can contain '|' to concatenate several commands. 892 {cmd} must not change the argument list. 893 Note: While this command is executing, the Syntax 894 autocommand event is disabled by adding it to 895 'eventignore'. This considerably speeds up editing 896 each file. 897 Also see |:windo|, |:tabdo|, |:bufdo|, |:cdo|, |:ldo|, 898 |:cfdo| and |:lfdo|. 899 900 Example: > 901 :args *.c 902 :argdo set ff=unix | update 903 This sets the 'fileformat' option to "unix" and writes the file if it is now 904 changed. This is done for all `*.c` files. 905 906 Example: > 907 :args *.[ch] 908 :argdo %s/\<my_foo\>/My_Foo/ge | update 909 This changes the word "my_foo" to "My_Foo" in all "*.c" and "*.h" files. The "e" 910 flag is used for the ":substitute" command to avoid an error for files where 911 "my_foo" isn't used. ":update" writes the file only if changes were made. 912 913 ============================================================================== 914 4. Writing *writing* *save-file* 915 916 Note: When the 'write' option is off, you are not able to write any file. 917 918 *:w* *:write* 919 *E502* *E503* *E504* *E505* 920 *E512* *E514* *E667* *E949* 921 :w[rite] [++opt] Write the whole buffer to the current file. This is 922 the normal way to save changes to a file. Fails when 923 'readonly' is set or when there is another reason why 924 the file can't be written, such as when the parent 925 directory doesn't exist (use |++p| to avoid that). 926 For ++opt see |++opt|, but only ++p, ++bin, ++nobin, 927 ++ff and ++enc are effective. 928 929 930 :w[rite]! [++opt] Like ":write", but forcefully write when 'readonly' is 931 set or there is another reason why writing was 932 refused. 933 Note: This may change the permission and ownership of 934 the file and break (symbolic) links. Add the 'W' flag 935 to 'cpoptions' to avoid this. 936 937 :[range]w[rite][!] [++opt] 938 Write the specified lines to the current file. This 939 is unusual, because the file will not contain all 940 lines in the buffer. 941 942 *:w_f* *:write_f* 943 :[range]w[rite] [++opt] {file} 944 Write the specified lines to {file}, unless it 945 already exists and the 'writeany' option is off. 946 947 *:w!* 948 :[range]w[rite]! [++opt] {file} 949 Write the specified lines to {file}. Overwrite an 950 existing file. 951 952 *:w_a* *:write_a* *E494* 953 :[range]w[rite][!] [++opt] >> 954 Append the specified lines to the current file. 955 956 :[range]w[rite][!] [++opt] >> {file} 957 Append the specified lines to {file}. '!' forces the 958 write even if file does not exist. 959 960 *:w_c* *:write_c* 961 :[range]w[rite] [++opt] !{cmd} 962 Execute {cmd} with [range] lines as standard input 963 (note the space in front of the '!'). {cmd} is 964 executed like with ":!{cmd}", any '!' is replaced with 965 the previous command |:!|. 966 967 The default [range] for the ":w" command is the whole buffer (1,$). The |'[| 968 and |']| marks will be set to the [range] being used for the write command. 969 If you write the whole buffer, it is no longer considered changed. When you 970 write it to a different file with ":w somefile" it depends on the "+" flag in 971 'cpoptions'. When included, the write command will reset the 'modified' flag, 972 even though the buffer itself may still be different from its file. 973 974 If a file name is given with ":w" it becomes the alternate file. This can be 975 used, for example, when the write fails and you want to try again later with 976 ":w #". This can be switched off by removing the 'A' flag from the 977 'cpoptions' option. 978 979 Note that the 'fsync' option matters here. If it's set it may make writes 980 slower (but safer). 981 982 *:sav* *:saveas* 983 :sav[eas][!] [++opt] {file} 984 Save the current buffer under the name {file} and set 985 the filename of the current buffer to {file}. The 986 previous name is used for the alternate file name. 987 The [!] is needed to overwrite an existing file. 988 When 'filetype' is empty filetype detection is done 989 with the new name, before the file is written. 990 When the write was successful 'readonly' is reset. 991 992 *:up* *:update* 993 :[range]up[date][!] [++opt] [>>] [file] 994 Like ":write", but only write when the buffer has been 995 modified, or when the buffer represents a new file 996 that doesn't exist on disk. 997 998 999 WRITING WITH MULTIPLE BUFFERS *buffer-write* 1000 1001 *:wa* *:wall* 1002 :wa[ll] [++opt] Write all changed buffers. Buffers without a file 1003 name cause an error message. Buffers which are 1004 readonly are not written. 1005 For ++opt see |++opt|, but only ++p is effective, and 1006 applies to each written file. 1007 1008 :wa[ll]! [++opt] Write all changed buffers, even the ones that are 1009 readonly. Buffers without a file name are not 1010 written and cause an error message. 1011 1012 1013 Vim will warn you if you try to overwrite a file that has been changed 1014 elsewhere (unless "!" was used). See |timestamp|. 1015 1016 *backup* *E207* *E506* *E507* *E508* *E509* *E510* 1017 If you write to an existing file (but do not append) while the 'backup', 1018 'writebackup' or 'patchmode' option is on, a backup of the original file is 1019 made. The file is either copied or renamed (see 'backupcopy'). After the 1020 file has been successfully written and when the 'writebackup' option is on and 1021 the 'backup' option is off, the backup file is deleted. When the 'patchmode' 1022 option is on the backup file may be renamed. 1023 1024 *backup-table* 1025 'backup' 'writebackup' action ~ 1026 off off no backup made 1027 off on backup current file, deleted afterwards (default) 1028 on off delete old backup, backup current file 1029 on on delete old backup, backup current file 1030 1031 When the 'backupskip' pattern matches with the name of the file which is 1032 written, no backup file is made. The values of 'backup' and 'writebackup' are 1033 ignored then. 1034 1035 When the 'backup' option is on, an old backup file (with the same name as the 1036 new backup file) will be deleted. If 'backup' is not set, but 'writebackup' 1037 is set, an existing backup file will not be deleted. The backup file that is 1038 made while the file is being written will have a different name. 1039 1040 On some filesystems it's possible that in a crash you lose both the backup and 1041 the newly written file (it might be there but contain bogus data). In that 1042 case try recovery, because the swap file is synced to disk and might still be 1043 there. |:recover| 1044 1045 The directories given with the 'backupdir' option are used to put the backup 1046 file in. (default: same directory as the written file). 1047 1048 Whether the backup is a new file, which is a copy of the original file, or the 1049 original file renamed depends on the 'backupcopy' option. See there for an 1050 explanation of when the copy is made and when the file is renamed. 1051 1052 If the creation of a backup file fails, the write is not done. If you want 1053 to write anyway add a '!' to the command. 1054 1055 *file-watcher* 1056 When you notice issues with programs, that act upon when a buffer is written 1057 (like inotify, entr or fswatch) or when external applications execute Vim to 1058 edit the file (like git) and those programs do not seem to notice that the 1059 original file has been changed, you may want to consider switching the 1060 'backupcopy' option value to "yes". This makes sure, Vim writes to the same 1061 file, that those watcher programs expect, without creating a new file (which 1062 prevents them from detecting that the file has changed). See also |crontab| 1063 1064 *write-permissions* 1065 When writing a new file the permissions are read-write. For unix the mask is 1066 0o666 with additionally umask applied. When writing a file that was read Vim 1067 will preserve the permissions, but clear the s-bit. 1068 1069 *write-readonly* 1070 When the 'cpoptions' option contains 'W', Vim will refuse to overwrite a 1071 readonly file. When 'W' is not present, ":w!" will overwrite a readonly file, 1072 if the system allows it (the directory must be writable). 1073 1074 *write-fail* 1075 If the writing of the new file fails, you have to be careful not to lose 1076 your changes AND the original file. If there is no backup file and writing 1077 the new file failed, you have already lost the original file! DON'T EXIT VIM 1078 UNTIL YOU WRITE OUT THE FILE! If a backup was made, it is put back in place 1079 of the original file (if possible). If you exit Vim, and lose the changes 1080 you made, the original file will mostly still be there. If putting back the 1081 original file fails, there will be an error message telling you that you 1082 lost the original file. 1083 1084 *DOS-format-write* 1085 If the 'fileformat' is "dos", <CR><NL> is used for <EOL>. This is default 1086 for Windows. On other systems the message "[dos]" is shown to 1087 remind you that an unusual <EOL> was used. 1088 *Unix-format-write* 1089 If the 'fileformat' is "unix", <NL> is used for <EOL>. On Windows 1090 the message "[unix]" is shown. 1091 *Mac-format-write* 1092 If the 'fileformat' is "mac", <CR> is used for <EOL>. The 1093 message "[mac]" is shown. 1094 1095 See also |file-formats| and the 'fileformat' and 'fileformats' options. 1096 1097 *ACL* 1098 ACL stands for Access Control List. It is an advanced way to control access 1099 rights for a file. It is used on new MS-Windows and Unix systems, but only 1100 when the filesystem supports it. 1101 Vim attempts to preserve the ACL info when writing a file. The backup file 1102 will get the ACL info of the original file. 1103 The ACL info is also used to check if a file is read-only (when opening the 1104 file). 1105 1106 *xattr* *E1506* *E1508* *E1509* 1107 xattr stands for Extended Attributes. It is an advanced way to save metadata 1108 alongside the file in the filesystem. It depends on the actual filesystem 1109 being used and Vim supports it only on a Linux system. 1110 Vim attempts to preserve the extended attribute info when writing a file. 1111 The backup file will get the extended attribute of the original file. 1112 1113 *read-only-share* 1114 When MS-Windows shares a drive on the network it can be marked as read-only. 1115 This means that even if the file read-only attribute is absent, and the ACL 1116 settings on NT network shared drives allow writing to the file, you can still 1117 not write to the file. Vim on Win32 platforms will detect read-only network 1118 drives and will mark the file as read-only. You will not be able to override 1119 it with |:write|. 1120 1121 *write-device* 1122 When the file name is actually a device name, Vim will not make a backup (that 1123 would be impossible). You need to use "!", since the device already exists. 1124 Example for Unix: > 1125 :w! /dev/lpt0 1126 and MS-Windows: > 1127 :w! lpt0 1128 For Unix a device is detected when the name doesn't refer to a normal file or 1129 a directory. A fifo or named pipe also looks like a device to Vim. 1130 For MS-Windows the device is detected by its name: 1131 CON 1132 CLOCK$ 1133 NUL 1134 PRN 1135 COMn n=1,2,3... etc 1136 LPTn n=1,2,3... etc 1137 The names can be in upper- or lowercase. 1138 1139 ============================================================================== 1140 5. Writing and quitting *write-quit* 1141 1142 *:q* *:quit* 1143 :q[uit] Quit the current window. Quit Vim if this is the last 1144 |edit-window|. This fails when changes have been made 1145 and Vim refuses to |abandon| the current buffer, and 1146 when the last file in the argument list has not been 1147 edited. 1148 If there are other tab pages and quitting the last 1149 window in the current tab page the current tab page is 1150 closed |tab-page|. 1151 Triggers the |QuitPre| autocommand event. 1152 See |CTRL-W_q| for quitting another window. 1153 1154 :conf[irm] q[uit] Quit, but give prompt when changes have been made, or 1155 the last file in the argument list has not been 1156 edited. See |:confirm| and 'confirm'. 1157 1158 :q[uit]! Quit without writing, also when the current buffer has 1159 changes. The buffer is unloaded, also when it has 1160 'hidden' set. 1161 If this is the last window and there is a modified 1162 hidden buffer, the current buffer is abandoned and the 1163 first changed hidden buffer becomes the current 1164 buffer. 1165 Use ":qall!" to exit always. 1166 1167 :cq[uit] Quit always, without writing, and return an error 1168 code. See |:cq|. 1169 1170 *:wq* 1171 :wq [++opt] Write the current file and close the window. If this 1172 was the last |edit-window| Vim quits. 1173 Writing fails when the file is read-only or the buffer 1174 does not have a name. Quitting fails when the last 1175 file in the argument list has not been edited. 1176 1177 :wq! [++opt] Write the current file and close the window. If this 1178 was the last |edit-window| Vim quits. Writing fails 1179 when the current buffer does not have a name. 1180 1181 :wq [++opt] {file} Write to {file} and close the window. If this was the 1182 last |edit-window| Vim quits. Quitting fails when the 1183 last file in the argument list has not been edited. 1184 1185 :wq! [++opt] {file} Write to {file} and close the current window. Quit 1186 Vim if this was the last |edit-window|. 1187 1188 :[range]wq[!] [++opt] [file] 1189 Same as above, but only write the lines in [range]. 1190 1191 *:x* *:xit* 1192 :[range]x[it][!] [++opt] [file] 1193 Like ":wq", but write only when changes have been 1194 made. 1195 When 'hidden' is set and there are more windows, the 1196 current buffer becomes hidden, after writing the file. 1197 1198 *:exi* *:exit* 1199 :[range]exi[t][!] [++opt] [file] 1200 Same as :xit. 1201 1202 *ZZ* 1203 ZZ Write current file, if modified, and close the current 1204 window (same as ":x"). 1205 If there are several windows for the current file, 1206 only the current window is closed. 1207 1208 *ZQ* 1209 ZQ Quit without checking for changes (same as ":q!"). 1210 1211 MULTIPLE WINDOWS AND BUFFERS *window-exit* 1212 1213 *:qa* *:qall* 1214 :qa[ll] Exit Vim, unless there are some buffers which have been 1215 changed. (Use ":bmod" to go to the next modified buffer). 1216 When 'autowriteall' is set all changed buffers will be 1217 written, like |:wqall|. 1218 1219 :conf[irm] qa[ll] 1220 Exit Vim. Bring up a prompt when some buffers have been 1221 changed. See |:confirm|. 1222 1223 :qa[ll]! Exit Vim. Any changes to buffers are lost. 1224 Also see |:cquit|, it does the same but exits with a non-zero 1225 value. 1226 1227 *:quita* *:quitall* 1228 :quita[ll][!] Same as ":qall". 1229 1230 :wqa[ll] [++opt] *:wqa* *:wqall* *:xa* *:xall* 1231 :xa[ll] Write all changed buffers and exit Vim. If there are buffers 1232 without a file name, which are readonly or which cannot be 1233 written for another reason, Vim will not quit. 1234 1235 :conf[irm] wqa[ll] [++opt] 1236 :conf[irm] xa[ll] 1237 Write all changed buffers and exit Vim. Bring up a prompt 1238 when some buffers are readonly or cannot be written for 1239 another reason. See |:confirm|. 1240 1241 :wqa[ll]! [++opt] 1242 :xa[ll]! Write all changed buffers, even the ones that are readonly, 1243 and exit Vim. If there are buffers without a file name or 1244 which cannot be written for another reason, Vim will not quit. 1245 1246 ============================================================================== 1247 6. Dialogs *edit-dialogs* 1248 1249 *:confirm* *:conf* 1250 :conf[irm] {command} Execute {command}, and use a dialog when an 1251 operation has to be confirmed. Can be used on the 1252 |:edit|, |:restart|, |:q|, |:qa| and |:w| commands 1253 (the latter to override a read-only setting), and any 1254 commands that can fail because of unsaved changes, 1255 such as |:only|, |:buffer|, |:bdelete|, etc. 1256 1257 Examples: > 1258 :confirm w foo 1259 < Will ask for confirmation when "foo" already exists. > 1260 :confirm q 1261 < Will ask for confirmation when there are changes. > 1262 :confirm qa 1263 < If any modified, unsaved buffers exist, you will be prompted to save 1264 or abandon each one. There are also choices to "save all" or "abandon 1265 all". 1266 1267 If you want to always use ":confirm", set the 'confirm' option. 1268 1269 *:browse* *:bro* *E338* *E614* *E615* *E616* 1270 :bro[wse] {command} Open a file selection dialog for an argument to 1271 {command}. At present this works for |:e|, |:w|, 1272 |:wall|, |:wq|, |:wqall|, |:x|, |:xall|, |:exit|, 1273 |:view|, |:sview|, |:r|, |:saveas|, |:sp|, |:mkexrc|, 1274 |:mkvimrc|, |:mksession|, |:mkview|, |:split|, 1275 |:vsplit|, |:tabe|, |:tabnew|, |:cfile|, |:cgetfile|, 1276 |:caddfile|, |:lfile|, |:lgetfile|, |:laddfile|, 1277 |:diffsplit|, |:diffpatch|, |:pedit|, |:redir|, 1278 |:source|, |:update|, |:visual|, |:vsplit|, 1279 and |:qall| if 'confirm' is set. 1280 Note: only in Win32 GUI; in console `:browse edit` 1281 works if the FileExplorer autocommand group exists. 1282 When ":browse" is not possible you get an error 1283 message. If {command} doesn't support browsing, the 1284 {command} is executed without a dialog. 1285 ":browse set" works like |:options|. 1286 See also |:oldfiles| for ":browse oldfiles". 1287 1288 The syntax is best shown via some examples: > 1289 :browse e $vim/foo 1290 < Open the browser in the $vim/foo directory, and edit the 1291 file chosen. > 1292 :browse e 1293 < Open the browser in the directory specified with 'browsedir', 1294 and edit the file chosen. > 1295 :browse w 1296 < Open the browser in the directory of the current buffer, 1297 with the current buffer filename as default, and save the 1298 buffer under the filename chosen. > 1299 :browse w C:/bar 1300 < Open the browser in the C:/bar directory, with the current 1301 buffer filename as default, and save the buffer under the 1302 filename chosen. 1303 Also see the 'browsedir' option. 1304 For versions of Vim where browsing is not supported, the command is executed 1305 unmodified. 1306 1307 *browsefilter* 1308 For MS-Windows you can modify the filters that are used in the browse 1309 dialog. By setting the g:browsefilter or b:browsefilter variables, you can 1310 change the filters globally or locally to the buffer. The variable is set to 1311 a string in the format "{filter label}\t{pattern};{pattern}\n" where "{filter 1312 label}" is the text that appears in the "Files of Type" comboBox, and {pattern} 1313 is the pattern which filters the filenames. Several patterns can be given, 1314 separated by ';'. 1315 1316 For example, to have only Vim files in the dialog, you could use the following 1317 command: > 1318 1319 let g:browsefilter = "Vim scripts\t*.vim\nVim Startup Files\t*vimrc\n" 1320 1321 You can override the filter setting on a per-buffer basis by setting the 1322 b:browsefilter variable. You would most likely set b:browsefilter in a 1323 filetype plugin, so that the browse dialog would contain entries related to 1324 the type of file you are currently editing. Disadvantage: This makes it 1325 difficult to start editing a file of a different type. To overcome this, you 1326 can add the following as the final filter on Windows: > 1327 1328 All Files\t(*.*)\t*\n 1329 < 1330 Or the following on other platforms, so that the user can still access any 1331 desired file: > 1332 1333 All Files\t(*)\t*\n 1334 < 1335 1336 To avoid setting browsefilter when Vim does not actually support it, you can 1337 use has("browsefilter"): > 1338 1339 if has("browsefilter") 1340 let g:browsefilter = "whatever" 1341 endif 1342 1343 ============================================================================== 1344 7. The current directory *current-directory* 1345 1346 You can use |:cd|, |:tcd| and |:lcd| to change to another directory, so you 1347 will not have to type that directory name in front of the file names. It also 1348 makes a difference for executing external commands, e.g. ":!ls" or ":te ls". 1349 1350 There are three current-directory "scopes": global, tab and window. The 1351 window-local working directory takes precedence over the tab-local 1352 working directory, which in turn takes precedence over the global 1353 working directory. If a local working directory (tab or window) does not 1354 exist, the next-higher scope in the hierarchy applies. 1355 1356 *:cd* *E747* *E472* 1357 :cd[!] On non-Unix systems when 'cdhome' is off: Print the 1358 current directory name. 1359 Otherwise: Change the current directory to the home 1360 directory. Clear any window-local directory. 1361 Use |:pwd| to print the current directory on all 1362 systems. 1363 1364 :cd[!] {path} Change the current directory to {path}. 1365 If {path} is relative, it is searched for in the 1366 directories listed in 'cdpath'. 1367 Clear any window-local directory. 1368 Does not change the meaning of an already opened file, 1369 because its full path name is remembered. Files from 1370 the |arglist| may change though! 1371 On MS-Windows this also changes the active drive. 1372 To change to the directory of the current file: > 1373 :cd %:h 1374 < 1375 *:cd-* *E186* 1376 :cd[!] - Change to the previous current directory (before the 1377 previous ":cd {path}" command). 1378 1379 *:chd* *:chdir* 1380 :chd[ir][!] [path] Same as |:cd|. 1381 1382 *:tc* *:tcd* 1383 :tc[d][!] {path} Like |:cd|, but only set the directory for the current 1384 tab. The current window will also use this directory. 1385 The current directory is not changed for windows in 1386 other tabs and for windows in the current tab that 1387 have their own window-local directory. 1388 1389 *:tcd-* 1390 :tc[d][!] - Change to the previous current directory (before the 1391 previous ":tcd {path}" command). 1392 1393 *:tch* *:tchdir* 1394 :tch[dir][!] Same as |:tcd|. 1395 1396 *:lc* *:lcd* 1397 :lc[d][!] {path} Like |:cd|, but only set the current directory for the 1398 current window. The current directory for other 1399 windows or tabs is not changed. 1400 1401 *:lch* *:lchdir* 1402 :lch[dir][!] Same as |:lcd|. 1403 1404 *:lcd-* 1405 :lc[d][!] - Change to the previous current directory (before the 1406 previous ":lcd {path}" command). 1407 1408 *:pw* *:pwd* *E187* 1409 :pw[d] Print the current directory name. 1410 Also see |getcwd()|. 1411 *:pwd-verbose* 1412 When 'verbose' is non-zero, |:pwd| will also display 1413 what scope the current directory was set. Example: > 1414 1415 " Set by :cd 1416 :verbose pwd 1417 [global] /path/to/current 1418 1419 " Set by :lcd 1420 :verbose pwd 1421 [window] /path/to/current 1422 1423 " Set by :tcd 1424 :verbose pwd 1425 [tabpage] /path/to/current 1426 1427 So long as no |:lcd| or |:tcd| command has been used, all windows share the 1428 same current directory. Using a command to jump to another window doesn't 1429 change anything for the current directory. 1430 1431 When |:lcd| has been used for a window, the specified directory becomes the 1432 current directory for that window. Windows where the |:lcd| command has not 1433 been used stick to the global or tab-local directory. When jumping to another 1434 window the current directory is changed to the last specified local current 1435 directory. If none was specified, the global or tab-local directory is used. 1436 When creating a new window it inherits the local directory of the current window. 1437 1438 When changing tabs the same behaviour applies. If the current tab has no 1439 local working directory the global working directory is used. 1440 1441 When a |:cd| command is used, the current window and tab will lose their local 1442 current directories and will use the global current directory from now on. 1443 When a |:tcd| command is used, only the current window will lose its local 1444 working directory. 1445 1446 After using |:cd| the full path name will be used for reading and writing 1447 files. On some networked file systems this may cause problems. The result of 1448 using the full path name is that the file names currently in use will remain 1449 referring to the same file. Example: If you have a file a:test and a 1450 directory a:vim the commands ":e test" ":cd vim" ":w" will overwrite the file 1451 a:test and not write a:vim/test. But if you do ":w test" the file a:vim/test 1452 will be written, because you gave a new file name and did not refer to a 1453 filename before the ":cd". 1454 1455 ============================================================================== 1456 8. Editing binary files *edit-binary* 1457 1458 Although Vim was made to edit text files, it is possible to edit binary 1459 files. The |-b| Vim argument (b for binary) makes Vim do file I/O in binary 1460 mode, and sets some options for editing binary files ('binary' on, 'textwidth' 1461 to 0, 'modeline' off, 'expandtab' off). Setting the 'binary' option has the 1462 same effect. Don't forget to do this before reading the file. 1463 1464 There are a few things to remember when editing binary files: 1465 - When editing executable files the number of bytes must not change. 1466 Use only the "R" or "r" command to change text. Do not delete characters 1467 with "x" or by backspacing. 1468 - Set the 'textwidth' option to 0. Otherwise lines will unexpectedly be 1469 split in two. 1470 - When there are not many <EOL>s, the lines will become very long. If you 1471 want to edit a line that does not fit on the screen reset the 'wrap' option. 1472 Horizontal scrolling is used then. If a line becomes too long (see |limits|) 1473 you cannot edit that line. The line will be split when reading the file. 1474 It is also possible that you get an "out of memory" error when reading the 1475 file. 1476 - Make sure the 'binary' option is set BEFORE loading the 1477 file. Otherwise both <CR><NL> and <NL> are considered to end a line 1478 and when the file is written the <NL> will be replaced with <CR><NL>. 1479 - <Nul> characters are shown on the screen as ^@. You can enter them with 1480 "CTRL-V CTRL-@" or "CTRL-V 000". 1481 - To insert a <NL> character in the file split a line. When writing the 1482 buffer to a file a <NL> will be written for the <EOL>. 1483 - Vim normally appends an <EOL> at the end of the file if there is none. 1484 Setting the 'binary' option prevents this. If you want to add the final 1485 <EOL>, set the 'endofline' option. You can also read the value of this 1486 option to see if there was an <EOL> for the last line (you cannot see this 1487 in the text). 1488 1489 ============================================================================== 1490 9. Encryption *encryption* 1491 1492 *:X* *E817* *E818* *E819* *E820* 1493 Support for editing encrypted files has been removed. 1494 https://github.com/neovim/neovim/issues/694 1495 https://github.com/neovim/neovim/issues/701 1496 1497 ============================================================================== 1498 10. Timestamps *timestamp* *timestamps* 1499 1500 Vim remembers the modification timestamp, mode and size of a file when you 1501 begin editing it. This is used to avoid that you have two different versions 1502 of the same file (without you knowing this). 1503 1504 After a shell command is run (|:!cmd| |suspend| |:read!| |K|) timestamps, 1505 file modes and file sizes are compared for all buffers in a window. Vim will 1506 run any associated |FileChangedShell| autocommands or display a warning for 1507 any files that have changed. In the GUI this happens when Vim regains input 1508 focus. 1509 1510 *E321* *E462* 1511 If you want to automatically reload a file when it has been changed outside of 1512 Vim, set the 'autoread' option. This doesn't work at the moment you write the 1513 file though, only when the file wasn't changed inside of Vim. 1514 *ignore-timestamp* 1515 If you do not want to be asked or automatically reload the file, you can use 1516 this: > 1517 set buftype=nofile 1518 1519 Or, when starting gvim from a shell: > 1520 gvim file.log -c "set buftype=nofile" 1521 1522 Note that if a FileChangedShell autocommand is defined you will not get a 1523 warning message or prompt. The autocommand is expected to handle this. 1524 1525 There is no warning for a directory. But you do get warned if you started 1526 editing a new file and it was created as a directory later. 1527 1528 When Vim notices the timestamp of a file has changed, and the file is being 1529 edited in a buffer but has not changed, Vim checks if the contents of the file 1530 is equal. This is done by reading the file again (into a hidden buffer, which 1531 is immediately deleted again) and comparing the text. If the text is equal, 1532 you will get no warning. 1533 1534 If you don't get warned often enough you can use the following command. 1535 1536 *:checkt* *:checktime* 1537 :checkt[ime] Check if any buffers were changed outside of Vim. 1538 This checks and warns you if you would end up with two 1539 versions of a file. 1540 If this is called from an autocommand, a ":global" 1541 command or is not typed the actual check is postponed 1542 until a moment the side effects (reloading the file) 1543 would be harmless. 1544 Each loaded buffer is checked for its associated file 1545 being changed. If the file was changed Vim will take 1546 action. If there are no changes in the buffer and 1547 'autoread' is set, the buffer is reloaded. Otherwise, 1548 you are offered the choice of reloading the file. If 1549 the file was deleted you get an error message. 1550 If the file previously didn't exist you get a warning 1551 if it exists now. 1552 Once a file has been checked the timestamp is reset, 1553 you will not be warned again. 1554 Syntax highlighting, marks, diff status, 1555 'fileencoding', 'fileformat' and 'binary' options 1556 are not changed. See |v:fcs_choice| to reload these 1557 too (for example, if a code formatting tools has 1558 changed the file). 1559 1560 :[N]checkt[ime] {filename} 1561 :[N]checkt[ime] [N] 1562 Check the timestamp of a specific buffer. The buffer 1563 may be specified by name, number or with a pattern. 1564 1565 1566 *E813* *E814* 1567 Vim will reload the buffer if you chose to. If a window is visible that 1568 contains this buffer, the reloading will happen in the context of this window. 1569 Otherwise a special window is used, so that most autocommands will work. You 1570 can't close this window. A few other restrictions apply. Best is to make 1571 sure nothing happens outside of the current buffer. E.g., setting 1572 window-local options may end up in the wrong window. Splitting the window, 1573 doing something there and closing it should be OK (if there are no side 1574 effects from other autocommands). Closing unrelated windows and buffers will 1575 get you into trouble. 1576 1577 Before writing a file, the timestamp is checked (unless "!" was used). 1578 If it has changed, Vim will ask if you really want to overwrite the file: 1579 1580 WARNING: The file has been changed since reading it!!! 1581 Do you really want to write to it (y/n)? 1582 1583 If you hit 'y' Vim will continue writing the file. If you hit 'n' the write 1584 is aborted. If you used ":wq" or "ZZ" Vim will not exit, you will get another 1585 chance to write the file. 1586 1587 The message would normally mean that somebody has written to the file after 1588 the edit session started. This could be another person, in which case you 1589 probably want to check if your changes to the file and the changes from the 1590 other person should be merged. Write the file under another name and check 1591 for differences (the "diff" program can be used for this). 1592 1593 It is also possible that you modified the file yourself, from another edit 1594 session or with another command (e.g., a filter command). Then you will know 1595 which version of the file you want to keep. 1596 1597 The accuracy of the time check depends on the filesystem. On Unix it is 1598 usually sub-second. With old file systems and on MS-Windows it is normally 1599 one second. Use `has('nanotime')` to check if sub-second time stamp checks 1600 are available. 1601 1602 There is one situation where you get the message while there is nothing wrong: 1603 On a Win32 system on the day daylight saving time starts. There is something 1604 in the Win32 libraries that confuses Vim about the hour time difference. The 1605 problem goes away the next day. 1606 1607 ============================================================================== 1608 11. File Searching *file-searching* 1609 1610 The file searching is currently used for the 'path', 'cdpath' and 'tags' 1611 options, for |finddir()| and |findfile()|. Other commands use |wildcards| 1612 which is slightly different. 1613 1614 There are three different types of searching: 1615 1616 1) Downward search: *starstar* 1617 Downward search uses the wildcards "*", "**" and possibly others 1618 supported by your operating system. "*" and "**" are handled inside Vim, 1619 so they work on all operating systems. Note that "**" only acts as a 1620 special wildcard when it is at the start of a name. 1621 1622 The usage of "*" is quite simple: It matches 0 or more characters. In a 1623 search pattern this would be `.*`. Note that the "." is not used for file 1624 searching. 1625 1626 "**" is more sophisticated: 1627 - It ONLY matches directories. 1628 - It matches up to 30 directories deep by default, so you can use it to 1629 search an entire directory tree 1630 - The maximum number of levels matched can be given by appending a 1631 number to "**". 1632 Thus '/usr/**2' can match: > 1633 /usr 1634 /usr/include 1635 /usr/include/sys 1636 /usr/include/g++ 1637 /usr/lib 1638 /usr/lib/X11 1639 .... 1640 < It does NOT match '/usr/include/g++/std' as this would be three 1641 levels. 1642 The allowed number range is 0 ("**0" is removed) to 100 1643 If the given number is smaller than 0 it defaults to 30, if it's 1644 bigger than 100 then 100 is used. The system also has a limit on the 1645 path length, usually 256 or 1024 bytes. 1646 - "**" can only be at the end of the path or be followed by a path 1647 separator or by a number and a path separator. 1648 1649 You can combine "*" and "**" in any order: > 1650 /usr/**/sys/* 1651 /usr/*tory/sys/** 1652 /usr/**2/sys/* 1653 1654 2) Upward search: 1655 Here you can give a directory and then search the directory tree upward for 1656 a file. You could give stop-directories to limit the upward search. The 1657 stop-directories are appended to the path (for the 'path' option) or to 1658 the filename (for the 'tags' option) with a ';'. If you want several 1659 stop-directories separate them with ';'. If you want no stop-directory 1660 ("search upward till the root directory") just use ';'. > 1661 /usr/include/sys;/usr 1662 < will search in: > 1663 /usr/include/sys 1664 /usr/include 1665 /usr 1666 < 1667 If you use a relative path the upward search is started in Vim's current 1668 directory or in the directory of the current file (if the relative path 1669 starts with './' and 'd' is not included in 'cpoptions'). 1670 1671 If Vim's current path is /u/user_x/work/release and you do > 1672 :set path=include;/u/user_x 1673 < and then search for a file with |gf| the file is searched in: > 1674 /u/user_x/work/release/include 1675 /u/user_x/work/include 1676 /u/user_x/include 1677 1678 < Note: If your 'path' setting includes a non-existing directory, Vim will 1679 skip the non-existing directory, and also does not search in the parent of 1680 the non-existing directory if upwards searching is used. 1681 1682 3) Combined up/downward search: 1683 If Vim's current path is /u/user_x/work/release and you do > 1684 set path=**;/u/user_x 1685 < and then search for a file with |gf| the file is searched in: > 1686 /u/user_x/work/release/** 1687 /u/user_x/work/** 1688 /u/user_x/** 1689 < 1690 BE CAREFUL! This might consume a lot of time, as the search of 1691 '/u/user_x/**' includes '/u/user_x/work/**' and 1692 '/u/user_x/work/release/**'. So '/u/user_x/work/release/**' is searched 1693 three times and '/u/user_x/work/**' is searched twice. 1694 1695 In the above example you might want to set path to: > 1696 :set path=**,/u/user_x/** 1697 < This searches: > 1698 /u/user_x/work/release/** 1699 /u/user_x/** 1700 < This searches the same directories, but in a different order. 1701 1702 Note that completion for ":find", ":sfind", and ":tabfind" commands do not 1703 currently work with 'path' items that contain a URL or use the double star 1704 with depth limiter (/usr/**2) or upward search (;) notations. 1705 1706 ============================================================================== 1707 12. Trusted Files *trust* 1708 1709 Nvim executes arbitrary code found on the filesystem if 'exrc' is enabled. To 1710 prevent executing malicious code, only "trusted files" are executed. You can 1711 mark a file as trusted or untrusted using the |:trust| command or the 1712 |vim.secure.read()| function. 1713 1714 *:trust* *E5570* 1715 :trust [++deny] [++remove] [file] 1716 1717 Manage trusted files. Without ++ options, :trust marks 1718 [file] (or current buffer if no [file]) as trusted, 1719 keyed on a hash of its contents. The trust list is 1720 stored on disk, Nvim will re-use it after restarting. 1721 1722 [++deny] marks [file] (or current buffer if no [file]) 1723 as untrusted: it will never be executed, 'exrc' will 1724 ignore it. 1725 1726 [++remove] removes [file] (or current buffer if no 1727 [file]) from the trust list. When the file is 1728 discovered by 'exrc' or |vim.secure.read()|, the user 1729 will be asked whether to trust or deny the file. 1730 1731 vim:tw=78:ts=8:noet:ft=help:norl: