代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>editing - Vim Documentation</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim8.0">
<meta name="syntax" content="help">
<meta name="settings" content="no_pre,use_css,expand_tabs">
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="mark-current-page.js" type="text/javascript"></script>
</head>
<body>
<header>
<div class="header">
<a href="http://vim-jp.org/">vim-jp</a>
/ <a href="http://vim-jp.org/vimdoc-en/">vimdoc-en</a>
/ editing<br />
<a name="top"></a><h1>editing - Vim Documentation</h1>
<a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
</div>
</header>
<nav>
<dl>
<dt>BASIC</dt>
<dd><ul>
<li><a href="quickref.html">quickref</a></li>
<li><a href="sponsor.html">sponsor</a></li>
</ul></dd>
<dt>USER MANUAL</dt>
<dd><ul>
<li><a href="usr_toc.html">usr_toc</a></li>
</ul></dd>
<dt>Getting Started</dt>
<dd><ul>
<li><a href="usr_01.html">usr_01</a></li>
<li><a href="usr_02.html">usr_02</a></li>
<li><a href="usr_03.html">usr_03</a></li>
<li><a href="usr_04.html">usr_04</a></li>
<li><a href="usr_05.html">usr_05</a></li>
<li><a href="usr_06.html">usr_06</a></li>
<li><a href="usr_07.html">usr_07</a></li>
<li><a href="usr_08.html">usr_08</a></li>
<li><a href="usr_09.html">usr_09</a></li>
<li><a href="usr_10.html">usr_10</a></li>
<li><a href="usr_11.html">usr_11</a></li>
<li><a href="usr_12.html">usr_12</a></li>
</ul></dd>
<dt>Editing Effectively</dt>
<dd><ul>
<li><a href="usr_20.html">usr_20</a></li>
<li><a href="usr_21.html">usr_21</a></li>
<li><a href="usr_22.html">usr_22</a></li>
<li><a href="usr_23.html">usr_23</a></li>
<li><a href="usr_24.html">usr_24</a></li>
<li><a href="usr_25.html">usr_25</a></li>
<li><a href="usr_26.html">usr_26</a></li>
<li><a href="usr_27.html">usr_27</a></li>
<li><a href="usr_28.html">usr_28</a></li>
<li><a href="usr_29.html">usr_29</a></li>
<li><a href="usr_30.html">usr_30</a></li>
<li><a href="usr_31.html">usr_31</a></li>
<li><a href="usr_32.html">usr_32</a></li>
</ul></dd>
<dt>Tuning Vim</dt>
<dd><ul>
<li><a href="usr_40.html">usr_40</a></li>
<li><a href="usr_41.html">usr_41</a></li>
<li><a href="usr_42.html">usr_42</a></li>
<li><a href="usr_43.html">usr_43</a></li>
<li><a href="usr_44.html">usr_44</a></li>
<li><a href="usr_45.html">usr_45</a></li>
</ul></dd>
<dt>Making Vim Run</dt>
<dd><ul>
<li><a href="usr_90.html">usr_90</a></li>
</ul></dd>
<dt>General subjects</dt>
<dd><ul>
<li><a href="intro.html">intro</a></li>
<li><a href="index.html">help</a></li>
<li><a href="helphelp.html">helphelp</a></li>
<li><a href="vimindex.html">index</a></li>
<li><a href="tags.html">tags</a></li>
<li><a href="howto.html">howto</a></li>
<li><a href="tips.html">tips</a></li>
<li><a href="message.html">message</a></li>
<li><a href="quotes.html">quotes</a></li>
<li><a href="todo.html">todo</a></li>
<li><a href="debug.html">debug</a></li>
<li><a href="develop.html">develop</a></li>
<li><a href="uganda.html">uganda</a></li>
</ul></dd>
<dt>Basic editing</dt>
<dd><ul>
<li><a href="starting.html">starting</a></li>
<li><a href="editing.html">editing</a></li>
<li><a href="motion.html">motion</a></li>
<li><a href="scroll.html">scroll</a></li>
<li><a href="insert.html">insert</a></li>
<li><a href="change.html">change</a></li>
<li><a href="indent.html">indent</a></li>
<li><a href="undo.html">undo</a></li>
<li><a href="repeat.html">repeat</a></li>
<li><a href="visual.html">visual</a></li>
<li><a href="various.html">various</a></li>
<li><a href="recover.html">recover</a></li>
</ul></dd>
<dt>Advanced editing</dt>
<dd><ul>
<li><a href="cmdline.html">cmdline</a></li>
<li><a href="options.html">options</a></li>
<li><a href="pattern.html">pattern</a></li>
<li><a href="map.html">map</a></li>
<li><a href="tagsrch.html">tagsrch</a></li>
<li><a href="quickfix.html">quickfix</a></li>
<li><a href="windows.html">windows</a></li>
<li><a href="tabpage.html">tabpage</a></li>
<li><a href="syntax.html">syntax</a></li>
<li><a href="spell.html">spell</a></li>
<li><a href="diff.html">diff</a></li>
<li><a href="autocmd.html">autocmd</a></li>
<li><a href="filetype.html">filetype</a></li>
<li><a href="eval.html">eval</a></li>
<li><a href="channel.html">channel</a></li>
<li><a href="fold.html">fold</a></li>
</ul></dd>
<dt>Special issues</dt>
<dd><ul>
<li><a href="print.html">print</a></li>
<li><a href="remote.html">remote</a></li>
<li><a href="term.html">term</a></li>
<li><a href="digraph.html">digraph</a></li>
<li><a href="mbyte.html">mbyte</a></li>
<li><a href="mlang.html">mlang</a></li>
<li><a href="arabic.html">arabic</a></li>
<li><a href="farsi.html">farsi</a></li>
<li><a href="hebrew.html">hebrew</a></li>
<li><a href="russian.html">russian</a></li>
<li><a href="ft_ada.html">ft_ada</a></li>
<li><a href="ft_sql.html">ft_sql</a></li>
<li><a href="hangulin.html">hangulin</a></li>
<li><a href="rileft.html">rileft</a></li>
</ul></dd>
<dt>GUI</dt>
<dd><ul>
<li><a href="gui.html">gui</a></li>
<li><a href="gui_w32.html">gui_w32</a></li>
<li><a href="gui_x11.html">gui_x11</a></li>
</ul></dd>
<dt>Interfaces</dt>
<dd><ul>
<li><a href="if_cscop.html">if_cscop</a></li>
<li><a href="if_lua.html">if_lua</a></li>
<li><a href="if_mzsch.html">if_mzsch</a></li>
<li><a href="if_perl.html">if_perl</a></li>
<li><a href="if_pyth.html">if_pyth</a></li>
<li><a href="if_tcl.html">if_tcl</a></li>
<li><a href="if_ole.html">if_ole</a></li>
<li><a href="if_ruby.html">if_ruby</a></li>
<li><a href="debugger.html">debugger</a></li>
<li><a href="workshop.html">workshop</a></li>
<li><a href="netbeans.html">netbeans</a></li>
<li><a href="sign.html">sign</a></li>
</ul></dd>
<dt>Versions</dt>
<dd><ul>
<li><a href="vi_diff.html">vi_diff</a></li>
<li><a href="version4.html">version4</a></li>
<li><a href="version5.html">version5</a></li>
<li><a href="version6.html">version6</a></li>
<li><a href="version7.html">version7</a></li>
<li><a href="version8.html">version8</a></li>
</ul></dd>
<dt>Remarks about specific systems</dt>
<dd><ul>
<li><a href="os_390.html">os_390</a></li>
<li><a href="os_amiga.html">os_amiga</a></li>
<li><a href="os_beos.html">os_beos</a></li>
<li><a href="os_dos.html">os_dos</a></li>
<li><a href="os_mac.html">os_mac</a></li>
<li><a href="os_mint.html">os_mint</a></li>
<li><a href="os_msdos.html">os_msdos</a></li>
<li><a href="os_os2.html">os_os2</a></li>
<li><a href="os_qnx.html">os_qnx</a></li>
<li><a href="os_risc.html">os_risc</a></li>
<li><a href="os_unix.html">os_unix</a></li>
<li><a href="os_vms.html">os_vms</a></li>
<li><a href="os_win32.html">os_win32</a></li>
</ul></dd>
<dt>Standard plugins</dt>
<dd><ul>
<li><a href="pi_getscript.html">pi_getscript</a></li>
<li><a href="pi_gzip.html">pi_gzip</a></li>
<li><a href="pi_logipat.html">pi_logipat</a></li>
<li><a href="pi_netrw.html">pi_netrw</a></li>
<li><a href="pi_paren.html">pi_paren</a></li>
<li><a href="pi_tar.html">pi_tar</a></li>
<li><a href="pi_vimball.html">pi_vimball</a></li>
<li><a href="pi_zip.html">pi_zip</a></li>
</ul></dd>
<dt>Filetype plugins</dt>
<dd><ul>
<li><a href="pi_spec.html">pi_spec</a></li>
</ul></dd>
<dt>Others</dt>
<dd><ul>
<li><a href="vim_faq.html">vim_faq</a></li>
</ul></dd>
</dl>
</nav>
<article class="Vimdoc VimdocJa">
<div id='vimCodeElement'>
<a class="Constant" href="editing.html" name="editing.txt">editing.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2017 Aug 01<br>
<br>
<br>
<span class="Identifier">VIM REFERENCE MANUAL by Bram Moolenaar</span><br>
<br>
<br>
Editing files <a class="Constant" href="editing.html#edit-files" name="edit-files">edit-files</a><br>
<br>
1. Introduction <a class="Identifier" href="editing.html#edit-intro">edit-intro</a><br>
2. Editing a file <a class="Identifier" href="editing.html#edit-a-file">edit-a-file</a><br>
3. The argument list <a class="Identifier" href="editing.html#argument-list">argument-list</a><br>
4. Writing <a class="Identifier" href="editing.html#writing">writing</a><br>
5. Writing and quitting <a class="Identifier" href="editing.html#write-quit">write-quit</a><br>
6. Dialogs <a class="Identifier" href="editing.html#edit-dialogs">edit-dialogs</a><br>
7. The current directory <a class="Identifier" href="editing.html#current-directory">current-directory</a><br>
8. Editing binary files <a class="Identifier" href="editing.html#edit-binary">edit-binary</a><br>
9. Encryption <a class="Identifier" href="editing.html#encryption">encryption</a><br>
10. Timestamps <a class="Identifier" href="editing.html#timestamps">timestamps</a><br>
11. File Searching <a class="Identifier" href="editing.html#file-searching">file-searching</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Introduction <a class="Constant" href="editing.html#edit-intro" name="edit-intro">edit-intro</a><br>
<br>
Editing a file with Vim means:<br>
<br>
1. reading the file into a buffer<br>
2. changing the buffer with editor commands<br>
3. writing the buffer into a file<br>
<br>
<a class="Constant" href="editing.html#current-file" name="current-file">current-file</a><br>
As long as you don't write the buffer, the original file remains unchanged.<br>
If you start editing a file (read a file into the buffer), the file name is<br>
remembered as the "current file name". This is also known as the name of the<br>
current buffer. It can be used with "%" on the command line <a class="Identifier" href="cmdline.html#:_%">:_%</a>.<br>
<br>
<a class="Constant" href="editing.html#alternate-file" name="alternate-file">alternate-file</a><br>
If there already was a current file name, then that one becomes the alternate<br>
file name. It can be used with "#" on the command line <a class="Identifier" href="cmdline.html#:_#">:_#</a> and you can use<br>
the <a class="Identifier" href="editing.html#CTRL-^">CTRL-^</a> command to toggle between the current and the alternate file.<br>
However, the alternate file name is not changed when <a class="Identifier" href="editing.html#:keepalt">:keepalt</a> is used.<br>
An alternate file name is remembered for each window.<br>
<br>
<a class="Constant" href="editing.html#:keepalt" name=":keepalt">:keepalt</a> <a class="Constant" href="editing.html#:keepa" name=":keepa">:keepa</a><br>
:keepalt <span class="Special">{cmd}</span> Execute <span class="Special">{cmd}</span> while keeping the current alternate file<br>
name. <span class="Todo">Note</span> that commands invoked indirectly (e.g.,<br>
with a function) may still set the alternate file<br>
name. <span class="Special">{not in Vi}</span><br>
<br>
All file names are remembered in the buffer list. When you enter a file name,<br>
for editing (e.g., with ":e filename") or writing (e.g., with ":w filename"),<br>
the file name is added to the list. You can use the buffer list to remember<br>
which files you edited and to quickly switch from one file to another (e.g.,<br>
to copy text) with the <a class="Identifier" href="editing.html#CTRL-^">CTRL-^</a> command. First type the number of the file<br>
and then hit <span class="Special">CTRL-^</span>. <span class="Special">{Vi: only one alternate file name is remembered}</span><br>
<br>
<br>
<span class="Special">CTRL-G</span> or <a class="Constant" href="editing.html#CTRL-G" name="CTRL-G">CTRL-G</a> <a class="Constant" href="editing.html#:f" name=":f">:f</a> <a class="Constant" href="editing.html#:fi" name=":fi">:fi</a> <a class="Constant" href="editing.html#:file" name=":file">:file</a><br>
:f[ile] Prints the current file name (as typed, unless ":cd"<br>
was used), the cursor position (unless the <a class="Type" href="options.html#'ruler'">'ruler'</a><br>
option is set), and the file status (readonly,<br>
modified, read errors, new file). See the <a class="Type" href="options.html#'shortmess'">'shortmess'</a><br>
option about how to make this message shorter.<br>
<span class="Special">{Vi does not include column number}</span><br>
<br>
:f[ile]! like <a class="Identifier" href="editing.html#:file">:file</a>, but don't truncate the name even when<br>
<a class="Type" href="options.html#'shortmess'">'shortmess'</a> indicates this.<br>
<br>
<span class="Special">{count}CTRL-G</span> Like <span class="Special">CTRL-G</span>, but prints the current file name with<br>
full path. If the count is higher than 1 the current<br>
buffer number is also given. <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#g_CTRL-G" name="g_CTRL-G">g_CTRL-G</a> <a class="Constant" href="editing.html#word-count" name="word-count">word-count</a> <a class="Constant" href="editing.html#byte-count" name="byte-count">byte-count</a><br>
g <span class="Special">CTRL-G</span> Prints the current position of the cursor in five<br>
ways: Column, Line, Word, Character and Byte. If the<br>
number of Characters and Bytes is the same then the<br>
Character position is omitted.<br>
If there are characters in the line that take more<br>
than one position on the screen (<span class="Special"><Tab></span> or special<br>
character), both the "real" column and the screen<br>
column are shown, separated with a dash.<br>
Also see the <a class="Type" href="options.html#'ruler'">'ruler'</a> option and the <a class="Identifier" href="eval.html#wordcount()">wordcount()</a><br>
function.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#v_g_CTRL-G" name="v_g_CTRL-G">v_g_CTRL-G</a><br>
<span class="Special">{Visual}</span>g <span class="Special">CTRL-G</span> Similar to "g <span class="Special">CTRL-G</span>", but Word, Character, Line, and<br>
Byte counts for the visually selected region are<br>
displayed.<br>
In Blockwise mode, Column count is also shown. (For<br>
<span class="Special">{Visual}</span> see <a class="Identifier" href="visual.html#Visual-mode">Visual-mode</a>.)<br>
<span class="Special">{not in VI}</span><br>
<br>
<a class="Constant" href="editing.html#:file_f" name=":file_f">:file_f</a><br>
:f[ile][!] <span class="Special">{name}</span> Sets the current file name to <span class="Special">{name}</span>. The optional !<br>
avoids truncating the message, as with <a class="Identifier" href="editing.html#:file">:file</a>.<br>
If the buffer did have a name, that name becomes the<br>
<a class="Identifier" href="editing.html#alternate-file">alternate-file</a> name. An unlisted buffer is created<br>
to hold the old name.<br>
<a class="Constant" href="editing.html#:0file" name=":0file">:0file</a><br>
:0f[ile][!] Remove the name of the current buffer. The optional !<br>
avoids truncating the message, as with <a class="Identifier" href="editing.html#:file">:file</a>. <span class="Special">{not</span><br>
<span class="Special">in Vi}</span><br>
<br>
:buffers<br>
:files<br>
:ls List all the currently known file names. See<br>
'windows.txt' <a class="Identifier" href="windows.html#:files">:files</a> <a class="Identifier" href="windows.html#:buffers">:buffers</a> <a class="Identifier" href="windows.html#:ls">:ls</a>. <span class="Special">{not in</span><br>
<span class="Special">Vi}</span><br>
<br>
Vim will remember the full path name of a file name that you enter. In most<br>
cases when the file name is displayed only the name you typed is shown, but<br>
the full path name is being used if you used the ":cd" command <a class="Identifier" href="editing.html#:cd">:cd</a>.<br>
<br>
<a class="Constant" href="editing.html#home-replace" name="home-replace">home-replace</a><br>
If the environment variable $HOME is set, and the file name starts with that<br>
string, it is often displayed with HOME replaced with "~". This was done to<br>
keep file names short. When reading or writing files the full name is still<br>
used, the "~" is only used when displaying file names. When replacing the<br>
file name would result in just "~", "~/" is used instead (to avoid confusion<br>
between options set to $HOME with <a class="Type" href="options.html#'backupext'">'backupext'</a> set to "~").<br>
<br>
When writing the buffer, the default is to use the current file name. Thus<br>
when you give the "ZZ" or ":wq" command, the original file will be<br>
overwritten. If you do not want this, the buffer can be written into another<br>
file by giving a file name argument to the ":write" command. For example:<br>
<br>
<div class="helpExample"> vim testfile<br>
[change the buffer with editor commands]<br>
:w newfile<br>
:q</div>
<br>
This will create a file "newfile", that is a modified copy of "testfile".<br>
The file "testfile" will remain unchanged. Anyway, if the <a class="Type" href="options.html#'backup'">'backup'</a> option is<br>
set, Vim renames or copies the original file before it will be overwritten.<br>
You can use this file if you discover that you need the original file. See<br>
also the <a class="Type" href="options.html#'patchmode'">'patchmode'</a> option. The name of the backup file is normally the same<br>
as the original file with <a class="Type" href="options.html#'backupext'">'backupext'</a> appended. The default "~" is a bit<br>
strange to avoid accidentally overwriting existing files. If you prefer ".bak"<br>
change the <a class="Type" href="options.html#'backupext'">'backupext'</a> option. Extra dots are replaced with '_' on MS-DOS<br>
machines, when Vim has detected that an MS-DOS-like filesystem is being used<br>
(e.g., messydos or crossdos) or when the <a class="Type" href="options.html#'shortname'">'shortname'</a> option is on. The<br>
backup file can be placed in another directory by setting <a class="Type" href="options.html#'backupdir'">'backupdir'</a>.<br>
<br>
<a class="Constant" href="editing.html#auto-shortname" name="auto-shortname">auto-shortname</a><br>
Technical: On the Amiga you can use 30 characters for a file name. But on an<br>
MS-DOS-compatible filesystem only 8 plus 3 characters are<br>
available. Vim tries to detect the type of filesystem when it is<br>
creating the .swp file. If an MS-DOS-like filesystem is suspected,<br>
a flag is set that has the same effect as setting the <a class="Type" href="options.html#'shortname'">'shortname'</a><br>
option. This flag will be reset as soon as you start editing a<br>
new file. The flag will be used when making the file name for the<br>
".swp" and ".~" files for the current file. But when you are<br>
editing a file in a normal filesystem and write to an MS-DOS-like<br>
filesystem the flag will not have been set. In that case the<br>
creation of the ".~" file may fail and you will get an error<br>
message. Use the <a class="Type" href="options.html#'shortname'">'shortname'</a> option in this case.<br>
<br>
When you started editing without giving a file name, "No File" is displayed in<br>
messages. If the ":write" command is used with a file name argument, the file<br>
name for the current file is set to that file name. This only happens when<br>
the 'F' flag is included in <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a> (by default it is included) <a class="Identifier" href="options.html#cpo-F">cpo-F</a>.<br>
This is useful when entering text in an empty buffer and then writing it to a<br>
file. If <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a> contains the 'f' flag (by default it is NOT included)<br>
<a class="Identifier" href="options.html#cpo-f">cpo-f</a> the file name is set for the ":read file" command. This is useful<br>
when starting Vim without an argument and then doing ":read file" to start<br>
editing a file.<br>
When the file name was set and <a class="Type" href="options.html#'filetype'">'filetype'</a> is empty the filetype detection<br>
autocommands will be triggered.<br>
<a class="Constant" href="editing.html#not-edited" name="not-edited">not-edited</a><br>
Because the file name was set without really starting to edit that file, you<br>
are protected from overwriting that file. This is done by setting the<br>
"notedited" flag. You can see if this flag is set with the <span class="Special">CTRL-G</span> or ":file"<br>
command. It will include "[Not edited]" when the "notedited" flag is set.<br>
When writing the buffer to the current file name (with ":w!"), the "notedited"<br>
flag is reset.<br>
<br>
<a class="Constant" href="editing.html#abandon" name="abandon">abandon</a><br>
Vim remembers whether you have changed the buffer. You are protected from<br>
losing the changes you made. If you try to quit without writing, or want to<br>
start editing another file, Vim will refuse this. In order to overrule this<br>
protection, add a '!' to the command. The changes will then be lost. For<br>
example: ":q" will not work if the buffer was changed, but ":q!" will. To see<br>
whether the buffer was changed use the "<span class="Special">CTRL-G</span>" command. The message includes<br>
the string "[Modified]" if the buffer has been changed, or "+" if the 'm' flag<br>
is in <a class="Type" href="options.html#'shortmess'">'shortmess'</a>.<br>
<br>
If you want to automatically save the changes without asking, switch on the<br>
<a class="Type" href="options.html#'autowriteall'">'autowriteall'</a> option. <a class="Type" href="options.html#'autowrite'">'autowrite'</a> is the associated Vi-compatible option<br>
that does not work for all commands.<br>
<br>
If you want to keep the changed buffer without saving it, switch on the<br>
<a class="Type" href="options.html#'hidden'">'hidden'</a> option. See <a class="Identifier" href="windows.html#hidden-buffer">hidden-buffer</a>. Some commands work like this even when<br>
<a class="Type" href="options.html#'hidden'">'hidden'</a> is not set, check the help for the command.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. Editing a file <a class="Constant" href="editing.html#edit-a-file" name="edit-a-file">edit-a-file</a><br>
<br>
<a class="Constant" href="editing.html#:e" name=":e">:e</a> <a class="Constant" href="editing.html#:edit" name=":edit">:edit</a> <a class="Constant" href="editing.html#reload" name="reload">reload</a><br>
:e[dit] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> Edit the current file. This is useful to re-edit the<br>
current file, when it has been changed outside of Vim.<br>
This fails when changes have been made to the current<br>
buffer and <a class="Type" href="options.html#'autowriteall'">'autowriteall'</a> isn't set or the file can't<br>
be written.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{Vi: no ++opt}</span><br>
<br>
<a class="Constant" href="editing.html#:edit!" name=":edit!">:edit!</a> <a class="Constant" href="editing.html#discard" name="discard">discard</a><br>
:e[dit]! <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Edit the current file always. Discard any changes to<br>
the current buffer. This is useful if you want to<br>
start all over again.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{Vi: no ++opt}</span><br>
<br>
<a class="Constant" href="editing.html#:edit_f" name=":edit_f">:edit_f</a><br>
:e[dit] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{file}</span><br>
Edit <span class="Special">{file}</span>.<br>
This fails when changes have been made to the current<br>
buffer, unless <a class="Type" href="options.html#'hidden'">'hidden'</a> is set or <a class="Type" href="options.html#'autowriteall'">'autowriteall'</a> is<br>
set and the file can be written.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{Vi: no ++opt}</span><br>
<br>
<a class="Constant" href="editing.html#:edit!_f" name=":edit!_f">:edit!_f</a><br>
:e[dit]! <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{file}</span><br>
Edit <span class="Special">{file}</span> always. Discard any changes to the<br>
current buffer.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{Vi: no ++opt}</span><br>
<br>
:e[dit] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> #<span class="Special">[count]</span><br>
Edit the <span class="Special">[count]</span>th buffer (as shown by <a class="Identifier" href="windows.html#:files">:files</a>).<br>
This command does the same as <span class="Special">[count]</span> <span class="Special">CTRL-^</span>. But ":e<br>
#" doesn't work if the alternate buffer doesn't have a<br>
file name, while <span class="Special">CTRL-^</span> still works then.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{Vi: no ++opt}</span><br>
<br>
<a class="Constant" href="editing.html#:ene" name=":ene">:ene</a> <a class="Constant" href="editing.html#:enew" name=":enew">:enew</a><br>
:ene[w] Edit a new, unnamed buffer. This fails when changes<br>
have been made to the current buffer, unless <a class="Type" href="options.html#'hidden'">'hidden'</a><br>
is set or <a class="Type" href="options.html#'autowriteall'">'autowriteall'</a> is set and the file can be<br>
written.<br>
If <a class="Type" href="options.html#'fileformats'">'fileformats'</a> is not empty, the first format given<br>
will be used for the new buffer. If <a class="Type" href="options.html#'fileformats'">'fileformats'</a> is<br>
empty, the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> of the current buffer is used.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:ene!" name=":ene!">:ene!</a> <a class="Constant" href="editing.html#:enew!" name=":enew!">:enew!</a><br>
:ene[w]! Edit a new, unnamed buffer. Discard any changes to<br>
the current buffer.<br>
Set <a class="Type" href="options.html#'fileformat'">'fileformat'</a> like <a class="Identifier" href="editing.html#:enew">:enew</a>.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:fin" name=":fin">:fin</a> <a class="Constant" href="editing.html#:find" name=":find">:find</a><br>
:fin[d][!] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{file}</span><br>
Find <span class="Special">{file}</span> in <a class="Type" href="options.html#'path'">'path'</a> and then <a class="Identifier" href="editing.html#:edit">:edit</a> it.<br>
<span class="Special">{not in Vi}</span> <span class="Special">{not available when the </span><a class="Identifier" href="various.html#+file_in_path">+file_in_path</a><br>
<span class="Special">feature was disabled at compile time}</span><br>
<br>
:<span class="Special">{count}</span>fin[d][!] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{file}</span><br>
Just like ":find", but use the <span class="Special">{count}</span> match in<br>
<a class="Type" href="options.html#'path'">'path'</a>. Thus ":2find file" will find the second<br>
"file" found in <a class="Type" href="options.html#'path'">'path'</a>. When there are fewer matches<br>
for the file in <a class="Type" href="options.html#'path'">'path'</a> than asked for, you get an<br>
error message.<br>
<br>
<a class="Constant" href="editing.html#:ex" name=":ex">:ex</a><br>
:ex <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">[file]</span><br>
Same as <a class="Identifier" href="editing.html#:edit">:edit</a>.<br>
<br>
<a class="Constant" href="editing.html#:vi" name=":vi">:vi</a> <a class="Constant" href="editing.html#:visual" name=":visual">:visual</a><br>
:vi[sual][!] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">[file]</span><br>
When used in Ex mode: Leave <a class="Identifier" href="intro.html#Ex-mode">Ex-mode</a>, go back to<br>
Normal mode. Otherwise same as <a class="Identifier" href="editing.html#:edit">:edit</a>.<br>
<br>
<a class="Constant" href="editing.html#:vie" name=":vie">:vie</a> <a class="Constant" href="editing.html#:view" name=":view">:view</a><br>
:vie[w][!] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> file<br>
When used in Ex mode: Leave <a class="Identifier" href="intro.html#Ex-mode">Ex-mode</a>, go back to<br>
Normal mode. Otherwise same as <a class="Identifier" href="editing.html#:edit">:edit</a>, but set<br>
<a class="Type" href="options.html#'readonly'">'readonly'</a> option for this buffer. <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#CTRL-^" name="CTRL-^">CTRL-^</a> <a class="Constant" href="editing.html#CTRL-6" name="CTRL-6">CTRL-6</a><br>
<span class="Special">CTRL-^</span> Edit the alternate file. Mostly the alternate file is<br>
the previously edited file. This is a quick way to<br>
toggle between two files. It is equivalent to ":e #",<br>
except that it also works when there is no file name.<br>
<br>
If the <a class="Type" href="options.html#'autowrite'">'autowrite'</a> or <a class="Type" href="options.html#'autowriteall'">'autowriteall'</a> option is on and<br>
the buffer was changed, write it.<br>
Mostly the ^ character is positioned on the 6 key,<br>
pressing CTRL and 6 then gets you what we call <span class="Special">CTRL-^</span>.<br>
But on some non-US keyboards <span class="Special">CTRL-^</span> is produced in<br>
another way.<br>
<br>
<span class="Special">{count}CTRL-^</span> Edit <span class="Special">[count]</span>th file in the buffer list (equivalent to<br>
":e #<span class="Special">[count]</span>"). This is a quick way to switch between<br>
files.<br>
See <a class="Identifier" href="editing.html#CTRL-^">CTRL-^</a> above for further details.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<span class="Special">[count]</span>]f <a class="Constant" href="editing.html#]f" name="]f">]f</a> <a class="Constant" href="editing.html#[f" name="[f">[f</a><br>
<span class="Special">[count]</span>[f Same as "gf". Deprecated.<br>
<br>
<a class="Constant" href="editing.html#gf" name="gf">gf</a> <a class="Constant" href="editing.html#E446" name="E446">E446</a> <a class="Constant" href="editing.html#E447" name="E447">E447</a><br>
<span class="Special">[count]</span>gf Edit the file whose name is under or after the cursor.<br>
Mnemonic: "goto file".<br>
Uses the <a class="Type" href="options.html#'isfname'">'isfname'</a> option to find out which characters<br>
are supposed to be in a file name. Trailing<br>
punctuation characters ".,:;!" are ignored. Escaped<br>
spaces "\ " are reduced to a single space.<br>
Uses the <a class="Type" href="options.html#'path'">'path'</a> option as a list of directory names to<br>
look for the file. See the <a class="Type" href="options.html#'path'">'path'</a> option for details<br>
about relative directories and wildcards.<br>
Uses the <a class="Type" href="options.html#'suffixesadd'">'suffixesadd'</a> option to check for file names<br>
with a suffix added.<br>
If the file can't be found, <a class="Type" href="options.html#'includeexpr'">'includeexpr'</a> is used to<br>
modify the name and another attempt is done.<br>
If a <span class="Special">[count]</span> is given, the count'th file that is found<br>
in the <a class="Type" href="options.html#'path'">'path'</a> is edited.<br>
This command fails if Vim refuses to <a class="Identifier" href="editing.html#abandon">abandon</a> the<br>
current file.<br>
If you want to edit the file in a new window use<br>
<a class="Identifier" href="windows.html#CTRL-W_CTRL-F">CTRL-W_CTRL-F</a>.<br>
If you do want to edit a new file, use:<br>
<div class="helpExample"> :e <cfile></div>
To make gf always work like that:<br>
<div class="helpExample"> :map gf :e <cfile><CR></div>
If the name is a hypertext link, that looks like<br>
"type://machine/path", you need the <a class="Identifier" href="pi_netrw.html#netrw">netrw</a> plugin.<br>
For Unix the '~' character is expanded, like in<br>
"~user/file". Environment variables are expanded too<br>
<a class="Identifier" href="options.html#expand-env">expand-env</a>.<br>
<span class="Special">{not in Vi}</span><br>
<span class="Special">{not available when the </span><a class="Identifier" href="various.html#+file_in_path">+file_in_path</a><span class="Special"> feature was</span><br>
<span class="Special">disabled at compile time}</span><br>
<br>
<a class="Constant" href="editing.html#v_gf" name="v_gf">v_gf</a><br>
<span class="Special">{Visual}[count]</span>gf Same as "gf", but the highlighted text is used as the<br>
name of the file to edit. <a class="Type" href="options.html#'isfname'">'isfname'</a> is ignored.<br>
Leading blanks are skipped, otherwise all blanks and<br>
special characters are included in the file name.<br>
(For <span class="Special">{Visual}</span> see <a class="Identifier" href="visual.html#Visual-mode">Visual-mode</a>.)<br>
<span class="Special">{not in VI}</span><br>
<br>
<a class="Constant" href="editing.html#gF" name="gF">gF</a><br>
<span class="Special">[count]</span>gF Same as "gf", except if a number follows the file<br>
name, then the cursor is positioned on that line in<br>
the file. The file name and the number must be<br>
separated by a non-filename (see <a class="Type" href="options.html#'isfname'">'isfname'</a>) and<br>
non-numeric character. White space between the<br>
filename, the separator and the number are ignored.<br>
Examples:<br>
<span class="PreProc">eval.c:10</span><br>
<span class="PreProc">eval.c @ 20</span><br>
<span class="PreProc">eval.c (30)</span><br>
<span class="PreProc">eval.c 40</span><br>
<br>
<a class="Constant" href="editing.html#v_gF" name="v_gF">v_gF</a><br>
<span class="Special">{Visual}[count]</span>gF Same as "v_gf".<br>
<br>
These commands are used to start editing a single file. This means that the<br>
file is read into the buffer and the current file name is set. The file that<br>
is opened depends on the current directory, see <a class="Identifier" href="editing.html#:cd">:cd</a>.<br>
<br>
See <a class="Identifier" href="insert.html#read-messages">read-messages</a> for an explanation of the message that is given after the<br>
file has been read.<br>
<br>
You can use the ":e!" command if you messed up the buffer and want to start<br>
all over again. The ":e" command is only useful if you have changed the<br>
current file name.<br>
<br>
<a class="Constant" href="editing.html#:filename" name=":filename">:filename</a> <a class="Constant" href="editing.html#{file}" name="{file}">{file}</a><br>
Besides the things mentioned here, more special items for where a filename is<br>
expected are mentioned at <a class="Identifier" href="cmdline.html#cmdline-special">cmdline-special</a>.<br>
<br>
<span class="Todo">Note</span> for systems other than Unix: When using a command that accepts a single<br>
file name (like ":edit file") spaces in the file name are allowed, but<br>
trailing spaces are ignored. This is useful on systems that regularly embed<br>
spaces in file names (like MS-Windows and the Amiga). Example: The command<br>
":e Long File Name " will edit the file "Long File Name". When using a<br>
command that accepts more than one file name (like ":next file1 file2")<br>
embedded spaces must be escaped with a backslash.<br>
<br>
<a class="Constant" href="editing.html#wildcard" name="wildcard">wildcard</a> <a class="Constant" href="editing.html#wildcards" name="wildcards">wildcards</a><br>
Wildcards in <span class="Special">{file}</span> are expanded, but as with file completion, <a class="Type" href="options.html#'wildignore'">'wildignore'</a><br>
and <a class="Type" href="options.html#'suffixes'">'suffixes'</a> apply. Which wildcards are supported depends on the system.<br>
These are the common ones:<br>
? matches one character<br>
* matches anything, including nothing<br>
** matches anything, including nothing, recurses into directories<br>
<span class="Special">[abc]</span> match 'a', 'b' or 'c'<br>
<br>
To avoid the special meaning of the wildcards prepend a backslash. However,<br>
on MS-Windows the backslash is a path separator and "path\[abc]" is still seen<br>
as a wildcard when "[" is in the <a class="Type" href="options.html#'isfname'">'isfname'</a> option. A simple way to avoid this<br>
is to use "path\[[]abc]", this matches the file "path\[abc]".<br>
<br>
<a class="Constant" href="editing.html#starstar-wildcard" name="starstar-wildcard">starstar-wildcard</a><br>
Expanding "**" is possible on Unix, Win32, Mac OS/X and a few other systems.<br>
This allows searching a directory tree. This goes up to 100 directories deep.<br>
<span class="Todo">Note</span> there are some commands where this works slightly differently, see<br>
<a class="Identifier" href="editing.html#file-searching">file-searching</a>.<br>
Example:<br>
<div class="helpExample"> :n **/*.txt</div>
Finds files:<br>
<span class="PreProc">aaa.txt</span><br>
<span class="PreProc">subdir/bbb.txt</span><br>
<span class="PreProc">a/b/c/d/ccc.txt</span><br>
When non-wildcard characters are used right before or after "**" these are<br>
only matched in the top directory. They are not used for directories further<br>
down in the tree. For example:<br>
<div class="helpExample"> :n /usr/inc**/types.h</div>
Finds files:<br>
<span class="PreProc">/usr/include/types.h</span><br>
<span class="PreProc">/usr/include/sys/types.h</span><br>
<span class="PreProc">/usr/inc/old/types.h</span><br>
<span class="Todo">Note</span> that the path with "/sys" is included because it does not need to match<br>
"/inc". Thus it's like matching "/usr/inc*/*/*...", not<br>
"/usr/inc*/inc*/inc*".<br>
<br>
<a class="Constant" href="editing.html#backtick-expansion" name="backtick-expansion">backtick-expansion</a> <a class="Constant" href="editing.html#`-expansion" name="`-expansion">`-expansion</a><br>
On Unix and a few other systems you can also use backticks for the file name<br>
argument, for example:<br>
<div class="helpExample"> :next `find . -name ver\\*.c -print`<br>
:view `ls -t *.patch \| head -n1`</div>
The backslashes before the star are required to prevent the shell from<br>
expanding "ver*.c" prior to execution of the find program. The backslash<br>
before the shell pipe symbol "|" prevents Vim from parsing it as command<br>
termination.<br>
This also works for most other systems, with the restriction that the<br>
backticks must be around the whole item. It is not possible to have text<br>
directly before the first or just after the last backtick.<br>
<br>
<a class="Constant" href="editing.html#`=" name="`=">`=</a><br>
You can have the backticks expanded as a Vim expression, instead of as an<br>
external command, by putting an equal sign right after the first backtick,<br>
e.g.:<br>
<div class="helpExample"> :e `=tempname()`</div>
The expression can contain just about anything, thus this can also be used to<br>
avoid the special meaning of '"', '|', '%' and '#'. However, <a class="Type" href="options.html#'wildignore'">'wildignore'</a><br>
does apply like to other wildcards.<br>
<br>
Environment variables in the expression are expanded when evaluating the<br>
expression, thus this works:<br>
<div class="helpExample"> :e `=$HOME . '/.vimrc'`</div>
This does not work, $HOME is inside a string and used literally:<br>
<div class="helpExample"> :e `='$HOME' . '/.vimrc'`</div>
<br>
If the expression returns a string then names are to be separated with line<br>
breaks. When the result is a <a class="Identifier" href="eval.html#List">List</a> then each item is used as a name. Line<br>
breaks also separate names.<br>
<span class="Todo">Note</span> that such expressions are only supported in places where a filename is<br>
expected as an argument to an Ex-command.<br>
<br>
<a class="Constant" href="editing.html#++opt" name="++opt">++opt</a> <a class="Constant" href="editing.html#[++opt]" name="[++opt]">[++opt]</a><br>
The <span class="Special">[++opt]</span> argument can be used to force the value of <a class="Type" href="options.html#'fileformat'">'fileformat'</a>,<br>
<a class="Type" href="options.html#'fileencoding'">'fileencoding'</a> or <a class="Type" href="options.html#'binary'">'binary'</a> to a value for one command, and to specify the<br>
behavior for bad characters. The form is:<br>
<div class="helpExample"> ++{optname}</div>
Or:<br>
<div class="helpExample"> ++{optname}={value}</div>
<br>
Where <span class="Special">{optname}</span> is one of: <a class="Constant" href="editing.html#++ff" name="++ff">++ff</a> <a class="Constant" href="editing.html#++enc" name="++enc">++enc</a> <a class="Constant" href="editing.html#++bin" name="++bin">++bin</a> <a class="Constant" href="editing.html#++nobin" name="++nobin">++nobin</a> <a class="Constant" href="editing.html#++edit" name="++edit">++edit</a><br>
ff or fileformat overrides <a class="Type" href="options.html#'fileformat'">'fileformat'</a><br>
enc or encoding overrides <a class="Type" href="options.html#'fileencoding'">'fileencoding'</a><br>
bin or binary sets <a class="Type" href="options.html#'binary'">'binary'</a><br>
nobin or nobinary resets <a class="Type" href="options.html#'binary'">'binary'</a><br>
bad specifies behavior for bad characters<br>
edit for <a class="Identifier" href="insert.html#:read">:read</a> only: keep option values as if editing<br>
a file<br>
<br>
<span class="Special">{value}</span> cannot contain white space. It can be any valid value for these<br>
options. Examples:<br>
<div class="helpExample"> :e ++ff=unix</div>
This edits the same file again with <a class="Type" href="options.html#'fileformat'">'fileformat'</a> set to "unix".<br>
<br>
<div class="helpExample"> :w ++enc=latin1 newfile</div>
This writes the current buffer to "newfile" in latin1 format.<br>
<br>
There may be several ++opt arguments, separated by white space. They must all<br>
appear before any <a class="Identifier" href="editing.html#+cmd">+cmd</a> argument.<br>
<br>
<a class="Constant" href="editing.html#++bad" name="++bad">++bad</a><br>
The argument of "++bad=" specifies what happens with characters that can't be<br>
converted and illegal bytes. It can be one of three things:<br>
++bad=X A single-byte character that replaces each bad character.<br>
++bad=keep Keep bad characters without conversion. <span class="Todo">Note</span> that this may<br>
result in illegal bytes in your text!<br>
++bad=drop Remove the bad characters.<br>
<br>
The default is like "++bad=?": Replace each bad character with a question<br>
mark. In some places an inverted question mark is used (0xBF).<br>
<br>
<span class="Todo">Note</span> that not all commands use the ++bad argument, even though they do not<br>
give an error when you add it. E.g. <a class="Identifier" href="editing.html#:write">:write</a>.<br>
<br>
<span class="Todo">Note</span> that when reading, the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> and <a class="Type" href="options.html#'fileencoding'">'fileencoding'</a> options will be<br>
set to the used format. When writing this doesn't happen, thus a next write<br>
will use the old value of the option. Same for the <a class="Type" href="options.html#'binary'">'binary'</a> option.<br>
<br>
<br>
<a class="Constant" href="editing.html#+cmd" name="+cmd">+cmd</a> <a class="Constant" href="editing.html#[+cmd]" name="[+cmd]">[+cmd]</a><br>
The <span class="Special">[+cmd]</span> argument can be used to position the cursor in the newly opened<br>
file, or execute any other command:<br>
+ Start at the last line.<br>
+<span class="Special">{num}</span> Start at line <span class="Special">{num}</span>.<br>
+/<span class="Special">{pat}</span> Start at first line containing <span class="Special">{pat}</span>.<br>
+<span class="Special">{command}</span> Execute <span class="Special">{command}</span> after opening the new file.<br>
<span class="Special">{command}</span> is any Ex command.<br>
To include a white space in the <span class="Special">{pat}</span> or <span class="Special">{command}</span>, precede it with a<br>
backslash. Double the number of backslashes.<br>
<div class="helpExample"> :edit +/The\ book file<br>
:edit +/dir\ dirname\\ file<br>
:edit +set\ dir=c:\\\\temp file</div>
<span class="Todo">Note</span> that in the last example the number of backslashes is halved twice: Once<br>
for the "+cmd" argument and once for the ":set" command.<br>
<br>
<a class="Constant" href="editing.html#file-formats" name="file-formats">file-formats</a><br>
The <a class="Type" href="options.html#'fileformat'">'fileformat'</a> option sets the <span class="Special"><EOL></span> style for a file:<br>
<span class="PreProc">'fileformat' characters name </span><br>
"dos" <span class="Special"><CR><NL></span> or <span class="Special"><NL></span> DOS format <a class="Constant" href="editing.html#DOS-format" name="DOS-format">DOS-format</a><br>
"unix" <span class="Special"><NL></span> Unix format <a class="Constant" href="editing.html#Unix-format" name="Unix-format">Unix-format</a><br>
"mac" <span class="Special"><CR></span> Mac format <a class="Constant" href="editing.html#Mac-format" name="Mac-format">Mac-format</a><br>
Previously <a class="Type" href="options.html#'textmode'">'textmode'</a> was used. It is obsolete now.<br>
<br>
When reading a file, the mentioned characters are interpreted as the <span class="Special"><EOL></span>.<br>
In DOS format (default for MS-DOS, OS/2 and Win32), <span class="Special"><CR><NL></span> and <span class="Special"><NL></span> are both<br>
interpreted as the <span class="Special"><EOL></span>. <span class="Todo">Note</span> that when writing the file in DOS format,<br>
<span class="Special"><CR></span> characters will be added for each single <span class="Special"><NL></span>. Also see <a class="Identifier" href="insert.html#file-read">file-read</a>.<br>
<br>
When writing a file, the mentioned characters are used for <span class="Special"><EOL></span>. For DOS<br>
format <span class="Special"><CR><NL></span> is used. Also see <a class="Identifier" href="editing.html#DOS-format-write">DOS-format-write</a>.<br>
<br>
You can read a file in DOS format and write it in Unix format. This will<br>
replace all <span class="Special"><CR><NL></span> pairs by <span class="Special"><NL></span> (assuming <a class="Type" href="options.html#'fileformats'">'fileformats'</a> includes "dos"):<br>
<div class="helpExample"> :e file<br>
:set fileformat=unix<br>
:w</div>
If you read a file in Unix format and write with DOS format, all <span class="Special"><NL></span><br>
characters will be replaced with <span class="Special"><CR><NL></span> (assuming <a class="Type" href="options.html#'fileformats'">'fileformats'</a> includes<br>
"unix"):<br>
<div class="helpExample"> :e file<br>
:set fileformat=dos<br>
:w</div>
<br>
If you start editing a new file and the <a class="Type" href="options.html#'fileformats'">'fileformats'</a> option is not empty<br>
(which is the default), Vim will try to detect whether the lines in the file<br>
are separated by the specified formats. When set to "unix,dos", Vim will<br>
check for lines with a single <span class="Special"><NL></span> (as used on Unix and Amiga) or by a <span class="Special"><CR></span><br>
<span class="Special"><NL></span> pair (MS-DOS). Only when ALL lines end in <span class="Special"><CR><NL></span>, <a class="Type" href="options.html#'fileformat'">'fileformat'</a> is set<br>
to "dos", otherwise it is set to "unix". When <a class="Type" href="options.html#'fileformats'">'fileformats'</a> includes "mac",<br>
and no <span class="Special"><NL></span> characters are found in the file, <a class="Type" href="options.html#'fileformat'">'fileformat'</a> is set to "mac".<br>
<br>
If the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> option is set to "dos" on non-MS-DOS systems the message<br>
"[dos format]" is shown to remind you that something unusual is happening. On<br>
MS-DOS systems you get the message "[unix format]" if <a class="Type" href="options.html#'fileformat'">'fileformat'</a> is set to<br>
"unix". On all systems but the Macintosh you get the message "[mac format]"<br>
if <a class="Type" href="options.html#'fileformat'">'fileformat'</a> is set to "mac".<br>
<br>
If the <a class="Type" href="options.html#'fileformats'">'fileformats'</a> option is empty and DOS format is used, but while reading<br>
a file some lines did not end in <span class="Special"><CR><NL></span>, "[CR missing]" will be included in<br>
the file message.<br>
If the <a class="Type" href="options.html#'fileformats'">'fileformats'</a> option is empty and Mac format is used, but while reading<br>
a file a <span class="Special"><NL></span> was found, "[NL missing]" will be included in the file message.<br>
<br>
If the new file does not exist, the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> of the current buffer is used<br>
when <a class="Type" href="options.html#'fileformats'">'fileformats'</a> is empty. Otherwise the first format from <a class="Type" href="options.html#'fileformats'">'fileformats'</a> is<br>
used for the new file.<br>
<br>
Before editing binary, executable or Vim script files you should set the<br>
<a class="Type" href="options.html#'binary'">'binary'</a> option. A simple way to do this is by starting Vim with the "-b"<br>
option. This will avoid the use of <a class="Type" href="options.html#'fileformat'">'fileformat'</a>. Without this you risk that<br>
single <span class="Special"><NL></span> characters are unexpectedly replaced with <span class="Special"><CR><NL></span>.<br>
<br>
You can encrypt files that are written by setting the <a class="Type" href="options.html#'key'">'key'</a> option. This<br>
provides some security against others reading your files. <a class="Identifier" href="editing.html#encryption">encryption</a><br>
<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. The argument list <a class="Constant" href="editing.html#argument-list" name="argument-list">argument-list</a> <a class="Constant" href="editing.html#arglist" name="arglist">arglist</a><br>
<br>
If you give more than one file name when starting Vim, this list is remembered<br>
as the argument list. You can jump to each file in this list.<br>
<br>
Do not confuse this with the buffer list, which you can see with the<br>
<a class="Identifier" href="windows.html#:buffers">:buffers</a> command. The argument list was already present in Vi, the buffer<br>
list is new in Vim. Every file name in the argument list will also be present<br>
in the buffer list (unless it was deleted with <a class="Identifier" href="windows.html#:bdel">:bdel</a> or <a class="Identifier" href="windows.html#:bwipe">:bwipe</a>). But it's<br>
common that names in the buffer list are not in the argument list.<br>
<br>
This subject is introduced in section <a class="Identifier" href="usr_07.html#07.2">07.2</a> of the user manual.<br>
<br>
There is one global argument list, which is used for all windows by default.<br>
It is possible to create a new argument list local to a window, see<br>
<a class="Identifier" href="editing.html#:arglocal">:arglocal</a>.<br>
<br>
You can use the argument list with the following commands, and with the<br>
expression functions <a class="Identifier" href="eval.html#argc()">argc()</a> and <a class="Identifier" href="eval.html#argv()">argv()</a>. These all work on the argument<br>
list of the current window.<br>
<br>
<a class="Constant" href="editing.html#:ar" name=":ar">:ar</a> <a class="Constant" href="editing.html#:args" name=":args">:args</a><br>
:ar[gs] Print the argument list, with the current file in<br>
square brackets.<br>
<br>
:ar[gs] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{arglist}</span> <a class="Constant" href="editing.html#:args_f" name=":args_f">:args_f</a><br>
Define <span class="Special">{arglist}</span> as the new argument list and edit<br>
the first one. This fails when changes have been made<br>
and Vim does not want to <a class="Identifier" href="editing.html#abandon">abandon</a> the current buffer.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{Vi: no ++opt}</span><br>
<br>
:ar[gs]! <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{arglist}</span> <a class="Constant" href="editing.html#:args_f!" name=":args_f!">:args_f!</a><br>
Define <span class="Special">{arglist}</span> as the new argument list and edit<br>
the first one. Discard any changes to the current<br>
buffer.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{Vi: no ++opt}</span><br>
<br>
:<span class="Special">[count]</span>arge[dit][!] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{name}</span> .. <a class="Constant" href="editing.html#:arge" name=":arge">:arge</a> <a class="Constant" href="editing.html#:argedit" name=":argedit">:argedit</a><br>
Add <span class="Special">{name}</span>s to the argument list and edit it.<br>
When <span class="Special">{name}</span> already exists in the argument list, this<br>
entry is edited.<br>
This is like using <a class="Identifier" href="editing.html#:argadd">:argadd</a> and then <a class="Identifier" href="editing.html#:edit">:edit</a>.<br>
Spaces in filenames have to be escaped with "\".<br>
<span class="Special">[count]</span> is used like with <a class="Identifier" href="editing.html#:argadd">:argadd</a>.<br>
If the current file cannot be <a class="Identifier" href="editing.html#abandon">abandon</a>ed <span class="Special">{name}</span>s will<br>
still be added to the argument list, but won't be<br>
edited. No check for duplicates is done.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{not in Vi}</span><br>
<br>
:<span class="Special">[count]</span>arga[dd] <span class="Special">{name}</span> .. <a class="Constant" href="editing.html#:arga" name=":arga">:arga</a> <a class="Constant" href="editing.html#:argadd" name=":argadd">:argadd</a> <a class="Constant" href="editing.html#E479" name="E479">E479</a><br>
:<span class="Special">[count]</span>arga[dd]<br>
Add the <span class="Special">{name}</span>s to the argument list. When <span class="Special">{name}</span> is<br>
omitted add the current buffer name to the argument<br>
list.<br>
If <span class="Special">[count]</span> is omitted, the <span class="Special">{name}</span>s are added just<br>
after the current entry in the argument list.<br>
Otherwise they are added after the <span class="Special">[count]</span>'th file.<br>
If the argument list is "a b c", and "b" is the<br>
current argument, then these commands result in:<br>
<span class="PreProc">command new argument list</span><br>
:argadd x a b x c<br>
:0argadd x x a b c<br>
:1argadd x a x b c<br>
:$argadd x a b c x<br>
And after the last one:<br>
:+2argadd y a b c x y<br>
There is no check for duplicates, it is possible to<br>
add a file to the argument list twice.<br>
The currently edited file is not changed.<br>
<span class="Special">{not in Vi}</span> <span class="Special">{not available when compiled without the</span><br>
<a class="Identifier" href="various.html#+listcmds">+listcmds</a><span class="Special"> feature}</span><br>
<span class="Todo">Note</span>: you can also use this method:<br>
<div class="helpExample"> :args ## x</div>
This will add the "x" item and sort the new list.<br>
<br>
:argd[elete] <span class="Special">{pattern}</span> .. <a class="Constant" href="editing.html#:argd" name=":argd">:argd</a> <a class="Constant" href="editing.html#:argdelete" name=":argdelete">:argdelete</a> <a class="Constant" href="editing.html#E480" name="E480">E480</a><br>
Delete files from the argument list that match the<br>
<span class="Special">{pattern}</span>s. <span class="Special">{pattern}</span> is used like a file pattern,<br>
see <a class="Identifier" href="autocmd.html#file-pattern">file-pattern</a>. "%" can be used to delete the<br>
current entry.<br>
This command keeps the currently edited file, also<br>
when it's deleted from the argument list.<br>
Example:<br>
<div class="helpExample"> :argdel *.obj</div>
<span class="Special">{not in Vi}</span> <span class="Special">{not available when compiled without the</span><br>
<a class="Identifier" href="various.html#+listcmds">+listcmds</a><span class="Special"> feature}</span><br>
<br>
:<span class="Special">[range]</span>argd[elete] Delete the <span class="Special">{range}</span> files from the argument list.<br>
Example:<br>
<div class="helpExample"> :10,$argdel</div>
Deletes arguments 10 and further, keeping 1-9.<br>
<div class="helpExample"> :$argd</div>
Deletes just the last one.<br>
<div class="helpExample"> :argd<br>
:.argd</div>
Deletes the current argument.<br>
<div class="helpExample"> :%argd</div>
Removes all the files from the arglist.<br>
When the last number in the range is too high, up to<br>
the last argument is deleted.<br>
<span class="Special">{not in Vi}</span> <span class="Special">{not available when compiled without the</span><br>
<a class="Identifier" href="various.html#+listcmds">+listcmds</a><span class="Special"> feature}</span><br>
<br>
<a class="Constant" href="editing.html#:argu" name=":argu">:argu</a> <a class="Constant" href="editing.html#:argument" name=":argument">:argument</a><br>
:<span class="Special">[count]</span>argu[ment] <span class="Special">[count]</span> <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Edit file <span class="Special">[count]</span> in the argument list. When <span class="Special">[count]</span><br>
is omitted the current entry is used. This fails<br>
when changes have been made and Vim does not want to<br>
<a class="Identifier" href="editing.html#abandon">abandon</a> the current buffer.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{not in Vi}</span> <span class="Special">{not available when compiled without the</span><br>
<a class="Identifier" href="various.html#+listcmds">+listcmds</a><span class="Special"> feature}</span><br>
<br>
:<span class="Special">[count]</span>argu[ment]! <span class="Special">[count]</span> <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Edit file <span class="Special">[count]</span> in the argument list, discard any<br>
changes to the current buffer. When <span class="Special">[count]</span> is<br>
omitted the current entry is used.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>.<br>
<span class="Special">{not in Vi}</span> <span class="Special">{not available when compiled without the</span><br>
<a class="Identifier" href="various.html#+listcmds">+listcmds</a><span class="Special"> feature}</span><br>
<br>
:<span class="Special">[count]</span>n[ext] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <a class="Constant" href="editing.html#:n" name=":n">:n</a> <a class="Constant" href="editing.html#:ne" name=":ne">:ne</a> <a class="Constant" href="editing.html#:next" name=":next">:next</a> <a class="Constant" href="editing.html#E165" name="E165">E165</a> <a class="Constant" href="editing.html#E163" name="E163">E163</a><br>
Edit <span class="Special">[count]</span> next file. This fails when changes have<br>
been made and Vim does not want to <a class="Identifier" href="editing.html#abandon">abandon</a> the<br>
current buffer. Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{Vi: no</span><br>
<span class="Special">count or ++opt}</span>.<br>
<br>
:<span class="Special">[count]</span>n[ext]! <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Edit <span class="Special">[count]</span> next file, discard any changes to the<br>
buffer. Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{Vi: no count</span><br>
<span class="Special">or ++opt}</span>.<br>
<br>
:n[ext] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{arglist}</span> <a class="Constant" href="editing.html#:next_f" name=":next_f">:next_f</a><br>
Same as <a class="Identifier" href="editing.html#:args_f">:args_f</a>.<br>
<br>
:n[ext]! <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{arglist}</span><br>
Same as <a class="Identifier" href="editing.html#:args_f!">:args_f!</a>.<br>
<br>
:<span class="Special">[count]N</span>[ext] <span class="Special">[count]</span> <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <a class="Constant" href="editing.html#:Next" name=":Next">:Next</a> <a class="Constant" href="editing.html#:N" name=":N">:N</a> <a class="Constant" href="editing.html#E164" name="E164">E164</a><br>
Edit <span class="Special">[count]</span> previous file in argument list. This<br>
fails when changes have been made and Vim does not<br>
want to <a class="Identifier" href="editing.html#abandon">abandon</a> the current buffer.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{Vi: no count or ++opt}</span>.<br>
<br>
:<span class="Special">[count]N</span>[ext]! <span class="Special">[count]</span> <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Edit <span class="Special">[count]</span> previous file in argument list. Discard<br>
any changes to the buffer. Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and<br>
<a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{Vi: no count or ++opt}</span>.<br>
<br>
:<span class="Special">[count]</span>prev[ious] <span class="Special">[count]</span> <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <a class="Constant" href="editing.html#:prev" name=":prev">:prev</a> <a class="Constant" href="editing.html#:previous" name=":previous">:previous</a><br>
Same as :Next. Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{Vi:</span><br>
<span class="Special">only in some versions}</span><br>
<br>
<a class="Constant" href="editing.html#:rew" name=":rew">:rew</a> <a class="Constant" href="editing.html#:rewind" name=":rewind">:rewind</a><br>
:rew[ind] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Start editing the first file in the argument list.<br>
This fails when changes have been made and Vim does<br>
not want to <a class="Identifier" href="editing.html#abandon">abandon</a> the current buffer.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{Vi: no ++opt}</span><br>
<br>
:rew[ind]! <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Start editing the first file in the argument list.<br>
Discard any changes to the buffer. Also see <a class="Identifier" href="editing.html#++opt">++opt</a><br>
and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{Vi: no ++opt}</span><br>
<br>
<a class="Constant" href="editing.html#:fir" name=":fir">:fir</a> <a class="Constant" href="editing.html#:first" name=":first">:first</a><br>
:fir[st][!] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Other name for ":rewind". <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:la" name=":la">:la</a> <a class="Constant" href="editing.html#:last" name=":last">:last</a><br>
:la[st] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Start editing the last file in the argument list.<br>
This fails when changes have been made and Vim does<br>
not want to <a class="Identifier" href="editing.html#abandon">abandon</a> the current buffer.<br>
Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{not in Vi}</span><br>
<br>
:la[st]! <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span><br>
Start editing the last file in the argument list.<br>
Discard any changes to the buffer. Also see <a class="Identifier" href="editing.html#++opt">++opt</a><br>
and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:wn" name=":wn">:wn</a> <a class="Constant" href="editing.html#:wnext" name=":wnext">:wnext</a><br>
:<span class="Special">[count]</span>wn[ext] <span class="Special">[++opt]</span><br>
Write current file and start editing the <span class="Special">[count]</span><br>
next file. Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{not in Vi}</span><br>
<br>
:<span class="Special">[count]</span>wn[ext] <span class="Special">[++opt]</span> <span class="Special">{file}</span><br>
Write current file to <span class="Special">{file}</span> and start editing the<br>
<span class="Special">[count]</span> next file, unless <span class="Special">{file}</span> already exists and<br>
the <a class="Type" href="options.html#'writeany'">'writeany'</a> option is off. Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and<br>
<a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{not in Vi}</span><br>
<br>
:<span class="Special">[count]</span>wn[ext]! <span class="Special">[++opt]</span> <span class="Special">{file}</span><br>
Write current file to <span class="Special">{file}</span> and start editing the<br>
<span class="Special">[count]</span> next file. Also see <a class="Identifier" href="editing.html#++opt">++opt</a> and <a class="Identifier" href="editing.html#+cmd">+cmd</a>. <span class="Special">{not</span><br>
<span class="Special">in Vi}</span><br>
<br>
:<span class="Special">[count]</span>wN[ext][!] <span class="Special">[++opt]</span> <span class="Special">[file]</span> <a class="Constant" href="editing.html#:wN" name=":wN">:wN</a> <a class="Constant" href="editing.html#:wNext" name=":wNext">:wNext</a><br>
:<span class="Special">[count]</span>wp[revious][!] <span class="Special">[++opt]</span> <span class="Special">[file]</span> <a class="Constant" href="editing.html#:wp" name=":wp">:wp</a> <a class="Constant" href="editing.html#:wprevious" name=":wprevious">:wprevious</a><br>
Same as :wnext, but go to previous file instead of<br>
next. <span class="Special">{not in Vi}</span><br>
<br>
The <span class="Special">[count]</span> in the commands above defaults to one. For some commands it is<br>
possible to use two counts. The last one (rightmost one) is used.<br>
<br>
If no <span class="Special">[+cmd]</span> argument is present, the cursor is positioned at the last known<br>
cursor position for the file. If <a class="Type" href="options.html#'startofline'">'startofline'</a> is set, the cursor will be<br>
positioned at the first non-blank in the line, otherwise the last know column<br>
is used. If there is no last known cursor position the cursor will be in the<br>
first line (the last line in Ex mode).<br>
<br>
<a class="Constant" href="editing.html#{arglist}" name="{arglist}">{arglist}</a><br>
The wildcards in the argument list are expanded and the file names are sorted.<br>
Thus you can use the command "vim *.c" to edit all the C files. From within<br>
Vim the command ":n *.c" does the same.<br>
<br>
White space is used to separate file names. Put a backslash before a space or<br>
tab to include it in a file name. E.g., to edit the single file "foo bar":<br>
<div class="helpExample"> :next foo\ bar</div>
<br>
On Unix and a few other systems you can also use backticks, for example:<br>
<div class="helpExample"> :next `find . -name \\*.c -print`</div>
The backslashes before the star are required to prevent "*.c" to be expanded<br>
by the shell before executing the find program.<br>
<br>
<a class="Constant" href="editing.html#arglist-position" name="arglist-position">arglist-position</a><br>
When there is an argument list you can see which file you are editing in the<br>
title of the window (if there is one and <a class="Type" href="options.html#'title'">'title'</a> is on) and with the file<br>
message you get with the "<span class="Special">CTRL-G</span>" command. You will see something like<br>
(file 4 of 11)<br>
If <a class="Type" href="options.html#'shortmess'">'shortmess'</a> contains 'f' it will be<br>
(4 of 11)<br>
If you are not really editing the file at the current position in the argument<br>
list it will be<br>
(file (4) of 11)<br>
This means that you are position 4 in the argument list, but not editing the<br>
fourth file in the argument list. This happens when you do ":e file".<br>
<br>
<br>
LOCAL ARGUMENT LIST<br>
<br>
<span class="Special">{not in Vi}</span><br>
<span class="Special">{not available when compiled without the </span><a class="Identifier" href="various.html#+windows">+windows</a><span class="Special"> or </span><a class="Identifier" href="various.html#+listcmds">+listcmds</a><span class="Special"> features}</span><br>
<br>
<a class="Constant" href="editing.html#:arglocal" name=":arglocal">:arglocal</a><br>
:argl[ocal] Make a local copy of the global argument list.<br>
Doesn't start editing another file.<br>
<br>
:argl[ocal][!] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{arglist}</span><br>
Define a new argument list, which is local to the<br>
current window. Works like <a class="Identifier" href="editing.html#:args_f">:args_f</a> otherwise.<br>
<br>
<a class="Constant" href="editing.html#:argglobal" name=":argglobal">:argglobal</a><br>
:argg[lobal] Use the global argument list for the current window.<br>
Doesn't start editing another file.<br>
<br>
:argg[lobal][!] <span class="Special">[++opt]</span> <span class="Special">[+cmd]</span> <span class="Special">{arglist}</span><br>
Use the global argument list for the current window.<br>
Define a new global argument list like <a class="Identifier" href="editing.html#:args_f">:args_f</a>.<br>
All windows using the global argument list will see<br>
this new list.<br>
<br>
There can be several argument lists. They can be shared between windows.<br>
When they are shared, changing the argument list in one window will also<br>
change it in the other window.<br>
<br>
When a window is split the new window inherits the argument list from the<br>
current window. The two windows then share this list, until one of them uses<br>
<a class="Identifier" href="editing.html#:arglocal">:arglocal</a> or <a class="Identifier" href="editing.html#:argglobal">:argglobal</a> to use another argument list.<br>
<br>
<br>
USING THE ARGUMENT LIST<br>
<br>
<a class="Constant" href="editing.html#:argdo" name=":argdo">:argdo</a><br>
:<span class="Special">[range]</span>argdo[!] <span class="Special">{cmd}</span> Execute <span class="Special">{cmd}</span> for each file in the argument list or<br>
if <span class="Special">[range]</span> is specified only for arguments in that<br>
range. It works like doing this:<br>
<div class="helpExample"> :rewind<br>
:{cmd}<br>
:next<br>
:{cmd}<br>
etc.</div>
When the current file can't be <a class="Identifier" href="editing.html#abandon">abandon</a>ed and the [!]<br>
is not present, the command fails.<br>
When an error is detected on one file, further files<br>
in the argument list will not be visited.<br>
The last file in the argument list (or where an error<br>
occurred) becomes the current file.<br>
<span class="Special">{cmd}</span> can contain '|' to concatenate several commands.<br>
<span class="Special">{cmd}</span> must not change the argument list.<br>
<span class="Todo">Note</span>: While this command is executing, the Syntax<br>
autocommand event is disabled by adding it to<br>
<a class="Type" href="options.html#'eventignore'">'eventignore'</a>. This considerably speeds up editing<br>
each file.<br>
<span class="Special">{not in Vi}</span> <span class="Special">{not available when compiled without the</span><br>
<a class="Identifier" href="various.html#+listcmds">+listcmds</a><span class="Special"> feature}</span><br>
Also see <a class="Identifier" href="windows.html#:windo">:windo</a>, <a class="Identifier" href="tabpage.html#:tabdo">:tabdo</a>, <a class="Identifier" href="windows.html#:bufdo">:bufdo</a>, <a class="Identifier" href="quickfix.html#:cdo">:cdo</a>, <a class="Identifier" href="quickfix.html#:ldo">:ldo</a>,<br>
<a class="Identifier" href="quickfix.html#:cfdo">:cfdo</a> and <a class="Identifier" href="quickfix.html#:lfdo">:lfdo</a><br>
<br>
Example:<br>
<div class="helpExample"> :args *.c<br>
:argdo set ff=unix | update</div>
This sets the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> option to "unix" and writes the file if it is now<br>
changed. This is done for all *.c files.<br>
<br>
Example:<br>
<div class="helpExample"> :args *.[ch]<br>
:argdo %s/\<my_foo\>/My_Foo/ge | update</div>
This changes the word "my_foo" to "My_Foo" in all *.c and *.h files. The "e"<br>
flag is used for the ":substitute" command to avoid an error for files where<br>
"my_foo" isn't used. ":update" writes the file only if changes were made.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
4. Writing <a class="Constant" href="editing.html#writing" name="writing">writing</a> <a class="Constant" href="editing.html#save-file" name="save-file">save-file</a><br>
<br>
<span class="Todo">Note</span>: When the <a class="Type" href="options.html#'write'">'write'</a> option is off, you are not able to write any file.<br>
<br>
<a class="Constant" href="editing.html#:w" name=":w">:w</a> <a class="Constant" href="editing.html#:write" name=":write">:write</a><br>
<a class="Constant" href="editing.html#E502" name="E502">E502</a> <a class="Constant" href="editing.html#E503" name="E503">E503</a> <a class="Constant" href="editing.html#E504" name="E504">E504</a> <a class="Constant" href="editing.html#E505" name="E505">E505</a><br>
<a class="Constant" href="editing.html#E512" name="E512">E512</a> <a class="Constant" href="editing.html#E514" name="E514">E514</a> <a class="Constant" href="editing.html#E667" name="E667">E667</a> <a class="Constant" href="editing.html#E796" name="E796">E796</a><br>
:w[rite] <span class="Special">[++opt]</span> Write the whole buffer to the current file. This is<br>
the normal way to save changes to a file. It fails<br>
when the <a class="Type" href="options.html#'readonly'">'readonly'</a> option is set or when there is<br>
another reason why the file can't be written.<br>
For ++opt see <a class="Identifier" href="editing.html#++opt">++opt</a>, but only ++bin, ++nobin, ++ff<br>
and ++enc are effective.<br>
<br>
:w[rite]! <span class="Special">[++opt]</span> Like ":write", but forcefully write when <a class="Type" href="options.html#'readonly'">'readonly'</a> is<br>
set or there is another reason why writing was<br>
refused.<br>
<span class="Todo">Note</span>: This may change the permission and ownership of<br>
the file and break (symbolic) links. Add the 'W' flag<br>
to <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a> to avoid this.<br>
<br>
:<span class="Special">[range]</span>w[rite][!] <span class="Special">[++opt]</span><br>
Write the specified lines to the current file. This<br>
is unusual, because the file will not contain all<br>
lines in the buffer.<br>
<br>
<a class="Constant" href="editing.html#:w_f" name=":w_f">:w_f</a> <a class="Constant" href="editing.html#:write_f" name=":write_f">:write_f</a><br>
:<span class="Special">[range]</span>w[rite] <span class="Special">[++opt]</span> <span class="Special">{file}</span><br>
Write the specified lines to <span class="Special">{file}</span>, unless it<br>
already exists and the <a class="Type" href="options.html#'writeany'">'writeany'</a> option is off.<br>
<br>
<a class="Constant" href="editing.html#:w!" name=":w!">:w!</a><br>
:<span class="Special">[range]</span>w[rite]! <span class="Special">[++opt]</span> <span class="Special">{file}</span><br>
Write the specified lines to <span class="Special">{file}</span>. Overwrite an<br>
existing file.<br>
<br>
<a class="Constant" href="editing.html#:w_a" name=":w_a">:w_a</a> <a class="Constant" href="editing.html#:write_a" name=":write_a">:write_a</a> <a class="Constant" href="editing.html#E494" name="E494">E494</a><br>
:<span class="Special">[range]</span>w[rite][!] <span class="Special">[++opt]</span> >><br>
Append the specified lines to the current file.<br>
<br>
:<span class="Special">[range]</span>w[rite][!] <span class="Special">[++opt]</span> >> <span class="Special">{file}</span><br>
Append the specified lines to <span class="Special">{file}</span>. '!' forces the<br>
write even if file does not exist.<br>
<br>
<a class="Constant" href="editing.html#:w_c" name=":w_c">:w_c</a> <a class="Constant" href="editing.html#:write_c" name=":write_c">:write_c</a><br>
:<span class="Special">[range]</span>w[rite] <span class="Special">[++opt]</span> !<span class="Special">{cmd}</span><br>
Execute <span class="Special">{cmd}</span> with <span class="Special">[range]</span> lines as standard input<br>
(<span class="Todo">note</span> the space in front of the '!'). <span class="Special">{cmd}</span> is<br>
executed like with ":!<span class="Special">{cmd}</span>", any '!' is replaced with<br>
the previous command <a class="Identifier" href="various.html#:!">:!</a>.<br>
<br>
The default <span class="Special">[range]</span> for the ":w" command is the whole buffer (1,$). If you<br>
write the whole buffer, it is no longer considered changed. When you<br>
write it to a different file with ":w somefile" it depends on the "+" flag in<br>
<a class="Type" href="options.html#'cpoptions'">'cpoptions'</a>. When included, the write command will reset the <a class="Type" href="options.html#'modified'">'modified'</a> flag,<br>
even though the buffer itself may still be different from its file.<br>
<br>
If a file name is given with ":w" it becomes the alternate file. This can be<br>
used, for example, when the write fails and you want to try again later with<br>
":w #". This can be switched off by removing the 'A' flag from the<br>
<a class="Type" href="options.html#'cpoptions'">'cpoptions'</a> option.<br>
<br>
<a class="Constant" href="editing.html#:sav" name=":sav">:sav</a> <a class="Constant" href="editing.html#:saveas" name=":saveas">:saveas</a><br>
:sav[eas][!] <span class="Special">[++opt]</span> <span class="Special">{file}</span><br>
Save the current buffer under the name <span class="Special">{file}</span> and set<br>
the filename of the current buffer to <span class="Special">{file}</span>. The<br>
previous name is used for the alternate file name.<br>
The [!] is needed to overwrite an existing file.<br>
When <a class="Type" href="options.html#'filetype'">'filetype'</a> is empty filetype detection is done<br>
with the new name, before the file is written.<br>
When the write was successful <a class="Type" href="options.html#'readonly'">'readonly'</a> is reset.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:up" name=":up">:up</a> <a class="Constant" href="editing.html#:update" name=":update">:update</a><br>
:<span class="Special">[range]</span>up[date][!] <span class="Special">[++opt]</span> [>>] <span class="Special">[file]</span><br>
Like ":write", but only write when the buffer has been<br>
modified. <span class="Special">{not in Vi}</span><br>
<br>
<br>
<span class="Statement">WRITING WITH MULTIPLE BUFFERS </span><a class="Constant" href="editing.html#buffer-write" name="buffer-write">buffer-write</a><br>
<br>
<a class="Constant" href="editing.html#:wa" name=":wa">:wa</a> <a class="Constant" href="editing.html#:wall" name=":wall">:wall</a><br>
:wa[ll] Write all changed buffers. Buffers without a file<br>
name cause an error message. Buffers which are<br>
readonly are not written. <span class="Special">{not in Vi}</span><br>
<br>
:wa[ll]! Write all changed buffers, even the ones that are<br>
readonly. Buffers without a file name are not<br>
written and cause an error message. <span class="Special">{not in Vi}</span><br>
<br>
<br>
Vim will warn you if you try to overwrite a file that has been changed<br>
elsewhere. See <a class="Identifier" href="editing.html#timestamp">timestamp</a>.<br>
<br>
<a class="Constant" href="editing.html#backup" name="backup">backup</a> <a class="Constant" href="editing.html#E207" name="E207">E207</a> <a class="Constant" href="editing.html#E506" name="E506">E506</a> <a class="Constant" href="editing.html#E507" name="E507">E507</a> <a class="Constant" href="editing.html#E508" name="E508">E508</a> <a class="Constant" href="editing.html#E509" name="E509">E509</a> <a class="Constant" href="editing.html#E510" name="E510">E510</a><br>
If you write to an existing file (but do not append) while the <a class="Type" href="options.html#'backup'">'backup'</a>,<br>
<a class="Type" href="options.html#'writebackup'">'writebackup'</a> or <a class="Type" href="options.html#'patchmode'">'patchmode'</a> option is on, a backup of the original file is<br>
made. The file is either copied or renamed (see <a class="Type" href="options.html#'backupcopy'">'backupcopy'</a>). After the<br>
file has been successfully written and when the <a class="Type" href="options.html#'writebackup'">'writebackup'</a> option is on and<br>
the <a class="Type" href="options.html#'backup'">'backup'</a> option is off, the backup file is deleted. When the <a class="Type" href="options.html#'patchmode'">'patchmode'</a><br>
option is on the backup file may be renamed.<br>
<br>
<a class="Constant" href="editing.html#backup-table" name="backup-table">backup-table</a><br>
<span class="PreProc">'backup' 'writebackup' action</span><br>
off off no backup made<br>
off on backup current file, deleted afterwards (default)<br>
on off delete old backup, backup current file<br>
on on delete old backup, backup current file<br>
<br>
When the <a class="Type" href="options.html#'backupskip'">'backupskip'</a> pattern matches with the name of the file which is<br>
written, no backup file is made. The values of <a class="Type" href="options.html#'backup'">'backup'</a> and <a class="Type" href="options.html#'writebackup'">'writebackup'</a> are<br>
ignored then.<br>
<br>
When the <a class="Type" href="options.html#'backup'">'backup'</a> option is on, an old backup file (with the same name as the<br>
new backup file) will be deleted. If <a class="Type" href="options.html#'backup'">'backup'</a> is not set, but <a class="Type" href="options.html#'writebackup'">'writebackup'</a><br>
is set, an existing backup file will not be deleted. The backup file that is<br>
made while the file is being written will have a different name.<br>
<br>
On some filesystems it's possible that in a crash you lose both the backup and<br>
the newly written file (it might be there but contain bogus data). In that<br>
case try recovery, because the swap file is synced to disk and might still be<br>
there. <a class="Identifier" href="recover.html#:recover">:recover</a><br>
<br>
The directories given with the <a class="Type" href="options.html#'backupdir'">'backupdir'</a> option are used to put the backup<br>
file in. (default: same directory as the written file).<br>
<br>
Whether the backup is a new file, which is a copy of the original file, or the<br>
original file renamed depends on the <a class="Type" href="options.html#'backupcopy'">'backupcopy'</a> option. See there for an<br>
explanation of when the copy is made and when the file is renamed.<br>
<br>
If the creation of a backup file fails, the write is not done. If you want<br>
to write anyway add a '!' to the command.<br>
<br>
<a class="Constant" href="editing.html#write-permissions" name="write-permissions">write-permissions</a><br>
When writing a new file the permissions are read-write. For unix the mask is<br>
0666 with additionally umask applied. When writing a file that was read Vim<br>
will preserve the permissions, but clear the s-bit.<br>
<br>
<a class="Constant" href="editing.html#write-readonly" name="write-readonly">write-readonly</a><br>
When the <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a> option contains 'W', Vim will refuse to overwrite a<br>
readonly file. When 'W' is not present, ":w!" will overwrite a readonly file,<br>
if the system allows it (the directory must be writable).<br>
<br>
<a class="Constant" href="editing.html#write-fail" name="write-fail">write-fail</a><br>
If the writing of the new file fails, you have to be careful not to lose<br>
your changes AND the original file. If there is no backup file and writing<br>
the new file failed, you have already lost the original file! DON'T EXIT VIM<br>
UNTIL YOU WRITE OUT THE FILE! If a backup was made, it is put back in place<br>
of the original file (if possible). If you exit Vim, and lose the changes<br>
you made, the original file will mostly still be there. If putting back the<br>
original file fails, there will be an error message telling you that you<br>
lost the original file.<br>
<br>
<a class="Constant" href="editing.html#DOS-format-write" name="DOS-format-write">DOS-format-write</a><br>
If the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> is "dos", <span class="Special"><CR></span> <span class="Special"><NL></span> is used for <span class="Special"><EOL></span>. This is default<br>
for MS-DOS, Win32 and OS/2. On other systems the message "[dos format]" is<br>
shown to remind you that an unusual <span class="Special"><EOL></span> was used.<br>
<a class="Constant" href="editing.html#Unix-format-write" name="Unix-format-write">Unix-format-write</a><br>
If the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> is "unix", <span class="Special"><NL></span> is used for <span class="Special"><EOL></span>. On MS-DOS, Win32 and<br>
OS/2 the message "[unix format]" is shown.<br>
<a class="Constant" href="editing.html#Mac-format-write" name="Mac-format-write">Mac-format-write</a><br>
If the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> is "mac", <span class="Special"><CR></span> is used for <span class="Special"><EOL></span>. On non-Mac systems the<br>
message "[mac format]" is shown.<br>
<br>
See also <a class="Identifier" href="editing.html#file-formats">file-formats</a> and the <a class="Type" href="options.html#'fileformat'">'fileformat'</a> and <a class="Type" href="options.html#'fileformats'">'fileformats'</a> options.<br>
<br>
<a class="Constant" href="editing.html#ACL" name="ACL">ACL</a><br>
ACL stands for Access Control List. It is an advanced way to control access<br>
rights for a file. It is used on new MS-Windows and Unix systems, but only<br>
when the filesystem supports it.<br>
Vim attempts to preserve the ACL info when writing a file. The backup file<br>
will get the ACL info of the original file.<br>
The ACL info is also used to check if a file is read-only (when opening the<br>
file).<br>
<br>
<a class="Constant" href="editing.html#read-only-share" name="read-only-share">read-only-share</a><br>
When MS-Windows shares a drive on the network it can be marked as read-only.<br>
This means that even if the file read-only attribute is absent, and the ACL<br>
settings on NT network shared drives allow writing to the file, you can still<br>
not write to the file. Vim on Win32 platforms will detect read-only network<br>
drives and will mark the file as read-only. You will not be able to override<br>
it with <a class="Identifier" href="editing.html#:write">:write</a>.<br>
<br>
<a class="Constant" href="editing.html#write-device" name="write-device">write-device</a><br>
When the file name is actually a device name, Vim will not make a backup (that<br>
would be impossible). You need to use "!", since the device already exists.<br>
Example for Unix:<br>
<div class="helpExample"> :w! /dev/lpt0</div>
and for MS-DOS or MS-Windows:<br>
<div class="helpExample"> :w! lpt0</div>
For Unix a device is detected when the name doesn't refer to a normal file or<br>
a directory. A fifo or named pipe also looks like a device to Vim.<br>
For MS-DOS and MS-Windows the device is detected by its name:<br>
AUX<br>
CON<br>
CLOCK$<br>
NUL<br>
PRN<br>
COMn n=1,2,3... etc<br>
LPTn n=1,2,3... etc<br>
The names can be in upper- or lowercase.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
5. Writing and quitting <a class="Constant" href="editing.html#write-quit" name="write-quit">write-quit</a><br>
<br>
<a class="Constant" href="editing.html#:q" name=":q">:q</a> <a class="Constant" href="editing.html#:quit" name=":quit">:quit</a><br>
:q[uit] Quit the current window. Quit Vim if this is the last<br>
window. This fails when changes have been made and<br>
Vim refuses to <a class="Identifier" href="editing.html#abandon">abandon</a> the current buffer, and when<br>
the last file in the argument list has not been<br>
edited.<br>
If there are other tab pages and quitting the last<br>
window in the current tab page the current tab page is<br>
closed <a class="Identifier" href="tabpage.html#tab-page">tab-page</a>.<br>
Triggers the <a class="Identifier" href="autocmd.html#QuitPre">QuitPre</a> autocommand event.<br>
<br>
:conf[irm] q[uit] Quit, but give prompt when changes have been made, or<br>
the last file in the argument list has not been<br>
edited. See <a class="Identifier" href="editing.html#:confirm">:confirm</a> and <a class="Type" href="options.html#'confirm'">'confirm'</a>. <span class="Special">{not in Vi}</span><br>
<br>
:q[uit]! Quit without writing, also when the current buffer has<br>
changes. The buffer is unloaded, also when it has<br>
<a class="Type" href="options.html#'hidden'">'hidden'</a> set.<br>
If this is the last window and there is a modified<br>
hidden buffer, the current buffer is abandoned and the<br>
first changed hidden buffer becomes the current<br>
buffer.<br>
Use ":qall!" to exit always.<br>
<br>
:cq[uit] Quit always, without writing, and return an error<br>
code. See <a class="Identifier" href="quickfix.html#:cq">:cq</a>. Used for Manx's QuickFix mode (see<br>
<a class="Identifier" href="quickfix.html#quickfix">quickfix</a>). <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:wq" name=":wq">:wq</a><br>
:wq <span class="Special">[++opt]</span> Write the current file and quit. Writing fails when<br>
the file is read-only or the buffer does not have a<br>
name. Quitting fails when the last file in the<br>
argument list has not been edited.<br>
<br>
:wq! <span class="Special">[++opt]</span> Write the current file and quit. Writing fails when<br>
the current buffer does not have a name.<br>
<br>
:wq <span class="Special">[++opt]</span> <span class="Special">{file}</span> Write to <span class="Special">{file}</span> and quit. Quitting fails when the<br>
last file in the argument list has not been edited.<br>
<br>
:wq! <span class="Special">[++opt]</span> <span class="Special">{file}</span> Write to <span class="Special">{file}</span> and quit.<br>
<br>
:<span class="Special">[range]</span>wq[!] <span class="Special">[++opt]</span> <span class="Special">[file]</span><br>
Same as above, but only write the lines in <span class="Special">[range]</span>.<br>
<br>
<a class="Constant" href="editing.html#:x" name=":x">:x</a> <a class="Constant" href="editing.html#:xit" name=":xit">:xit</a><br>
:<span class="Special">[range]</span>x[it][!] <span class="Special">[++opt]</span> <span class="Special">[file]</span><br>
Like ":wq", but write only when changes have been<br>
made.<br>
When <a class="Type" href="options.html#'hidden'">'hidden'</a> is set and there are more windows, the<br>
current buffer becomes hidden, after writing the file.<br>
<br>
<a class="Constant" href="editing.html#:exi" name=":exi">:exi</a> <a class="Constant" href="editing.html#:exit" name=":exit">:exit</a><br>
:<span class="Special">[range]</span>exi[t][!] <span class="Special">[++opt]</span> <span class="Special">[file]</span><br>
Same as :xit.<br>
<br>
<a class="Constant" href="editing.html#ZZ" name="ZZ">ZZ</a><br>
ZZ Write current file, if modified, and quit (same as<br>
":x"). (<span class="Todo">Note</span>: If there are several windows for the<br>
current file, the file is written if it was modified<br>
and the window is closed).<br>
<br>
<a class="Constant" href="editing.html#ZQ" name="ZQ">ZQ</a><br>
ZQ Quit without checking for changes (same as ":q!").<br>
<span class="Special">{not in Vi}</span><br>
<br>
<span class="Statement">MULTIPLE WINDOWS AND BUFFERS </span><a class="Constant" href="editing.html#window-exit" name="window-exit">window-exit</a><br>
<br>
<a class="Constant" href="editing.html#:qa" name=":qa">:qa</a> <a class="Constant" href="editing.html#:qall" name=":qall">:qall</a><br>
:qa[ll] Exit Vim, unless there are some buffers which have been<br>
changed. (Use ":bmod" to go to the next modified buffer).<br>
When <a class="Type" href="options.html#'autowriteall'">'autowriteall'</a> is set all changed buffers will be<br>
written, like <a class="Identifier" href="editing.html#:wqall">:wqall</a>. <span class="Special">{not in Vi}</span><br>
<br>
:conf[irm] qa[ll]<br>
Exit Vim. Bring up a prompt when some buffers have been<br>
changed. See <a class="Identifier" href="editing.html#:confirm">:confirm</a>. <span class="Special">{not in Vi}</span><br>
<br>
:qa[ll]! Exit Vim. Any changes to buffers are lost. <span class="Special">{not in Vi}</span><br>
Also see <a class="Identifier" href="quickfix.html#:cquit">:cquit</a>, it does the same but exits with a non-zero<br>
value.<br>
<br>
<a class="Constant" href="editing.html#:quita" name=":quita">:quita</a> <a class="Constant" href="editing.html#:quitall" name=":quitall">:quitall</a><br>
:quita[ll][!] Same as ":qall". <span class="Special">{not in Vi}</span><br>
<br>
:wqa[ll] <span class="Special">[++opt]</span> <a class="Constant" href="editing.html#:wqa" name=":wqa">:wqa</a> <a class="Constant" href="editing.html#:wqall" name=":wqall">:wqall</a> <a class="Constant" href="editing.html#:xa" name=":xa">:xa</a> <a class="Constant" href="editing.html#:xall" name=":xall">:xall</a><br>
:xa[ll] Write all changed buffers and exit Vim. If there are buffers<br>
without a file name, which are readonly or which cannot be<br>
written for another reason, Vim will not quit. <span class="Special">{not in Vi}</span><br>
<br>
:conf[irm] wqa[ll] <span class="Special">[++opt]</span><br>
:conf[irm] xa[ll]<br>
Write all changed buffers and exit Vim. Bring up a prompt<br>
when some buffers are readonly or cannot be written for<br>
another reason. See <a class="Identifier" href="editing.html#:confirm">:confirm</a>. <span class="Special">{not in Vi}</span><br>
<br>
:wqa[ll]! <span class="Special">[++opt]</span><br>
:xa[ll]! Write all changed buffers, even the ones that are readonly,<br>
and exit Vim. If there are buffers without a file name or<br>
which cannot be written for another reason, Vim will not quit.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
6. Dialogs <a class="Constant" href="editing.html#edit-dialogs" name="edit-dialogs">edit-dialogs</a><br>
<br>
<a class="Constant" href="editing.html#:confirm" name=":confirm">:confirm</a> <a class="Constant" href="editing.html#:conf" name=":conf">:conf</a><br>
:conf[irm] <span class="Special">{command}</span> Execute <span class="Special">{command}</span>, and use a dialog when an<br>
operation has to be confirmed. Can be used on the<br>
<a class="Identifier" href="editing.html#:q">:q</a>, <a class="Identifier" href="editing.html#:qa">:qa</a> and <a class="Identifier" href="editing.html#:w">:w</a> commands (the latter to override<br>
a read-only setting), and any other command that can<br>
fail in such a way, such as <a class="Identifier" href="windows.html#:only">:only</a>, <a class="Identifier" href="windows.html#:buffer">:buffer</a>,<br>
<a class="Identifier" href="windows.html#:bdelete">:bdelete</a>, etc.<br>
<br>
Examples:<br>
<div class="helpExample"> :confirm w foo</div>
Will ask for confirmation when "foo" already exists.<br>
<div class="helpExample"> :confirm q</div>
Will ask for confirmation when there are changes.<br>
<div class="helpExample"> :confirm qa</div>
If any modified, unsaved buffers exist, you will be prompted to save<br>
or abandon each one. There are also choices to "save all" or "abandon<br>
all".<br>
<br>
If you want to always use ":confirm", set the <a class="Type" href="options.html#'confirm'">'confirm'</a> option.<br>
<br>
<a class="Constant" href="editing.html#:browse" name=":browse">:browse</a> <a class="Constant" href="editing.html#:bro" name=":bro">:bro</a> <a class="Constant" href="editing.html#E338" name="E338">E338</a> <a class="Constant" href="editing.html#E614" name="E614">E614</a> <a class="Constant" href="editing.html#E615" name="E615">E615</a> <a class="Constant" href="editing.html#E616" name="E616">E616</a><br>
:bro[wse] <span class="Special">{command}</span> Open a file selection dialog for an argument to<br>
<span class="Special">{command}</span>. At present this works for <a class="Identifier" href="editing.html#:e">:e</a>, <a class="Identifier" href="editing.html#:w">:w</a>,<br>
<a class="Identifier" href="editing.html#:wall">:wall</a>, <a class="Identifier" href="editing.html#:wq">:wq</a>, <a class="Identifier" href="editing.html#:wqall">:wqall</a>, <a class="Identifier" href="editing.html#:x">:x</a>, <a class="Identifier" href="editing.html#:xall">:xall</a>, <a class="Identifier" href="editing.html#:exit">:exit</a>,<br>
<a class="Identifier" href="editing.html#:view">:view</a>, <a class="Identifier" href="windows.html#:sview">:sview</a>, <a class="Identifier" href="insert.html#:r">:r</a>, <a class="Identifier" href="editing.html#:saveas">:saveas</a>, <a class="Identifier" href="windows.html#:sp">:sp</a>, <a class="Identifier" href="starting.html#:mkexrc">:mkexrc</a>,<br>
<a class="Identifier" href="starting.html#:mkvimrc">:mkvimrc</a>, <a class="Identifier" href="starting.html#:mksession">:mksession</a>, <a class="Identifier" href="starting.html#:mkview">:mkview</a>, <a class="Identifier" href="windows.html#:split">:split</a>,<br>
<a class="Identifier" href="windows.html#:vsplit">:vsplit</a>, <a class="Identifier" href="tabpage.html#:tabe">:tabe</a>, <a class="Identifier" href="tabpage.html#:tabnew">:tabnew</a>, <a class="Identifier" href="quickfix.html#:cfile">:cfile</a>, <a class="Identifier" href="quickfix.html#:cgetfile">:cgetfile</a>,<br>
<a class="Identifier" href="quickfix.html#:caddfile">:caddfile</a>, <a class="Identifier" href="quickfix.html#:lfile">:lfile</a>, <a class="Identifier" href="quickfix.html#:lgetfile">:lgetfile</a>, <a class="Identifier" href="quickfix.html#:laddfile">:laddfile</a>,<br>
<a class="Identifier" href="diff.html#:diffsplit">:diffsplit</a>, <a class="Identifier" href="diff.html#:diffpatch">:diffpatch</a>, <a class="Identifier" href="vi_diff.html#:open">:open</a>, <a class="Identifier" href="windows.html#:pedit">:pedit</a>,<br>
<a class="Identifier" href="various.html#:redir">:redir</a>, <a class="Identifier" href="repeat.html#:source">:source</a>, <a class="Identifier" href="editing.html#:update">:update</a>, <a class="Identifier" href="editing.html#:visual">:visual</a>, <a class="Identifier" href="windows.html#:vsplit">:vsplit</a>,<br>
and <a class="Identifier" href="editing.html#:qall">:qall</a> if <a class="Type" href="options.html#'confirm'">'confirm'</a> is set.<br>
<span class="Special">{only in Win32, Athena, Motif, GTK and Mac GUI}</span><br>
When ":browse" is not possible you get an error<br>
message. If the <a class="Identifier" href="various.html#+browse">+browse</a> feature is missing or the<br>
<span class="Special">{command}</span> doesn't support browsing, the <span class="Special">{command}</span> is<br>
executed without a dialog.<br>
":browse set" works like <a class="Identifier" href="options.html#:options">:options</a>.<br>
See also <a class="Identifier" href="starting.html#:oldfiles">:oldfiles</a> for ":browse oldfiles".<br>
<br>
The syntax is best shown via some examples:<br>
<div class="helpExample"> :browse e $vim/foo</div>
Open the browser in the $vim/foo directory, and edit the<br>
file chosen.<br>
<div class="helpExample"> :browse e</div>
Open the browser in the directory specified with <a class="Type" href="options.html#'browsedir'">'browsedir'</a>,<br>
and edit the file chosen.<br>
<div class="helpExample"> :browse w</div>
Open the browser in the directory of the current buffer,<br>
with the current buffer filename as default, and save the<br>
buffer under the filename chosen.<br>
<div class="helpExample"> :browse w C:/bar</div>
Open the browser in the C:/bar directory, with the current<br>
buffer filename as default, and save the buffer under the<br>
filename chosen.<br>
Also see the <a class="Identifier" href="options.html#'browsedir'">'browsedir'</a> option.<br>
For versions of Vim where browsing is not supported, the command is executed<br>
unmodified.<br>
<br>
<a class="Constant" href="editing.html#browsefilter" name="browsefilter">browsefilter</a><br>
For MS Windows and GTK, you can modify the filters that are used in the browse<br>
dialog. By setting the g:browsefilter or b:browsefilter variables, you can<br>
change the filters globally or locally to the buffer. The variable is set to<br>
a string in the format "{filter label}\t<span class="Special">{pattern}</span>;<span class="Special">{pattern}</span>\n" where {filter<br>
label} is the text that appears in the "Files of Type" comboBox, and <span class="Special">{pattern}</span><br>
is the pattern which filters the filenames. Several patterns can be given,<br>
separated by ';'.<br>
<br>
For Motif the same format is used, but only the very first pattern is actually<br>
used (Motif only offers one pattern, but you can edit it).<br>
<br>
For example, to have only Vim files in the dialog, you could use the following<br>
command:<br>
<br>
<div class="helpExample"> let g:browsefilter = "Vim Scripts\t*.vim\nVim Startup Files\t*vimrc\n"</div>
<br>
You can override the filter setting on a per-buffer basis by setting the<br>
b:browsefilter variable. You would most likely set b:browsefilter in a<br>
filetype plugin, so that the browse dialog would contain entries related to<br>
the type of file you are currently editing. Disadvantage: This makes it<br>
difficult to start editing a file of a different type. To overcome this, you<br>
may want to add "All Files\t*.*\n" as the final filter, so that the user can<br>
still access any desired file.<br>
<br>
To avoid setting browsefilter when Vim does not actually support it, you can<br>
use has("browsefilter"):<br>
<br>
<div class="helpExample"> if has("browsefilter")<br>
let g:browsefilter = "whatever"<br>
endif</div>
<br>
<span class="PreProc">==============================================================================</span><br>
7. The current directory <a class="Constant" href="editing.html#current-directory" name="current-directory">current-directory</a><br>
<br>
You may use the <a class="Identifier" href="editing.html#:cd">:cd</a> and <a class="Identifier" href="editing.html#:lcd">:lcd</a> commands to change to another directory, so<br>
you will not have to type that directory name in front of the file names. It<br>
also makes a difference for executing external commands, e.g. ":!ls".<br>
<br>
Changing directory fails when the current buffer is modified, the '.' flag is<br>
present in <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a> and "!" is not used in the command.<br>
<br>
<a class="Constant" href="editing.html#:cd" name=":cd">:cd</a> <a class="Constant" href="editing.html#E747" name="E747">E747</a> <a class="Constant" href="editing.html#E472" name="E472">E472</a><br>
:cd[!] On non-Unix systems: Print the current directory<br>
name. On Unix systems: Change the current directory<br>
to the home directory. Use <a class="Identifier" href="editing.html#:pwd">:pwd</a> to print the<br>
current directory on all systems.<br>
<br>
:cd[!] <span class="Special">{path}</span> Change the current directory to <span class="Special">{path}</span>.<br>
If <span class="Special">{path}</span> is relative, it is searched for in the<br>
directories listed in <a class="Identifier" href="options.html#'cdpath'">'cdpath'</a>.<br>
Does not change the meaning of an already opened file,<br>
because its full path name is remembered. Files from<br>
the <a class="Identifier" href="editing.html#arglist">arglist</a> may change though!<br>
On MS-DOS this also changes the active drive.<br>
To change to the directory of the current file:<br>
<div class="helpExample"> :cd %:h</div>
<br>
<a class="Constant" href="editing.html#:cd-" name=":cd-">:cd-</a> <a class="Constant" href="editing.html#E186" name="E186">E186</a><br>
:cd[!] - Change to the previous current directory (before the<br>
previous ":cd <span class="Special">{path}</span>" command). <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:chd" name=":chd">:chd</a> <a class="Constant" href="editing.html#:chdir" name=":chdir">:chdir</a><br>
:chd[ir][!] <span class="Special">[path]</span> Same as <a class="Identifier" href="editing.html#:cd">:cd</a>.<br>
<br>
<a class="Constant" href="editing.html#:lc" name=":lc">:lc</a> <a class="Constant" href="editing.html#:lcd" name=":lcd">:lcd</a><br>
:lc[d][!] <span class="Special">{path}</span> Like <a class="Identifier" href="editing.html#:cd">:cd</a>, but only set the current directory when<br>
the cursor is in the current window. The current<br>
directory for other windows is not changed, switching<br>
to another window will stop using <span class="Special">{path}</span>.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:lch" name=":lch">:lch</a> <a class="Constant" href="editing.html#:lchdir" name=":lchdir">:lchdir</a><br>
:lch[dir][!] Same as <a class="Identifier" href="editing.html#:lcd">:lcd</a>. <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="editing.html#:pw" name=":pw">:pw</a> <a class="Constant" href="editing.html#:pwd" name=":pwd">:pwd</a> <a class="Constant" href="editing.html#E187" name="E187">E187</a><br>
:pw[d] Print the current directory name. <span class="Special">{Vi: no pwd}</span><br>
Also see <a class="Identifier" href="eval.html#getcwd()">getcwd()</a>.<br>
<br>
So long as no <a class="Identifier" href="editing.html#:lcd">:lcd</a> command has been used, all windows share the same current<br>
directory. Using a command to jump to another window doesn't change anything<br>
for the current directory.<br>
When a <a class="Identifier" href="editing.html#:lcd">:lcd</a> command has been used for a window, the specified directory<br>
becomes the current directory for that window. Windows where the <a class="Identifier" href="editing.html#:lcd">:lcd</a><br>
command has not been used stick to the global current directory. When jumping<br>
to another window the current directory will become the last specified local<br>
current directory. If none was specified, the global current directory is<br>
used.<br>
When a <a class="Identifier" href="editing.html#:cd">:cd</a> command is used, the current window will lose his local current<br>
directory and will use the global current directory from now on.<br>
<br>
After using <a class="Identifier" href="editing.html#:cd">:cd</a> the full path name will be used for reading and writing<br>
files. On some networked file systems this may cause problems. The result of<br>
using the full path name is that the file names currently in use will remain<br>
referring to the same file. Example: If you have a file a:test and a<br>
directory a:vim the commands ":e test" ":cd vim" ":w" will overwrite the file<br>
a:test and not write a:vim/test. But if you do ":w test" the file a:vim/test<br>
will be written, because you gave a new file name and did not refer to a<br>
filename before the ":cd".<br>
<br>
<span class="PreProc">==============================================================================</span><br>
8. Editing binary files <a class="Constant" href="editing.html#edit-binary" name="edit-binary">edit-binary</a><br>
<br>
Although Vim was made to edit text files, it is possible to edit binary<br>
files. The <a class="Identifier" href="starting.html#-b">-b</a> Vim argument (b for binary) makes Vim do file I/O in binary<br>
mode, and sets some options for editing binary files (<a class="Type" href="options.html#'binary'">'binary'</a> on, <a class="Type" href="options.html#'textwidth'">'textwidth'</a><br>
to 0, <a class="Type" href="options.html#'modeline'">'modeline'</a> off, <a class="Type" href="options.html#'expandtab'">'expandtab'</a> off). Setting the <a class="Type" href="options.html#'binary'">'binary'</a> option has the<br>
same effect. Don't forget to do this before reading the file.<br>
<br>
There are a few things to remember when editing binary files:<br>
- When editing executable files the number of characters must not change.<br>
Use only the "R" or "r" command to change text. Do not delete characters<br>
with "x" or by backspacing.<br>
- Set the <a class="Type" href="options.html#'textwidth'">'textwidth'</a> option to 0. Otherwise lines will unexpectedly be<br>
split in two.<br>
- When there are not many <span class="Special"><EOL></span>s, the lines will become very long. If you<br>
want to edit a line that does not fit on the screen reset the <a class="Type" href="options.html#'wrap'">'wrap'</a> option.<br>
Horizontal scrolling is used then. If a line becomes too long (more than<br>
about 32767 characters on the Amiga, much more on 32-bit systems, see<br>
<a class="Identifier" href="vi_diff.html#limits">limits</a>) you cannot edit that line. The line will be split when reading<br>
the file. It is also possible that you get an "out of memory" error when<br>
reading the file.<br>
- Make sure the <a class="Type" href="options.html#'binary'">'binary'</a> option is set BEFORE loading the<br>
file. Otherwise both <span class="Special"><CR></span> <span class="Special"><NL></span> and <span class="Special"><NL></span> are considered to end a line<br>
and when the file is written the <span class="Special"><NL></span> will be replaced with <span class="Special"><CR></span> <span class="Special"><NL></span>.<br>
- <span class="Special"><Nul></span> characters are shown on the screen as ^@. You can enter them with<br>
"<span class="Special">CTRL-V</span> <span class="Special">CTRL-@</span>" or "<span class="Special">CTRL-V</span> 000" <span class="Special">{Vi cannot handle <Nul> characters in the</span><br>
<span class="Special">file}</span><br>
- To insert a <span class="Special"><NL></span> character in the file split a line. When writing the<br>
buffer to a file a <span class="Special"><NL></span> will be written for the <span class="Special"><EOL></span>.<br>
- Vim normally appends an <span class="Special"><EOL></span> at the end of the file if there is none.<br>
Setting the <a class="Type" href="options.html#'binary'">'binary'</a> option prevents this. If you want to add the final<br>
<span class="Special"><EOL></span>, set the <a class="Type" href="options.html#'endofline'">'endofline'</a> option. You can also read the value of this<br>
option to see if there was an <span class="Special"><EOL></span> for the last line (you cannot see this<br>
in the text).<br>
<br>
<span class="PreProc">==============================================================================</span><br>
9. Encryption <a class="Constant" href="editing.html#encryption" name="encryption">encryption</a><br>
<br>
Vim is able to write files encrypted, and read them back. The encrypted text<br>
cannot be read without the right key.<br>
<span class="Special">{only available when compiled with the </span><a class="Identifier" href="various.html#+cryptv">+cryptv</a><span class="Special"> feature}</span> <a class="Constant" href="editing.html#E833" name="E833">E833</a><br>
<br>
The text in the swap file and the undo file is also encrypted. <a class="Constant" href="editing.html#E843" name="E843">E843</a><br>
However, this is done block-by-block and may reduce the time needed to crack a<br>
password. You can disable the swap file, but then a crash will cause you to<br>
lose your work. The undo file can be disabled without much disadvantage.<br>
<div class="helpExample"> :set noundofile<br>
:noswapfile edit secrets</div>
<br>
<span class="Todo">Note</span>: The text in memory is not encrypted. A system administrator may be able<br>
to see your text while you are editing it. When filtering text with<br>
":!filter" or using ":w !command" the text is also not encrypted, this may<br>
reveal it to others. The <a class="Type" href="options.html#'viminfo'">'viminfo'</a> file is not encrypted.<br>
<br>
You could do this to edit very secret text:<br>
<div class="helpExample"> :set noundofile viminfo=<br>
:noswapfile edit secrets.txt</div>
Keep in mind that without a swap file you risk losing your work in the event<br>
of a crash or a power failure.<br>
<br>
WARNING: If you make a typo when entering the key and then write the file and<br>
exit, the text will be lost!<br>
<br>
The normal way to work with encryption, is to use the ":X" command, which will<br>
ask you to enter a key. A following write command will use that key to<br>
encrypt the file. If you later edit the same file, Vim will ask you to enter<br>
a key. If you type the same key as that was used for writing, the text will<br>
be readable again. If you use a wrong key, it will be a mess.<br>
<br>
<a class="Constant" href="editing.html#:X" name=":X">:X</a><br>
:X Prompt for an encryption key. The typing is done without showing the<br>
actual text, so that someone looking at the display won't see it.<br>
The typed key is stored in the <a class="Type" href="options.html#'key'">'key'</a> option, which is used to encrypt<br>
the file when it is written. The file will remain unchanged until you<br>
write it. See also <a class="Identifier" href="starting.html#-x">-x</a>.<br>
<br>
The value of the <a class="Type" href="options.html#'key'">'key'</a> options is used when text is written. When the option<br>
is not empty, the written file will be encrypted, using the value as the<br>
encryption key. A magic number is prepended, so that Vim can recognize that<br>
the file is encrypted.<br>
<br>
To disable the encryption, reset the <a class="Type" href="options.html#'key'">'key'</a> option to an empty value:<br>
<div class="helpExample"> :set key=</div>
<br>
You can use the <a class="Type" href="options.html#'cryptmethod'">'cryptmethod'</a> option to select the type of encryption, use one<br>
of these:<br>
<div class="helpExample"> :setlocal cm=zip " weak method, backwards compatible<br>
:setlocal cm=blowfish " method with flaws<br>
:setlocal cm=blowfish2 " medium strong method</div>
<br>
Do this before writing the file. When reading an encrypted file it will be<br>
set automatically to the method used when that file was written. You can<br>
change <a class="Type" href="options.html#'cryptmethod'">'cryptmethod'</a> before writing that file to change the method.<br>
<br>
To set the default method, used for new files, use this in your <a class="Identifier" href="starting.html#vimrc">vimrc</a> <br>
file:<br>
<div class="helpExample"> set cm=blowfish2</div>
Using "blowfish2" is highly recommended. Only use another method if you<br>
must use an older Vim version that does not support it.<br>
<br>
The message given for reading and writing a file will show "[crypted]" when<br>
using zip, "[blowfish]" when using blowfish, etc.<br>
<br>
When writing an undo file, the same key and method will be used for the text<br>
in the undo file. <a class="Identifier" href="undo.html#persistent-undo">persistent-undo</a>.<br>
<br>
To test for blowfish support you can use these conditions:<br>
<div class="helpExample"> has('crypt-blowfish')<br>
has('crypt-blowfish2')</div>
This works since Vim 7.4.1099 while blowfish support was added earlier.<br>
Thus the condition failing doesn't mean blowfish is not supported. You can<br>
test for blowfish with:<br>
<div class="helpExample"> v:version >= 703</div>
And for blowfish2 with:<br>
<div class="helpExample"> v:version > 704 || (v:version == 704 && has('patch401'))</div>
If you are sure Vim includes patch 7.4.237 a simpler check is:<br>
<div class="helpExample"> has('patch-7.4.401')</div>
<br>
<a class="Constant" href="editing.html#E817" name="E817">E817</a> <a class="Constant" href="editing.html#E818" name="E818">E818</a> <a class="Constant" href="editing.html#E819" name="E819">E819</a> <a class="Constant" href="editing.html#E820" name="E820">E820</a><br>
When encryption does not work properly, you would be able to write your text<br>
to a file and never be able to read it back. Therefore a test is performed to<br>
check if the encryption works as expected. If you get one of these errors<br>
don't write the file encrypted! You need to rebuild the Vim binary to fix<br>
this.<br>
<br>
<a class="Constant" href="editing.html#E831" name="E831">E831</a> This is an internal error, "cannot happen". If you can reproduce it,<br>
please report to the developers.<br>
<br>
When reading a file that has been encrypted and the <a class="Type" href="options.html#'key'">'key'</a> option is not empty,<br>
it will be used for decryption. If the value is empty, you will be prompted<br>
to enter the key. If you don't enter a key, or you enter the wrong key, the<br>
file is edited without being decrypted. There is no warning about using the<br>
wrong key (this makes brute force methods to find the key more difficult).<br>
<br>
If want to start reading a file that uses a different key, set the <a class="Type" href="options.html#'key'">'key'</a><br>
option to an empty string, so that Vim will prompt for a new one. Don't use<br>
the ":set" command to enter the value, other people can read the command over<br>
your shoulder.<br>
<br>
Since the value of the <a class="Type" href="options.html#'key'">'key'</a> option is supposed to be a secret, its value can<br>
never be viewed. You should not set this option in a vimrc file.<br>
<br>
An encrypted file can be recognized by the "file" command, if you add these<br>
lines to "/etc/magic", "/usr/share/misc/magic" or wherever your system has the<br>
"magic" file:<br>
<div class="helpExample"> 0 string VimCrypt~ Vim encrypted file<br>
>9 string 01 - "zip" cryptmethod<br>
>9 string 02 - "blowfish" cryptmethod<br>
>9 string 03 - "blowfish2" cryptmethod</div>
<br>
<span class="Todo">Notes</span>:<br>
- Encryption is not possible when doing conversion with <a class="Type" href="options.html#'charconvert'">'charconvert'</a>.<br>
- Text you copy or delete goes to the numbered registers. The registers can<br>
be saved in the .viminfo file, where they could be read. Change your<br>
<a class="Type" href="options.html#'viminfo'">'viminfo'</a> option to be safe.<br>
- Someone can type commands in Vim when you walk away for a moment, he should<br>
not be able to get the key.<br>
- If you make a typing mistake when entering the key, you might not be able to<br>
get your text back!<br>
- If you type the key with a ":set key=value" command, it can be kept in the<br>
history, showing the <a class="Type" href="options.html#'key'">'key'</a> value in a viminfo file.<br>
- There is never 100% safety. The encryption in Vim has not been tested for<br>
robustness.<br>
- The algorithm used for <a class="Type" href="options.html#'cryptmethod'">'cryptmethod'</a> "zip" is breakable. A 4 character key<br>
in about one hour, a 6 character key in one day (on a Pentium 133 PC). This<br>
requires that you know some text that must appear in the file. An expert<br>
can break it for any key. When the text has been decrypted, this also means<br>
that the key can be revealed, and other files encrypted with the same key<br>
can be decrypted.<br>
- Pkzip uses the same encryption as <a class="Type" href="options.html#'cryptmethod'">'cryptmethod'</a> "zip", and US Govt has no<br>
objection to its export. Pkzip's public file APPNOTE.TXT describes this<br>
algorithm in detail.<br>
- The implementation of <a class="Type" href="options.html#'cryptmethod'">'cryptmethod'</a> "blowfish" has a flaw. It is possible<br>
to crack the first 64 bytes of a file and in some circumstances more of the<br>
file. Use of it is not recommended, but it's still the strongest method<br>
supported by Vim 7.3 and 7.4. The "zip" method is even weaker.<br>
- Vim originates from the Netherlands. That is where the sources come from.<br>
Thus the encryption code is not exported from the USA.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
10. Timestamps <a class="Constant" href="editing.html#timestamp" name="timestamp">timestamp</a> <a class="Constant" href="editing.html#timestamps" name="timestamps">timestamps</a><br>
<br>
Vim remembers the modification timestamp, mode and size of a file when you<br>
begin editing it. This is used to avoid that you have two different versions<br>
of the same file (without you knowing this).<br>
<br>
After a shell command is run (<a class="Identifier" href="various.html#:!cmd">:!cmd</a> <a class="Identifier" href="starting.html#suspend">suspend</a> <a class="Identifier" href="insert.html#:read!">:read!</a> <a class="Identifier" href="various.html#K">K</a>) timestamps,<br>
file modes and file sizes are compared for all buffers in a window. Vim will<br>
run any associated <a class="Identifier" href="autocmd.html#FileChangedShell">FileChangedShell</a> autocommands or display a warning for<br>
any files that have changed. In the GUI this happens when Vim regains input<br>
focus.<br>
<br>
<a class="Constant" href="editing.html#E321" name="E321">E321</a> <a class="Constant" href="editing.html#E462" name="E462">E462</a><br>
If you want to automatically reload a file when it has been changed outside of<br>
Vim, set the <a class="Type" href="options.html#'autoread'">'autoread'</a> option. This doesn't work at the moment you write the<br>
file though, only when the file wasn't changed inside of Vim.<br>
<br>
If you do not want to be asked or automatically reload the file, you can use<br>
this:<br>
<div class="helpExample"> set buftype=nofile</div>
<br>
Or, when starting gvim from a shell:<br>
<div class="helpExample"> gvim file.log -c "set buftype=nofile"</div>
<br>
<span class="Todo">Note</span> that if a FileChangedShell autocommand is defined you will not get a<br>
warning message or prompt. The autocommand is expected to handle this.<br>
<br>
There is no warning for a directory (e.g., with <a class="Identifier" href="pi_netrw.html#netrw-browse">netrw-browse</a>). But you do<br>
get warned if you started editing a new file and it was created as a directory<br>
later.<br>
<br>
When Vim notices the timestamp of a file has changed, and the file is being<br>
edited in a buffer but has not changed, Vim checks if the contents of the file<br>
is equal. This is done by reading the file again (into a hidden buffer, which<br>
is immediately deleted again) and comparing the text. If the text is equal,<br>
you will get no warning.<br>
<br>
If you don't get warned often enough you can use the following command.<br>
<br>
<a class="Constant" href="editing.html#:checkt" name=":checkt">:checkt</a> <a class="Constant" href="editing.html#:checktime" name=":checktime">:checktime</a><br>
:checkt[ime] Check if any buffers were changed outside of Vim.<br>
This checks and warns you if you would end up with two<br>
versions of a file.<br>
If this is called from an autocommand, a ":global"<br>
command or is not typed the actual check is postponed<br>
until a moment the side effects (reloading the file)<br>
would be harmless.<br>
Each loaded buffer is checked for its associated file<br>
being changed. If the file was changed Vim will take<br>
action. If there are no changes in the buffer and<br>
<a class="Type" href="options.html#'autoread'">'autoread'</a> is set, the buffer is reloaded. Otherwise,<br>
you are offered the choice of reloading the file. If<br>
the file was deleted you get an error message.<br>
If the file previously didn't exist you get a warning<br>
if it exists now.<br>
Once a file has been checked the timestamp is reset,<br>
you will not be warned again.<br>
<br>
:<span class="Special">[N]</span>checkt[ime] <span class="Special">{filename}</span><br>
:<span class="Special">[N]</span>checkt[ime] <span class="Special">[N]</span><br>
Check the timestamp of a specific buffer. The buffer<br>
may be specified by name, number or with a pattern.<br>
<br>
<br>
<a class="Constant" href="editing.html#E813" name="E813">E813</a> <a class="Constant" href="editing.html#E814" name="E814">E814</a><br>
Vim will reload the buffer if you chose to. If a window is visible that<br>
contains this buffer, the reloading will happen in the context of this window.<br>
Otherwise a special window is used, so that most autocommands will work. You<br>
can't close this window. A few other restrictions apply. Best is to make<br>
sure nothing happens outside of the current buffer. E.g., setting<br>
window-local options may end up in the wrong window. Splitting the window,<br>
doing something there and closing it should be OK (if there are no side<br>
effects from other autocommands). Closing unrelated windows and buffers will<br>
get you into trouble.<br>
<br>
Before writing a file the timestamp is checked. If it has changed, Vim will<br>
ask if you really want to overwrite the file:<br>
<br>
WARNING: The file has been changed since reading it!!!<br>
Do you really want to write to it (y/n)?<br>
<br>
If you hit 'y' Vim will continue writing the file. If you hit 'n' the write is<br>
aborted. If you used ":wq" or "ZZ" Vim will not exit, you will get another<br>
chance to write the file.<br>
<br>
The message would normally mean that somebody has written to the file after<br>
the edit session started. This could be another person, in which case you<br>
probably want to check if your changes to the file and the changes from the<br>
other person should be merged. Write the file under another name and check for<br>
differences (the "diff" program can be used for this).<br>
<br>
It is also possible that you modified the file yourself, from another edit<br>
session or with another command (e.g., a filter command). Then you will know<br>
which version of the file you want to keep.<br>
<br>
There is one situation where you get the message while there is nothing wrong:<br>
On a Win32 system on the day daylight saving time starts. There is something<br>
in the Win32 libraries that confuses Vim about the hour time difference. The<br>
problem goes away the next day.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
11. File Searching <a class="Constant" href="editing.html#file-searching" name="file-searching">file-searching</a><br>
<br>
<span class="Special">{not available when compiled without the </span><a class="Identifier" href="various.html#+path_extra">+path_extra</a><span class="Special"> feature}</span><br>
<br>
The file searching is currently used for the <a class="Type" href="options.html#'path'">'path'</a>, <a class="Type" href="options.html#'cdpath'">'cdpath'</a> and <a class="Type" href="options.html#'tags'">'tags'</a><br>
options, for <a class="Identifier" href="eval.html#finddir()">finddir()</a> and <a class="Identifier" href="eval.html#findfile()">findfile()</a>. Other commands use <a class="Identifier" href="editing.html#wildcards">wildcards</a><br>
which is slightly different.<br>
<br>
There are three different types of searching:<br>
<br>
1) Downward search: <a class="Constant" href="editing.html#starstar" name="starstar">starstar</a><br>
Downward search uses the wildcards '*', '**' and possibly others<br>
supported by your operating system. '*' and '**' are handled inside Vim,<br>
so they work on all operating systems. <span class="Todo">Note</span> that "**" only acts as a<br>
special wildcard when it is at the start of a name.<br>
<br>
The usage of '*' is quite simple: It matches 0 or more characters. In a<br>
search pattern this would be ".*". <span class="Todo">Note</span> that the "." is not used for file<br>
searching.<br>
<br>
'**' is more sophisticated:<br>
- It ONLY matches directories.<br>
- It matches up to 30 directories deep by default, so you can use it to<br>
search an entire directory tree<br>
- The maximum number of levels matched can be given by appending a number<br>
to '**'.<br>
Thus '/usr/**2' can match:<br>
<div class="helpExample"> /usr<br>
/usr/include<br>
/usr/include/sys<br>
/usr/include/g++<br>
/usr/lib<br>
/usr/lib/X11<br>
....</div>
It does NOT match '/usr/include/g++/std' as this would be three<br>
levels.<br>
The allowed number range is 0 ('**0' is removed) to 100<br>
If the given number is smaller than 0 it defaults to 30, if it's<br>
bigger than 100 then 100 is used. The system also has a limit on the<br>
path length, usually 256 or 1024 bytes.<br>
- '**' can only be at the end of the path or be followed by a path<br>
separator or by a number and a path separator.<br>
<br>
You can combine '*' and '**' in any order:<br>
<div class="helpExample"> /usr/**/sys/*<br>
/usr/*tory/sys/**<br>
/usr/**2/sys/*</div>
<br>
2) Upward search:<br>
Here you can give a directory and then search the directory tree upward for<br>
a file. You could give stop-directories to limit the upward search. The<br>
stop-directories are appended to the path (for the <a class="Type" href="options.html#'path'">'path'</a> option) or to<br>
the filename (for the <a class="Type" href="options.html#'tags'">'tags'</a> option) with a ';'. If you want several<br>
stop-directories separate them with ';'. If you want no stop-directory<br>
("search upward till the root directory) just use ';'.<br>
<div class="helpExample"> /usr/include/sys;/usr</div>
will search in:<br>
<div class="helpExample"> /usr/include/sys<br>
/usr/include<br>
/usr</div>
<br>
If you use a relative path the upward search is started in Vim's current<br>
directory or in the directory of the current file (if the relative path<br>
starts with './' and 'd' is not included in <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a>).<br>
<br>
If Vim's current path is /u/user_x/work/release and you do<br>
<div class="helpExample"> :set path=include;/u/user_x</div>
and then search for a file with <a class="Identifier" href="editing.html#gf">gf</a> the file is searched in:<br>
<div class="helpExample"> /u/user_x/work/release/include<br>
/u/user_x/work/include<br>
/u/user_x/include</div>
<br>
3) Combined up/downward search:<br>
If Vim's current path is /u/user_x/work/release and you do<br>
<div class="helpExample"> set path=**;/u/user_x</div>
and then search for a file with <a class="Identifier" href="editing.html#gf">gf</a> the file is searched in:<br>
<div class="helpExample"> /u/user_x/work/release/**<br>
/u/user_x/work/**<br>
/u/user_x/**</div>
<br>
BE CAREFUL! This might consume a lot of time, as the search of<br>
'/u/user_x/**' includes '/u/user_x/work/**' and<br>
'/u/user_x/work/release/**'. So '/u/user_x/work/release/**' is searched<br>
three times and '/u/user_x/work/**' is searched twice.<br>
<br>
In the above example you might want to set path to:<br>
<div class="helpExample"> :set path=**,/u/user_x/**</div>
This searches:<br>
<span class="PreProc">/u/user_x/work/release/**</span><br>
<span class="PreProc">/u/user_x/**</span><br>
This searches the same directories, but in a different order.<br>
<br>
<span class="Todo">Note</span> that completion for ":find", ":sfind", and ":tabfind" commands do not<br>
currently work with <a class="Type" href="options.html#'path'">'path'</a> items that contain a URL or use the double star<br>
with depth limiter (/usr/**2) or upward search (;) notations.<br>
<br>
vim:tw=78:ts=8:ft=help:norl:<br>
</div>
</article>
<footer>
<a href="#top">Return to the top</a> - <a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
<br />
<div style="text-align:right;">
Hosted by <a href="https://github.com/vim-jp/vimdoc-en">vimdoc-en project</a><br />
If you met any problem, please report it to <a href="https://github.com/vim-jp/vimdoc-en/issues">issue</a>.<br />
</div>
</footer>
<!--<script src="js/check-referrer.js" type="text/javascript"></script>-->
</body>
</html>
<!-- vim:set ts=8 sts=2 sw=2 tw=0 et: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。