代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_02 - 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>
/ usr_02<br />
<a name="top"></a><h1>usr_02 - 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="usr_02.html" name="usr_02.txt">usr_02.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2017 Mar 14<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
The first steps in Vim<br>
<br>
<br>
This chapter provides just enough information to edit a file with Vim. Not<br>
well or fast, but you can edit. Take some time to practice with these<br>
commands, they form the base for what follows.<br>
<br>
<a class="Identifier" href="usr_02.html#02.1">02.1</a> Running Vim for the First Time<br>
<a class="Identifier" href="usr_02.html#02.2">02.2</a> Inserting text<br>
<a class="Identifier" href="usr_02.html#02.3">02.3</a> Moving around<br>
<a class="Identifier" href="usr_02.html#02.4">02.4</a> Deleting characters<br>
<a class="Identifier" href="usr_02.html#02.5">02.5</a> Undo and Redo<br>
<a class="Identifier" href="usr_02.html#02.6">02.6</a> Other editing commands<br>
<a class="Identifier" href="usr_02.html#02.7">02.7</a> Getting out<br>
<a class="Identifier" href="usr_02.html#02.8">02.8</a> Finding help<br>
<br>
Next chapter: <a class="Identifier" href="usr_03.html">usr_03.txt</a> Moving around<br>
Previous chapter: <a class="Identifier" href="usr_01.html">usr_01.txt</a> About the manuals<br>
Table of contents: <a class="Identifier" href="usr_toc.html">usr_toc.txt</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_02.html#02.1" name="02.1">02.1</a> Running Vim for the First Time<br>
<br>
To start Vim, enter this command:<br>
<br>
<div class="helpExample"> gvim file.txt</div>
<br>
In UNIX you can type this at any command prompt. If you are running Microsoft<br>
Windows, open an MS-DOS prompt window and enter the command.<br>
In either case, Vim starts editing a file called file.txt. Because this<br>
is a new file, you get a blank window. This is what your screen will look<br>
like:<br>
<br>
+---------------------------------------+<br>
|# |<br>
|~ |<br>
|~ |<br>
|~ |<br>
|~ |<br>
|"file.txt" [New file] |<br>
+---------------------------------------+<br>
('#" is the cursor position.)<br>
<br>
The tilde (~) lines indicate lines not in the file. In other words, when Vim<br>
runs out of file to display, it displays tilde lines. At the bottom of the<br>
screen, a message line indicates the file is named file.txt and shows that you<br>
are creating a new file. The message information is temporary and other<br>
information overwrites it.<br>
<br>
<br>
THE VIM COMMAND<br>
<br>
The gvim command causes the editor to create a new window for editing. If you<br>
use this command:<br>
<br>
<div class="helpExample"> vim file.txt</div>
<br>
the editing occurs inside your command window. In other words, if you are<br>
running inside an xterm, the editor uses your xterm window. If you are using<br>
an MS-DOS command prompt window under Microsoft Windows, the editing occurs<br>
inside this window. The text in the window will look the same for both<br>
versions, but with gvim you have extra features, like a menu bar. More about<br>
that later.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_02.html#02.2" name="02.2">02.2</a> Inserting text<br>
<br>
The Vim editor is a modal editor. That means that the editor behaves<br>
differently, depending on which mode you are in. The two basic modes are<br>
called Normal mode and Insert mode. In Normal mode the characters you type<br>
are commands. In Insert mode the characters are inserted as text.<br>
Since you have just started Vim it will be in Normal mode. To start Insert<br>
mode you type the "i" command (i for Insert). Then you can enter<br>
the text. It will be inserted into the file. Do not worry if you make<br>
mistakes; you can correct them later. To enter the following programmer's<br>
limerick, this is what you type:<br>
<br>
<div class="helpExample"> iA very intelligent turtle<br>
Found programming UNIX a hurdle</div>
<br>
After typing "turtle" you press the <span class="Special"><Enter></span> key to start a new line. Finally<br>
you press the <span class="Special"><Esc></span> key to stop Insert mode and go back to Normal mode. You<br>
now have two lines of text in your Vim window:<br>
<br>
+---------------------------------------+<br>
|A very intelligent turtle |<br>
|Found programming UNIX a hurdle |<br>
|~ |<br>
|~ |<br>
| |<br>
+---------------------------------------+<br>
<br>
<br>
WHAT IS THE MODE?<br>
<br>
To be able to see what mode you are in, type this command:<br>
<br>
<div class="helpExample"> :set showmode</div>
<br>
You will notice that when typing the colon Vim moves the cursor to the last<br>
line of the window. That's where you type colon commands (commands that start<br>
with a colon). Finish this command by pressing the <span class="Special"><Enter></span> key (all commands<br>
that start with a colon are finished this way).<br>
Now, if you type the "i" command Vim will display --INSERT-- at the bottom<br>
of the window. This indicates you are in Insert mode.<br>
<br>
+---------------------------------------+<br>
|A very intelligent turtle |<br>
|Found programming UNIX a hurdle |<br>
|~ |<br>
|~ |<br>
|-- INSERT -- |<br>
+---------------------------------------+<br>
<br>
If you press <span class="Special"><Esc></span> to go back to Normal mode the last line will be made blank.<br>
<br>
<br>
GETTING OUT OF TROUBLE<br>
<br>
One of the problems for Vim novices is mode confusion, which is caused by<br>
forgetting which mode you are in or by accidentally typing a command that<br>
switches modes. To get back to Normal mode, no matter what mode you are in,<br>
press the <span class="Special"><Esc></span> key. Sometimes you have to press it twice. If Vim beeps back<br>
at you, you already are in Normal mode.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_02.html#02.3" name="02.3">02.3</a> Moving around<br>
<br>
After you return to Normal mode, you can move around by using these keys:<br>
<br>
h left <a class="Constant" href="usr_02.html#hjkl" name="hjkl">hjkl</a><br>
j down<br>
k up<br>
l right<br>
<br>
At first, it may appear that these commands were chosen at random. After all,<br>
who ever heard of using l for right? But actually, there is a very good<br>
reason for these choices: Moving the cursor is the most common thing you do in<br>
an editor, and these keys are on the home row of your right hand. In other<br>
words, these commands are placed where you can type them the fastest<br>
(especially when you type with ten fingers).<br>
<br>
<span class="Todo">Note</span>:<br>
You can also move the cursor by using the arrow keys. If you do,<br>
however, you greatly slow down your editing because to press the arrow<br>
keys, you must move your hand from the text keys to the arrow keys.<br>
Considering that you might be doing it hundreds of times an hour, this<br>
can take a significant amount of time.<br>
Also, there are keyboards which do not have arrow keys, or which<br>
locate them in unusual places; therefore, knowing the use of the hjkl<br>
keys helps in those situations.<br>
<br>
One way to remember these commands is that h is on the left, l is on the<br>
right and j points down. In a picture:<br>
<br>
<div class="helpExample"> k<br>
h l<br>
j</div>
<br>
The best way to learn these commands is by using them. Use the "i" command to<br>
insert some more lines of text. Then use the hjkl keys to move around and<br>
insert a word somewhere. Don't forget to press <span class="Special"><Esc></span> to go back to Normal<br>
mode. The <a class="Identifier" href="usr_01.html#vimtutor">vimtutor</a> is also a nice way to learn by doing.<br>
<br>
For Japanese users, Hiroshi Iwatani suggested using this:<br>
<br>
Komsomolsk<br>
^<br>
|<br>
Huan Ho <--- ---> Los Angeles<br>
(Yellow river) |<br>
v<br>
Java (the island, not the programming language)<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_02.html#02.4" name="02.4">02.4</a> Deleting characters<br>
<br>
To delete a character, move the cursor over it and type "x". (This is a<br>
throwback to the old days of the typewriter, when you deleted things by typing<br>
xxxx over them.) Move the cursor to the beginning of the first line, for<br>
example, and type xxxxxxx (seven x's) to delete "A very ". The result should<br>
look like this:<br>
<br>
+---------------------------------------+<br>
|intelligent turtle |<br>
|Found programming UNIX a hurdle |<br>
|~ |<br>
|~ |<br>
| |<br>
+---------------------------------------+<br>
<br>
Now you can insert new text, for example by typing:<br>
<br>
<div class="helpExample"> iA young <Esc></div>
<br>
This begins an insert (the i), inserts the words "A young", and then exits<br>
insert mode (the final <span class="Special"><Esc></span>). The result:<br>
<br>
+---------------------------------------+<br>
|A young intelligent turtle |<br>
|Found programming UNIX a hurdle |<br>
|~ |<br>
|~ |<br>
| |<br>
+---------------------------------------+<br>
<br>
<br>
DELETING A LINE<br>
<br>
To delete a whole line use the "dd" command. The following line will<br>
then move up to fill the gap:<br>
<br>
+---------------------------------------+<br>
|Found programming UNIX a hurdle |<br>
|~ |<br>
|~ |<br>
|~ |<br>
| |<br>
+---------------------------------------+<br>
<br>
<br>
DELETING A LINE BREAK<br>
<br>
In Vim you can join two lines together, which means that the line break<br>
between them is deleted. The "J" command does this.<br>
Take these two lines:<br>
<br>
<span class="PreProc">A young intelligent</span><br>
<span class="PreProc">turtle</span><br>
<br>
Move the cursor to the first line and press "J":<br>
<br>
<span class="PreProc">A young intelligent turtle</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_02.html#02.5" name="02.5">02.5</a> Undo and Redo<br>
<br>
Suppose you delete too much. Well, you can type it in again, but an easier<br>
way exists. The "u" command undoes the last edit. Take a look at this in<br>
action: After using "dd" to delete the first line, "u" brings it back.<br>
Another one: Move the cursor to the A in the first line:<br>
<br>
<span class="PreProc">A young intelligent turtle</span><br>
<br>
Now type xxxxxxx to delete "A young". The result is as follows:<br>
<br>
<span class="PreProc">intelligent turtle</span><br>
<br>
Type "u" to undo the last delete. That delete removed the g, so the undo<br>
restores the character.<br>
<br>
<span class="PreProc">g intelligent turtle</span><br>
<br>
The next u command restores the next-to-last character deleted:<br>
<br>
<span class="PreProc">ng intelligent turtle</span><br>
<br>
The next u command gives you the u, and so on:<br>
<br>
<span class="PreProc">ung intelligent turtle</span><br>
<span class="PreProc">oung intelligent turtle</span><br>
<span class="PreProc">young intelligent turtle</span><br>
<span class="PreProc">young intelligent turtle</span><br>
<span class="PreProc">A young intelligent turtle</span><br>
<br>
<span class="Todo">Note</span>:<br>
If you type "u" twice, and the result is that you get the same text<br>
back, you have Vim configured to work Vi compatible. Look here to fix<br>
this: <a class="Identifier" href="usr_01.html#not-compatible">not-compatible</a>.<br>
This text assumes you work "The Vim Way". You might prefer to use<br>
the good old Vi way, but you will have to watch out for small<br>
differences in the text then.<br>
<br>
<br>
REDO<br>
<br>
If you undo too many times, you can press <span class="Special">CTRL-R</span> (redo) to reverse the<br>
preceding command. In other words, it undoes the undo. To see this in<br>
action, press <span class="Special">CTRL-R</span> twice. The character A and the space after it disappear:<br>
<br>
<span class="PreProc">young intelligent turtle</span><br>
<br>
There's a special version of the undo command, the "U" (undo line) command.<br>
The undo line command undoes all the changes made on the last line that was<br>
edited. Typing this command twice cancels the preceding "U".<br>
<br>
<span class="PreProc">A very intelligent turtle</span><br>
xxxx Delete very<br>
<br>
<span class="PreProc">A intelligent turtle</span><br>
xxxxxx Delete turtle<br>
<br>
<span class="PreProc">A intelligent</span><br>
Restore line with "U"<br>
<span class="PreProc">A very intelligent turtle</span><br>
Undo "U" with "u"<br>
<span class="PreProc">A intelligent</span><br>
<br>
The "U" command is a change by itself, which the "u" command undoes and <span class="Special">CTRL-R</span><br>
redoes. This might be a bit confusing. Don't worry, with "u" and <span class="Special">CTRL-R</span> you<br>
can go to any of the situations you had. More about that in section <a class="Identifier" href="usr_32.html#32.2">32.2</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_02.html#02.6" name="02.6">02.6</a> Other editing commands<br>
<br>
Vim has a large number of commands to change the text. See <a class="Identifier" href="quickref.html#Q_in">Q_in</a> and below.<br>
Here are a few often used ones.<br>
<br>
<br>
APPENDING<br>
<br>
The "i" command inserts a character before the character under the cursor.<br>
That works fine; but what happens if you want to add stuff to the end of the<br>
line? For that you need to insert text after the cursor. This is done with<br>
the "a" (append) command.<br>
For example, to change the line<br>
<br>
<span class="PreProc">and that's not saying much for the turtle.</span><br>
to<br>
<span class="PreProc">and that's not saying much for the turtle!!!</span><br>
<br>
move the cursor over to the dot at the end of the line. Then type "x" to<br>
delete the period. The cursor is now positioned at the end of the line on the<br>
e in turtle. Now type<br>
<br>
<div class="helpExample"> a!!!<Esc></div>
<br>
to append three exclamation points after the e in turtle:<br>
<br>
<span class="PreProc">and that's not saying much for the turtle!!!</span><br>
<br>
<br>
OPENING UP A NEW LINE<br>
<br>
The "o" command creates a new, empty line below the cursor and puts Vim in<br>
Insert mode. Then you can type the text for the new line.<br>
Suppose the cursor is somewhere in the first of these two lines:<br>
<br>
<span class="PreProc">A very intelligent turtle</span><br>
<span class="PreProc">Found programming UNIX a hurdle</span><br>
<br>
If you now use the "o" command and type new text:<br>
<br>
<div class="helpExample"> oThat liked using Vim<Esc></div>
<br>
The result is:<br>
<br>
<span class="PreProc">A very intelligent turtle</span><br>
<span class="PreProc">That liked using Vim</span><br>
<span class="PreProc">Found programming UNIX a hurdle</span><br>
<br>
The "O" command (uppercase) opens a line above the cursor.<br>
<br>
<br>
USING A COUNT<br>
<br>
Suppose you want to move up nine lines. You can type "kkkkkkkkk" or you can<br>
enter the command "9k". In fact, you can precede many commands with a number.<br>
Earlier in this chapter, for instance, you added three exclamation points to<br>
the end of a line by typing "a!!!<span class="Special"><Esc></span>". Another way to do this is to use the<br>
command "3a!<span class="Special"><Esc></span>". The count of 3 tells the command that follows to triple<br>
its effect. Similarly, to delete three characters, use the command "3x". The<br>
count always comes before the command it applies to.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_02.html#02.7" name="02.7">02.7</a> Getting out<br>
<br>
To exit, use the "ZZ" command. This command writes the file and exits.<br>
<br>
<span class="Todo">Note</span>:<br>
Unlike many other editors, Vim does not automatically make a backup<br>
file. If you type "ZZ", your changes are committed and there's no<br>
turning back. You can configure the Vim editor to produce backup<br>
files, see <a class="Identifier" href="usr_07.html#07.4">07.4</a>.<br>
<br>
<br>
DISCARDING CHANGES<br>
<br>
Sometimes you will make a sequence of changes and suddenly realize you were<br>
better off before you started. Not to worry; Vim has a<br>
quit-and-throw-things-away command. It is:<br>
<br>
<div class="helpExample"> :q!</div>
<br>
Don't forget to press <span class="Special"><Enter></span> to finish the command.<br>
<br>
For those of you interested in the details, the three parts of this command<br>
are the colon (:), which enters Command-line mode; the q command, which tells<br>
the editor to quit; and the override command modifier (!).<br>
The override command modifier is needed because Vim is reluctant to throw<br>
away changes. If you were to just type ":q", Vim would display an error<br>
message and refuse to exit:<br>
<br>
<span class="PreProc">E37: No write since last change (use ! to override)</span><br>
<br>
By specifying the override, you are in effect telling Vim, "I know that what<br>
I'm doing looks stupid, but I'm a big boy and really want to do this."<br>
<br>
If you want to continue editing with Vim: The ":e!" command reloads the<br>
original version of the file.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_02.html#02.8" name="02.8">02.8</a> Finding help<br>
<br>
Everything you always wanted to know can be found in the Vim help files.<br>
Don't be afraid to ask!<br>
<br>
If you know what you are looking for, it is usually easier to search for it<br>
using the help system, instead of using Google. Because the subjects follow<br>
a certain style guide.<br>
<br>
Also the help has the advantage of belonging to your particular Vim version.<br>
You won't see help for commands added later. These would not work for you.<br>
<br>
To get generic help use this command:<br>
<br>
<div class="helpExample"> :help</div>
<br>
You could also use the first function key <span class="Special"><F1></span>. If your keyboard has a <span class="Special"><Help></span><br>
key it might work as well.<br>
If you don't supply a subject, ":help" displays the general help window.<br>
The creators of Vim did something very clever (or very lazy) with the help<br>
system: They made the help window a normal editing window. You can use all<br>
the normal Vim commands to move through the help information. Therefore h, j,<br>
k, and l move left, down, up and right.<br>
To get out of the help window, use the same command you use to get out of<br>
the editor: "ZZ". This will only close the help window, not exit Vim.<br>
<br>
As you read the help text, you will notice some text enclosed in vertical bars<br>
(for example, <a class="Identifier" href="helphelp.html#help">help</a>). This indicates a hyperlink. If you position the<br>
cursor anywhere between the bars and press <span class="Special">CTRL-]</span> (jump to tag), the help<br>
system takes you to the indicated subject. (For reasons not discussed here,<br>
the Vim terminology for a hyperlink is tag. So <span class="Special">CTRL-]</span> jumps to the location<br>
of the tag given by the word under the cursor.)<br>
After a few jumps, you might want to go back. <span class="Special">CTRL-T</span> (pop tag) takes you<br>
back to the preceding position. <span class="Special">CTRL-O</span> (jump to older position) also works<br>
nicely here.<br>
At the top of the help screen, there is the notation *help.txt*. This name<br>
between "*" characters is used by the help system to define a tag (hyperlink<br>
destination).<br>
See <a class="Identifier" href="usr_29.html#29.1">29.1</a> for details about using tags.<br>
<br>
To get help on a given subject, use the following command:<br>
<br>
<div class="helpExample"> :help {subject}</div>
<br>
To get help on the "x" command, for example, enter the following:<br>
<br>
<div class="helpExample"> :help x</div>
<br>
To find out how to delete text, use this command:<br>
<br>
<div class="helpExample"> :help deleting</div>
<br>
To get a complete index of all Vim commands, use the following command:<br>
<br>
<div class="helpExample"> :help index</div>
<br>
When you need to get help for a control character command (for example,<br>
<span class="Special">CTRL-A</span>), you need to spell it with the prefix "<span class="Special">CTRL-"</span>.<br>
<br>
<div class="helpExample"> :help CTRL-A</div>
<br>
The Vim editor has many different modes. By default, the help system displays<br>
the normal-mode commands. For example, the following command displays help<br>
for the normal-mode <span class="Special">CTRL-H</span> command:<br>
<br>
<div class="helpExample"> :help CTRL-H</div>
<br>
To identify other modes, use a mode prefix. If you want the help for the<br>
insert-mode version of a command, use "i_". For <span class="Special">CTRL-H</span> this gives you the<br>
following command:<br>
<br>
<div class="helpExample"> :help i_CTRL-H</div>
<br>
When you start the Vim editor, you can use several command-line arguments.<br>
These all begin with a dash (-). To find what the -t argument does, for<br>
example, use the command:<br>
<br>
<div class="helpExample"> :help -t</div>
<br>
The Vim editor has a number of options that enable you to configure and<br>
customize the editor. If you want help for an option, you need to enclose it<br>
in single quotation marks. To find out what the <a class="Type" href="options.html#'number'">'number'</a> option does, for<br>
example, use the following command:<br>
<br>
<div class="helpExample"> :help 'number'</div>
<br>
The table with all mode prefixes can be found below: <a class="Identifier" href="usr_02.html#help-summary">help-summary</a>.<br>
<br>
Special keys are enclosed in angle brackets. To find help on the up-arrow key<br>
in Insert mode, for instance, use this command:<br>
<br>
<div class="helpExample"> :help i_<Up></div>
<br>
If you see an error message that you don't understand, for example:<br>
<br>
<span class="PreProc">E37: No write since last change (use ! to override)</span><br>
<br>
You can use the error ID at the start to find help about it:<br>
<br>
<div class="helpExample"> :help E37</div>
<br>
<br>
Summary: <a class="Constant" href="usr_02.html#help-summary" name="help-summary">help-summary</a> <br>
<br>
1) Use Ctrl-D after typing a topic and let Vim show all available topics.<br>
Or press Tab to complete:<br>
<div class="helpExample"> :help some<Tab></div>
More information on how to use the help:<br>
<div class="helpExample"> :help helphelp</div>
<br>
2) Follow the links in bars to related help. You can go from the detailed<br>
help to the user documentation, which describes certain commands more from<br>
a user perspective and less detailed. E.g. after:<br>
<div class="helpExample"> :help pattern.txt</div>
You can see the user guide topics <a class="Identifier" href="usr_03.html#03.9">03.9</a> and <a class="Identifier" href="usr_27.html">usr_27.txt</a> in the<br>
introduction.<br>
<br>
3) Options are enclosed in single apostrophes. To go to the help topic for the<br>
list option:<br>
<div class="helpExample"> :help 'list'</div>
If you only know you are looking for a certain option, you can also do:<br>
<div class="helpExample"> :help options.txt</div>
to open the help page which describes all option handling and then search<br>
using regular expressions, e.g. textwidth.<br>
Certain options have their own namespace, e.g.:<br>
<div class="helpExample"> :help cpo-<letter></div>
for the corresponding flag of the <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a> settings, substitute <span class="Special"><letter></span><br>
by a specific flag, e.g.:<br>
<div class="helpExample"> :help cpo-;</div>
And for the guioption flags:<br>
<div class="helpExample"> :help go-<letter></div>
<br>
4) Normal mode commands do not have a prefix. To go to the help page for the<br>
"gt" command:<br>
<div class="helpExample"> :help gt</div>
<br>
5) Insert mode commands start with i_. Help for deleting a word:<br>
<div class="helpExample"> :help i_CTRL-W</div>
<br>
6) Visual mode commands start with v_. Help for jumping to the other side of<br>
the Visual area:<br>
<div class="helpExample"> :help v_o</div>
<br>
7) Command line editing and arguments start with c_. Help for using the<br>
command argument %:<br>
<div class="helpExample"> :help c_%</div>
<br>
8) Ex-commands always start with ":", so to go to the :s command help:<br>
<div class="helpExample"> :help :s</div>
<br>
9) Commands specifically for debugging start with ">". To go to the help<br>
for the "cont" debug command:<br>
<div class="helpExample"> :help >cont</div>
<br>
10) Key combinations. They usually start with a single letter indicating<br>
the mode for which they can be used. E.g.:<br>
<div class="helpExample"> :help i_CTRL-X</div>
takes you to the family of Ctrl-X commands for insert mode which can be<br>
used to auto complete different things. <span class="Todo">Note</span>, that certain keys will<br>
always be written the same, e.g. Control will always be CTRL.<br>
For normal mode commands there is no prefix and the topic is available at<br>
:h <span class="Special">CTRL-<</span>Letter>. E.g. <br>
<div class="helpExample"> :help CTRL-W</div>
In contrast<br>
<div class="helpExample"> :help c_CTRL-R</div>
will describe what the Ctrl-R does when entering commands in the Command<br>
line and<br>
<div class="helpExample"> :help v_Ctrl-A</div>
talks about incrementing numbers in visual mode and<br>
<div class="helpExample"> :help g_CTRL-A</div>
talks about the g<span class="Special"><C-A></span> command (e.g. you have to press "g" then <span class="Special"><Ctrl-A></span>).<br>
Here the "g" stand for the normal command "g" which always expects a second<br>
key before doing something similar to the commands starting with "z"<br>
<br>
11) Regexp items always start with /. So to get help for the "\+" quantifier<br>
in Vim regexes:<br>
<div class="helpExample"> :help /\+</div>
If you need to know everything about regular expressions, start reading<br>
at:<br>
<div class="helpExample"> :help pattern.txt</div>
<br>
12) Registers always start with "quote". To find out about the special ":"<br>
register:<br>
<div class="helpExample"> :help quote:</div>
<br>
13) Vim script is available at<br>
<div class="helpExample"> :help eval.txt</div>
Certain aspects of the language are available at :h expr-X where "X" is a<br>
single letter. E.g. <br>
<div class="helpExample"> :help expr-!</div>
will take you to the topic describing the "!" (Not) operator for<br>
VimScript.<br>
Also important is<br>
<div class="helpExample"> :help function-list</div>
to find a short description of all functions available. Help topics for<br>
Vim script functions always include the "()", so:<br>
<div class="helpExample"> :help append()</div>
talks about the append Vim script function rather than how to append text<br>
in the current buffer.<br>
<br>
14) Mappings are talked about in the help page :h <a class="Identifier" href="map.html">map.txt</a>. Use<br>
<div class="helpExample"> :help mapmode-i</div>
to find out about the <a class="Identifier" href="map.html#:imap">:imap</a> command. Also use :map-topic<br>
to find out about certain subtopics particular for mappings. e.g:<br>
<div class="helpExample"> :help :map-local</div>
for buffer-local mappings or<br>
<div class="helpExample"> :help map-bar</div>
for how the '|' is handled in mappings.<br>
<br>
15) Command definitions are talked about :h command-topic, so use<br>
<div class="helpExample"> :help command-bar</div>
to find out about the '!' argument for custom commands.<br>
<br>
16) Window management commands always start with <span class="Special">CTRL-W</span>, so you find the<br>
corresponding help at :h <span class="Special">CTRL-W</span>_letter. E.g.<br>
<div class="helpExample"> :help CTRL-W_p</div>
for moving the previous accessed window. You can also access<br>
<div class="helpExample"> :help windows.txt</div>
and read your way through if you are looking for window handling<br>
commands.<br>
<br>
17) Use <a class="Identifier" href="helphelp.html#:helpgrep">:helpgrep</a> to search in all help pages (and also of any installed<br>
plugins). See <a class="Identifier" href="helphelp.html#:helpgrep">:helpgrep</a> for how to use it.<br>
To search for a topic:<br>
<div class="helpExample"> :helpgrep topic</div>
This takes you to the first match. To go to the next one:<br>
<div class="helpExample"> :cnext</div>
All matches are available in the quickfix window which can be opened<br>
with:<br>
<div class="helpExample"> :copen</div>
Move around to the match you like and press Enter to jump to that help.<br>
<br>
18) The user manual. This describes help topics for beginners in a rather<br>
friendly way. Start at <a class="Identifier" href="usr_toc.html">usr_toc.txt</a> to find the table of content (as you<br>
might have guessed):<br>
<div class="helpExample"> :help usr_toc.txt</div>
Skim over the contents to find interesting topics. The "Digraphs" and<br>
"Entering special characters" items are in chapter 24, so to go to that<br>
particular help page:<br>
<div class="helpExample"> :help usr_24.txt</div>
Also if you want to access a certain chapter in the help, the chapter<br>
number can be accessed directly like this:<br>
<div class="helpExample"> :help 10.1</div>
goes to chapter 10.1 in <a class="Identifier" href="usr_10.html">usr_10.txt</a> and talks about recording macros.<br>
<br>
19) Highlighting groups. Always start with hl-groupname. E.g.<br>
<div class="helpExample"> :help hl-WarningMsg</div>
talks about the WarningMsg highlighting group.<br>
<br>
20) Syntax highlighting is namespaced to :syn-topic e.g.<br>
<div class="helpExample"> :help :syn-conceal</div>
talks about the conceal argument for the :syn command.<br>
<br>
21) Quickfix commands usually start with :c while location list commands<br>
usually start with :l<br>
<br>
22) Autocommand events can be found by their name:<br>
<div class="helpExample"> :help BufWinLeave</div>
To see all possible events:<br>
<div class="helpExample"> :help autocommand-events</div>
<br>
23) Command-line switches always start with "-". So for the help of the -f<br>
command switch of Vim use:<br>
<div class="helpExample"> :help -f</div>
<br>
24) Optional features always start with "+". To find out about the<br>
conceal feature use:<br>
<div class="helpExample"> :help +conceal</div>
<br>
25) Documentation for included filetype specific functionality is usually<br>
available in the form ft-<span class="Special"><filetype></span>-<span class="Special"><functionality></span>. So<br>
<div class="helpExample"> :help ft-c-syntax</div>
talks about the C syntax file and the option it provides. Sometimes,<br>
additional sections for omni completion<br>
<div class="helpExample"> :help ft-php-omni</div>
or filetype plugins<br>
<div class="helpExample"> :help ft-tex-plugin</div>
are available.<br>
<br>
26) Error and Warning codes can be looked up directly in the help. So<br>
<div class="helpExample"> :help E297</div>
takes you exactly to the description of the swap error message and<br>
<div class="helpExample"> :help W10</div>
talks about the warning "Changing a readonly file".<br>
Sometimes however, those error codes are not described, but rather are<br>
listed at the Vim command that usually causes this. So:<br>
<div class="helpExample"> :help E128</div>
takes you to the <a class="Identifier" href="eval.html#:function">:function</a> command<br>
<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_03.html">usr_03.txt</a> Moving around<br>
<br>
Copyright: see <a class="Identifier" href="usr_01.html#manual-copyright">manual-copyright</a> 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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。