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