Lines Matching refs:file
10 2. Editing a file |edit-a-file|
19 11. File Searching |file-searching|
24 Editing a file with Vim means:
26 1. reading the file into a buffer
28 3. writing the buffer into a file
30 *current-file*
31 As long as you don't write the buffer, the original file remains unchanged.
32 If you start editing a file (read a file into the buffer), the file name is
33 remembered as the "current file name". This is also known as the name of the
36 *alternate-file*
37 If there already was a current file name, then that one becomes the alternate
38 file name. It can be used with "#" on the command line |:_#| and you can use
39 the |CTRL-^| command to toggle between the current and the alternate file.
40 However, the alternate file name is not changed when |:keepalt| is used.
41 An alternate file name is remembered for each window.
44 :keepalt {cmd} Execute {cmd} while keeping the current alternate file
46 with a function) may still set the alternate file
49 All file names are remembered in the buffer list. When you enter a file name,
51 the file name is added to the list. You can use the buffer list to remember
52 which files you edited and to quickly switch from one file to another (e.g.,
53 to copy text) with the |CTRL-^| command. First type the number of the file
57 CTRL-G or *CTRL-G* *:f* *:fi* *:file*
58 :f[ile] Prints the current file name (as typed, unless ":cd"
60 option is set), and the file status (readonly,
61 modified, read errors, new file). See the 'shortmess'
64 :f[ile]! like |:file|, but don't truncate the name even when
67 {count}CTRL-G Like CTRL-G, but prints the current file name with
95 :f[ile][!] {name} Sets the current file name to {name}. The optional !
96 avoids truncating the message, as with |:file|.
98 |alternate-file| name. An unlisted buffer is created
100 *:0file*
102 avoids truncating the message, as with |:file|.
106 :ls List all the currently known file names. See
109 Vim will remember the full path name of a file name that you enter. In most
110 cases when the file name is displayed only the name you typed is shown, but
114 If the environment variable $HOME is set, and the file name starts with that
116 keep file names short. When reading or writing files the full name is still
117 used, the "~" is only used when displaying file names. When replacing the
118 file name would result in just "~", "~/" is used instead (to avoid confusion
121 When writing the buffer, the default is to use the current file name. Thus
122 when you give the "ZZ" or ":wq" command, the original file will be
124 file by giving a file name argument to the ":write" command. For example: >
131 This will create a file "newfile", that is a modified copy of "testfile".
132 The file "testfile" will remain unchanged. Anyway, if the 'backup' option is
133 set, Vim renames or copies the original file before it will be overwritten.
134 You can use this file if you discover that you need the original file. See
135 also the 'patchmode' option. The name of the backup file is normally the same
136 as the original file with 'backupext' appended. The default "~" is a bit
141 backup file can be placed in another directory by setting 'backupdir'.
144 Technical: On the Amiga you can use 30 characters for a file name. But on an
147 creating the .swp file. If an MS-DOS-like filesystem is suspected,
150 new file. The flag will be used when making the file name for the
151 ".swp" and ".~" files for the current file. But when you are
152 editing a file in a normal filesystem and write to an MS-DOS-like
154 creation of the ".~" file may fail and you will get an error
157 When you started editing without giving a file name, "No File" is displayed in
158 messages. If the ":write" command is used with a file name argument, the file
159 name for the current file is set to that file name. This only happens when
162 file. If 'cpoptions' contains the 'f' flag (by default it is NOT included)
163 |cpo-f| the file name is set for the ":read file" command. This is useful
164 when starting Vim without an argument and then doing ":read file" to start
165 editing a file.
166 When the file name was set and 'filetype' is empty the filetype detection
169 Because the file name was set without really starting to edit that file, you
170 are protected from overwriting that file. This is done by setting the
171 "notedited" flag. You can see if this flag is set with the CTRL-G or ":file"
173 When writing the buffer to the current file name (with ":w!"), the "notedited"
179 start editing another file, Vim will refuse this. In order to overrule this
195 2. Editing a file *edit-a-file*
198 :e[dit] [++opt] [+cmd] Edit the current file. This is useful to re-edit the
199 current file, when it has been changed outside of Vim.
201 buffer and 'autowriteall' isn't set or the file can't
207 Edit the current file always. Discard any changes to
213 :e[dit] [++opt] [+cmd] {file}
214 Edit {file}.
217 set and the file can be written.
221 :e[dit]! [++opt] [+cmd] {file}
222 Edit {file} always. Discard any changes to the
230 file name, while CTRL-^ still works then.
236 is set or 'autowriteall' is set and the file can be
248 :fin[d][!] [++opt] [+cmd] {file}
249 Find {file} in 'path' and then |:edit| it.
253 :{count}fin[d][!] [++opt] [+cmd] {file}
255 'path'. Thus ":2find file" will find the second
256 "file" found in 'path'. When there are fewer matches
257 for the file in 'path' than asked for, you get an
261 :ex [++opt] [+cmd] [file]
265 :vi[sual][!] [++opt] [+cmd] [file]
270 :vie[w][!] [++opt] [+cmd] file
276 CTRL-^ Edit the alternate file. Mostly the alternate file is
277 the previously edited file. This is a quick way to
279 except that it also works when there is no file name.
288 {count}CTRL-^ Edit [count]th file in the buffer list (equivalent to
297 [count]gf Edit the file whose name is under or after the cursor.
298 Mnemonic: "goto file".
300 are supposed to be in a file name. Trailing
304 look for the file. See the 'path' option for details
306 Uses the 'suffixesadd' option to check for file names
308 If the file can't be found, 'includeexpr' is used to
310 If a [count] is given, the count'th file that is found
313 current file.
314 If you want to edit the file in a new window use
316 If you do want to edit a new file, use: >
323 "~user/file". Environment variables are expanded too
330 name of the file to edit. 'isfname' is ignored.
332 special characters are included in the file name.
336 [count]gF Same as "gf", except if a number follows the file
338 the file.
339 The file name and the number must be separated by a
354 These commands are used to start editing a single file. This means that the
355 file is read into the buffer and the current file name is set. The file that
359 file has been read.
363 current file name.
365 *:filename* *{file}*
370 file name (like ":edit file") spaces in the file name are allowed, but
372 spaces in file names (like MS-Windows and the Amiga). Example: The command
373 ":e Long File Name " will edit the file "Long File Name". When using a
374 command that accepts more than one file name (like ":next file1 file2")
378 Wildcards in {file} are expanded, but as with file completion, 'wildignore'
389 is to use "path\[[]abc]", this matches the file "path\[abc]".
395 |file-searching|.
415 On Unix and a few other systems you can also use backticks for the file name
472 a file
477 This edits the same file again with 'fileformat' set to "unix". >
482 The message given when writing a file will show "[converted]" when
509 file, or execute any other command:
513 +{command} Execute {command} after opening the new file.
517 :edit +/The\ book file
518 :edit +/dir\ dirname\\ file
519 :edit +set\ dir=c:\\\\temp file
523 *file-formats*
524 The 'fileformat' option sets the <EOL> style for a file:
531 When reading a file, the mentioned characters are interpreted as the <EOL>.
533 the <EOL>. Note that when writing the file in DOS format, <CR> characters
534 will be added for each single <NL>. Also see |file-read|.
536 When writing a file, the mentioned characters are used for <EOL>. For DOS
539 You can read a file in DOS format and write it in Unix format. This will
541 :e file
544 If you read a file in Unix format and write with DOS format, all <NL>
547 :e file
551 If you start editing a new file and the 'fileformats' option is not empty
552 (which is the default), Vim will try to detect whether the lines in the file
557 "mac", and no <NL> characters are found in the file, 'fileformat' is set to
567 a file some lines did not end in <CR><NL>, "[CR missing]" will be included in
568 the file message.
570 a file a <NL> was found, "[NL missing]" will be included in the file message.
572 If the new file does not exist, the 'fileformat' of the current buffer is used
574 used for the new file.
588 If you give more than one file name when starting Vim, this list is remembered
589 as the argument list. You can jump to each file in this list.
593 list is new in Vim. Every file name in the argument list will also be present
608 :ar[gs] Print the argument list, with the current file in
630 If the current file cannot be |abandon|ed {name}s will
642 Otherwise they are added after the [count]'th file.
653 add a file to the argument list twice.
654 The currently edited file is not changed.
661 {pattern}s. {pattern} is used like a file pattern,
662 see |file-pattern|. "%" can be used to delete the
664 This command keeps the currently edited file, also
685 Edit file [count] in the argument list. When [count]
692 Edit file [count] in the argument list, discard any
698 Edit [count] next file. This fails when changes have
703 Edit [count] next file, discard any changes to the
713 Edit [count] previous file in argument list. This
719 Edit [count] previous file in argument list. Discard
728 Start editing the first file in the argument list.
734 Start editing the first file in the argument list.
744 Start editing the last file in the argument list.
750 Start editing the last file in the argument list.
756 Write current file and start editing the [count]
757 next file. Also see |++opt| and |+cmd|.
759 :[count]wn[ext] [++opt] {file}
760 Write current file to {file} and start editing the
761 [count] next file, unless {file} already exists and
765 :[count]wn[ext]! [++opt] {file}
766 Write current file to {file} and start editing the
767 [count] next file. Also see |++opt| and |+cmd|.
769 :[count]wN[ext][!] [++opt] [file] *:wN* *:wNext*
770 :[count]wp[revious][!] [++opt] [file] *:wp* *:wprevious*
771 Same as :wnext, but go to previous file instead of
778 cursor position for the file. If 'startofline' is set, the cursor will be
784 The wildcards in the argument list are expanded and the file names are sorted.
788 White space is used to separate file names. Put a backslash before a space or
789 tab to include it in a file name. E.g., to edit the single file "foo bar": >
798 When there is an argument list you can see which file you are editing in the
799 title of the window (if there is one and 'title' is on) and with the file
801 (file 4 of 11)
804 If you are not really editing the file at the current position in the argument
806 (file (4) of 11)
808 fourth file in the argument list. This happens when you do ":e file".
815 Doesn't start editing another file.
823 Doesn't start editing another file.
843 :[range]argdo[!] {cmd} Execute {cmd} for each file in the argument list or
851 < When the current file can't be |abandon|ed and the [!]
853 When an error is detected on one file, further files
855 The last file in the argument list (or where an error
856 occurred) becomes the current file.
862 each file.
869 This sets the 'fileformat' option to "unix" and writes the file if it is now
877 "my_foo" isn't used. ":update" writes the file only if changes were made.
880 4. Writing *writing* *save-file*
882 Note: When the 'write' option is off, you are not able to write any file.
887 :w[rite] [++opt] Write the whole buffer to the current file. This is
888 the normal way to save changes to a file. It fails
890 another reason why the file can't be written.
898 the file and break (symbolic) links. Add the 'W' flag
902 Write the specified lines to the current file. This
903 is unusual, because the file will not contain all
907 :[range]w[rite] [++opt] {file}
908 Write the specified lines to {file}, unless it
912 :[range]w[rite]! [++opt] {file}
913 Write the specified lines to {file}. Overwrite an
914 existing file.
918 Append the specified lines to the current file.
920 :[range]w[rite][!] [++opt] >> {file}
921 Append the specified lines to {file}. '!' forces the
922 write even if file does not exist.
933 write it to a different file with ":w somefile" it depends on the "+" flag in
935 even though the buffer itself may still be different from its file.
937 If a file name is given with ":w" it becomes the alternate file. This can be
946 :sav[eas][!] [++opt] {file}
947 Save the current buffer under the name {file} and set
948 the filename of the current buffer to {file}. The
949 previous name is used for the alternate file name.
950 The [!] is needed to overwrite an existing file.
952 with the new name, before the file is written.
956 :[range]up[date][!] [++opt] [>>] [file]
964 :wa[ll] Write all changed buffers. Buffers without a file
969 readonly. Buffers without a file name are not
973 Vim will warn you if you try to overwrite a file that has been changed
977 If you write to an existing file (but do not append) while the 'backup',
978 'writebackup' or 'patchmode' option is on, a backup of the original file is
979 made. The file is either copied or renamed (see 'backupcopy'). After the
980 file has been successfully written and when the 'writebackup' option is on and
981 the 'backup' option is off, the backup file is deleted. When the 'patchmode'
982 option is on the backup file may be renamed.
987 off on backup current file, deleted afterwards (default)
988 on off delete old backup, backup current file
989 on on delete old backup, backup current file
991 When the 'backupskip' pattern matches with the name of the file which is
992 written, no backup file is made. The values of 'backup' and 'writebackup' are
995 When the 'backup' option is on, an old backup file (with the same name as the
996 new backup file) will be deleted. If 'backup' is not set, but 'writebackup'
997 is set, an existing backup file will not be deleted. The backup file that is
998 made while the file is being written will have a different name.
1001 the newly written file (it might be there but contain bogus data). In that
1002 case try recovery, because the swap file is synced to disk and might still be
1006 file in. (default: same directory as the written file).
1008 Whether the backup is a new file, which is a copy of the original file, or the
1009 original file renamed depends on the 'backupcopy' option. See there for an
1010 explanation of when the copy is made and when the file is renamed.
1012 If the creation of a backup file fails, the write is not done. If you want
1016 When writing a new file the permissions are read-write. For unix the mask is
1017 0o666 with additionally umask applied. When writing a file that was read Vim
1022 readonly file. When 'W' is not present, ":w!" will overwrite a readonly file,
1026 If the writing of the new file fails, you have to be careful not to lose
1027 your changes AND the original file. If there is no backup file and writing
1028 the new file failed, you have already lost the original file! DON'T EXIT VIM
1030 of the original file (if possible). If you exit Vim, and lose the changes
1031 you made, the original file will mostly still be there. If putting back the
1032 original file fails, there will be an error message telling you that you
1033 lost the original file.
1046 See also |file-formats| and the 'fileformat' and 'fileformats' options.
1050 rights for a file. It is used on new MS-Windows and Unix systems, but only
1052 Vim attempts to preserve the ACL info when writing a file. The backup file
1053 will get the ACL info of the original file.
1054 The ACL info is also used to check if a file is read-only (when opening the
1055 file).
1059 This means that even if the file read-only attribute is absent, and the ACL
1060 settings on NT network shared drives allow writing to the file, you can still
1061 not write to the file. Vim on Win32 platforms will detect read-only network
1062 drives and will mark the file as read-only. You will not be able to override
1066 When the file name is actually a device name, Vim will not make a backup (that
1072 For Unix a device is detected when the name doesn't refer to a normal file or
1091 when the last file in the argument list has not been
1100 the last file in the argument list has not been
1117 :wq [++opt] Write the current file and close the window. If this
1119 Writing fails when the file is read-only or the buffer
1121 file in the argument list has not been edited.
1123 :wq! [++opt] Write the current file and close the window. If this
1127 :wq [++opt] {file} Write to {file} and close the window. If this was the
1129 last file in the argument list has not been edited.
1131 :wq! [++opt] {file} Write to {file} and close the current window. Quit
1134 :[range]wq[!] [++opt] [file]
1138 :[range]x[it][!] [++opt] [file]
1142 current buffer becomes hidden, after writing the file.
1145 :[range]exi[t][!] [++opt] [file]
1149 ZZ Write current file, if modified, and close the current
1151 If there are several windows for the current file,
1179 without a file name, which are readonly or which cannot be
1190 and exit Vim. If there are buffers without a file name or
1218 :bro[wse] {command} Open a file selection dialog for an argument to
1241 file chosen. >
1244 and edit the file chosen. >
1277 the type of file you are currently editing. Disadvantage: This makes it
1278 difficult to start editing a file of a different type. To overcome this, you
1280 still access any desired file.
1294 file names. It also makes a difference for executing external commands, e.g.
1311 Does not change the meaning of an already opened file,
1315 To change to the directory of the current file: >
1393 files. On some networked file systems this may cause problems. The result of
1394 using the full path name is that the file names currently in use will remain
1395 referring to the same file. Example: If you have a file a:test and a
1396 directory a:vim the commands ":e test" ":cd vim" ":w" will overwrite the file
1397 a:test and not write a:vim/test. But if you do ":w test" the file a:vim/test
1398 will be written, because you gave a new file name and did not refer to a
1405 files. The |-b| Vim argument (b for binary) makes Vim do file I/O in binary
1408 same effect. Don't forget to do this before reading the file.
1421 the file. It is also possible that you get an "out of memory" error when
1422 reading the file.
1424 file. Otherwise both <CR><NL> and <NL> are considered to end a line
1425 and when the file is written the <NL> will be replaced with <CR><NL>.
1428 - To insert a <NL> character in the file split a line. When writing the
1429 buffer to a file a <NL> will be written for the <EOL>.
1430 - Vim normally appends an <EOL> at the end of the file if there is none.
1443 The text in the swap file and the undo file is also encrypted. *E843*
1445 password. You can disable the swap file, but then a crash will cause you to
1446 lose your work. The undo file can be disabled without too much disadvantage. >
1453 reveal it to others. The 'viminfo' file is not encrypted.
1458 Keep in mind that without a swap file you risk losing your work in the event
1461 WARNING: If you make a typo when entering the key and then write the file and
1466 encrypt the file. If you later edit the same file, Vim will ask you to enter
1474 the file when it is written.
1475 The file will remain unchanged until you write it. Note that commands
1476 such as `:xit` and `ZZ` will NOT write the file unless there are other
1481 is not empty, the written file will be encrypted, using the value as the
1483 the file is encrypted.
1494 Do this before writing the file. When reading an encrypted file it will be
1495 set automatically to the method used when that file was written. You can
1496 change 'cryptmethod' before writing that file to change the method.
1499 file: >
1504 The message given for reading and writing a file will show "[crypted]" when
1507 When writing an undo file, the same key and method will be used for the text
1508 in the undo file. |persistent-undo|.
1524 to a file and never be able to read it back. Therefore a test is performed to
1526 don't write the file encrypted! You need to rebuild the Vim binary to fix
1532 When reading a file that has been encrypted and the 'key' option is not empty,
1535 file is edited without being decrypted. There is no warning about using the
1538 If want to start reading a file that uses a different key, set the 'key'
1544 never be viewed. You should not set this option in a vimrc file.
1546 An encrypted file can be recognized by the "file" command, if you add these
1548 "magic" file: >
1549 0 string VimCrypt~ Vim encrypted file
1557 be saved in the .viminfo file, where they could be read. Change your
1564 history, showing the 'key' value in a viminfo file.
1569 requires that you know some text that must appear in the file. An expert
1574 objection to its export. Pkzip's public file APPNOTE.TXT describes this
1577 to crack the first 64 bytes of a file and in some circumstances more of the
1578 file. Use of it is not recommended, but it's still the strongest method
1586 Vim remembers the modification timestamp, mode and size of a file when you
1588 of the same file (without you knowing this).
1591 file modes and file sizes are compared for all buffers in a window. Vim will
1597 If you want to automatically reload a file when it has been changed outside of
1599 file though, only when the file wasn't changed inside of Vim.
1601 If you do not want to be asked or automatically reload the file, you can use
1606 gvim file.log -c "set buftype=nofile"
1612 get warned if you started editing a new file and it was created as a directory
1615 When Vim notices the timestamp of a file has changed, and the file is being
1616 edited in a buffer but has not changed, Vim checks if the contents of the file
1617 is equal. This is done by reading the file again (into a hidden buffer, which
1626 versions of a file.
1629 until a moment the side effects (reloading the file)
1631 Each loaded buffer is checked for its associated file
1632 being changed. If the file was changed Vim will take
1635 you are offered the choice of reloading the file. If
1636 the file was deleted you get an error message.
1637 If the file previously didn't exist you get a warning
1639 Once a file has been checked the timestamp is reset,
1659 Before writing a file the timestamp is checked. If it has changed, Vim will
1660 ask if you really want to overwrite the file:
1662 WARNING: The file has been changed since reading it!!!
1665 If you hit 'y' Vim will continue writing the file. If you hit 'n' the write is
1667 chance to write the file.
1669 The message would normally mean that somebody has written to the file after
1671 probably want to check if your changes to the file and the changes from the
1672 other person should be merged. Write the file under another name and check for
1675 It is also possible that you modified the file yourself, from another edit
1677 which version of the file you want to keep.
1680 usually sub-second. With old file sytems and on MS-Windows it is normally one
1690 11. File Searching *file-searching*
1694 The file searching is currently used for the 'path', 'cdpath' and 'tags'
1707 search pattern this would be ".*". Note that the "." is not used for file
1740 a file. You could give stop-directories to limit the upward search. The
1752 directory or in the directory of the current file (if the relative path
1757 < and then search for a file with |gf| the file is searched in: >
1771 < and then search for a file with |gf| the file is searched in: >