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