代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_03 - 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_03<br />
<a name="top"></a><h1>usr_03 - 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_03.html" name="usr_03.txt">usr_03.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2017 Jul 21<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
Moving around<br>
<br>
<br>
Before you can insert or delete text the cursor has to be moved to the right<br>
place. Vim has a large number of commands to position the cursor. This<br>
chapter shows you how to use the most important ones. You can find a list of<br>
these commands below <a class="Identifier" href="quickref.html#Q_lr">Q_lr</a>.<br>
<br>
<a class="Identifier" href="usr_03.html#03.1">03.1</a> Word movement<br>
<a class="Identifier" href="usr_03.html#03.2">03.2</a> Moving to the start or end of a line<br>
<a class="Identifier" href="usr_03.html#03.3">03.3</a> Moving to a character<br>
<a class="Identifier" href="usr_03.html#03.4">03.4</a> Matching a parenthesis<br>
<a class="Identifier" href="usr_03.html#03.5">03.5</a> Moving to a specific line<br>
<a class="Identifier" href="usr_03.html#03.6">03.6</a> Telling where you are<br>
<a class="Identifier" href="usr_03.html#03.7">03.7</a> Scrolling around<br>
<a class="Identifier" href="usr_03.html#03.8">03.8</a> Simple searches<br>
<a class="Identifier" href="usr_03.html#03.9">03.9</a> Simple search patterns<br>
<a class="Identifier" href="usr_03.html#03.10">03.10</a> Using marks<br>
<br>
Next chapter: <a class="Identifier" href="usr_04.html">usr_04.txt</a> Making small changes<br>
Previous chapter: <a class="Identifier" href="usr_02.html">usr_02.txt</a> The first steps in Vim<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_03.html#03.1" name="03.1">03.1</a> Word movement<br>
<br>
To move the cursor forward one word, use the "w" command. Like most Vim<br>
commands, you can use a numeric prefix to move past multiple words. For<br>
example, "3w" moves three words. This figure shows how it works:<br>
<br>
<span class="PreProc">This is a line with example text</span><br>
--->-->->-----------------><br>
w w w 3w<br>
<br>
Notice that "w" moves to the start of the next word if it already is at the<br>
start of a word.<br>
The "b" command moves backward to the start of the previous word:<br>
<br>
<span class="PreProc">This is a line with example text</span><br>
<----<--<-<---------<---<br>
b b b 2b b<br>
<br>
There is also the "e" command that moves to the next end of a word and "ge",<br>
which moves to the previous end of a word:<br>
<br>
<span class="PreProc">This is a line with example text</span><br>
<- <--- -----> ----><br>
ge ge e e<br>
<br>
If you are at the last word of a line, the "w" command will take you to the<br>
first word in the next line. Thus you can use this to move through a<br>
paragraph, much faster than using "l". "b" does the same in the other<br>
direction.<br>
<br>
A word ends at a non-word character, such as a ".", "-" or ")". To change<br>
what Vim considers to be a word, see the <a class="Type" href="options.html#'iskeyword'">'iskeyword'</a> option. If you try this<br>
out in the help directly, <a class="Type" href="options.html#'iskeyword'">'iskeyword'</a> needs to be reset for the examples to<br>
work:<br>
<div class="helpExample"> :set iskeyword&</div>
It is also possible to move by white-space separated WORDs. This is not a<br>
word in the normal sense, that's why the uppercase is used. The commands for<br>
moving by WORDs are also uppercase, as this figure shows:<br>
<br>
ge b w e<br>
<- <- ---> ---><br>
<span class="PreProc">This is-a line, with special/separated/words (and some more).</span><br>
<----- <----- --------------------> -----><br>
gE B W E<br>
<br>
With this mix of lowercase and uppercase commands, you can quickly move<br>
forward and backward through a paragraph.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.2" name="03.2">03.2</a> Moving to the start or end of a line<br>
<br>
The "$" command moves the cursor to the end of a line. If your keyboard has<br>
an <span class="Special"><End></span> key it will do the same thing.<br>
<br>
The "^" command moves to the first non-blank character of the line. The "0"<br>
command (zero) moves to the very first character of the line. The <span class="Special"><Home></span> key<br>
does the same thing. In a picture:<br>
<br>
^<br>
<------------<br>
<span class="PreProc">.....This is a line with example text</span><br>
<----------------- ---------------><br>
0 $<br>
<br>
(the "....." indicates blanks here)<br>
<br>
The "$" command takes a count, like most movement commands. But moving to<br>
the end of the line several times doesn't make sense. Therefore it causes the<br>
editor to move to the end of another line. For example, "1$" moves you to<br>
the end of the first line (the one you're on), "2$" to the end of the next<br>
line, and so on.<br>
The "0" command doesn't take a count argument, because the "0" would be<br>
part of the count. Unexpectedly, using a count with "^" doesn't have any<br>
effect.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.3" name="03.3">03.3</a> Moving to a character<br>
<br>
One of the most useful movement commands is the single-character search<br>
command. The command "fx" searches forward in the line for the single<br>
character x. Hint: "f" stands for "Find".<br>
For example, you are at the beginning of the following line. Suppose you<br>
want to go to the h of human. Just execute the command "fh" and the cursor<br>
will be positioned over the h:<br>
<br>
<span class="PreProc">To err is human. To really foul up you need a computer.</span><br>
---------->---------------><br>
fh fy<br>
<br>
This also shows that the command "fy" moves to the end of the word really.<br>
You can specify a count; therefore, you can go to the "l" of "foul" with<br>
"3fl":<br>
<br>
<span class="PreProc">To err is human. To really foul up you need a computer.</span><br>
---------------------><br>
3fl<br>
<br>
The "F" command searches to the left:<br>
<br>
<span class="PreProc">To err is human. To really foul up you need a computer.</span><br>
<---------------------<br>
Fh<br>
<br>
The "tx" command works like the "fx" command, except it stops one character<br>
before the searched character. Hint: "t" stands for "To". The backward<br>
version of this command is "Tx".<br>
<br>
<span class="PreProc">To err is human. To really foul up you need a computer.</span><br>
<------------ -------------><br>
Th tn<br>
<br>
These four commands can be repeated with ";". "," repeats in the other<br>
direction. The cursor is never moved to another line. Not even when the<br>
sentence continues.<br>
<br>
Sometimes you will start a search, only to realize that you have typed the<br>
wrong command. You type "f" to search backward, for example, only to realize<br>
that you really meant "F". To abort a search, press <span class="Special"><Esc></span>. So "f<span class="Special"><Esc></span>" is an<br>
aborted forward search and doesn't do anything. <span class="Todo">Note</span>: <span class="Special"><Esc></span> cancels most<br>
operations, not just searches.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.4" name="03.4">03.4</a> Matching a parenthesis<br>
<br>
When writing a program you often end up with nested () constructs. Then the<br>
"%" command is very handy: It moves to the matching paren. If the cursor is<br>
on a "(" it will move to the matching ")". If it's on a ")" it will move to<br>
the matching "(".<br>
<br>
%<br>
<-----><br>
<span class="PreProc">if (a == (b * c) / d)</span><br>
<----------------><br>
%<br>
<br>
This also works for [] and {} pairs. (This can be defined with the<br>
<a class="Type" href="options.html#'matchpairs'">'matchpairs'</a> option.)<br>
<br>
When the cursor is not on a useful character, "%" will search forward to find<br>
one. Thus if the cursor is at the start of the line of the previous example,<br>
"%" will search forward and find the first "(". Then it moves to its match:<br>
<br>
<span class="PreProc">if (a == (b * c) / d)</span><br>
---+----------------><br>
%<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.5" name="03.5">03.5</a> Moving to a specific line<br>
<br>
If you are a C or C++ programmer, you are familiar with error messages such as<br>
the following:<br>
<br>
<span class="PreProc">prog.c:33: j undeclared (first use in this function)</span><br>
<br>
This tells you that you might want to fix something on line 33. So how do you<br>
find line 33? One way is to do "9999k" to go to the top of the file and "32j"<br>
to go down thirty-two lines. It is not a good way, but it works. A much<br>
better way of doing things is to use the "G" command. With a count, this<br>
command positions you at the given line number. For example, "33G" puts you<br>
on line 33. (For a better way of going through a compiler's error list, see<br>
<a class="Identifier" href="usr_30.html">usr_30.txt</a>, for information on the :make command.)<br>
With no argument, "G" positions you at the end of the file. A quick way to<br>
go to the start of a file use "gg". "1G" will do the same, but is a tiny bit<br>
more typing.<br>
<br>
| first line of a file ^<br>
| text text text text |<br>
| text text text text | gg<br>
7G | text text text text |<br>
| text text text text<br>
| text text text text<br>
V text text text text |<br>
text text text text | G<br>
text text text text |<br>
last line of a file V<br>
<br>
Another way to move to a line is using the "%" command with a count. For<br>
example "50%" moves you to halfway the file. "90%" goes to near the end.<br>
<br>
The previous assumes that you want to move to a line in the file, no matter if<br>
it's currently visible or not. What if you want to move to one of the lines<br>
you can see? This figure shows the three commands you can use:<br>
<br>
+---------------------------+<br>
H --> | text sample text |<br>
| sample text |<br>
| text sample text |<br>
| sample text |<br>
M --> | text sample text |<br>
| sample text |<br>
| text sample text |<br>
| sample text |<br>
L --> | text sample text |<br>
+---------------------------+<br>
<br>
Hints: "H" stands for Home, "M" for Middle and "L" for Last.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.6" name="03.6">03.6</a> Telling where you are<br>
<br>
To see where you are in a file, there are three ways:<br>
<br>
1. Use the <span class="Special">CTRL-G</span> command. You get a message like this (assuming the <a class="Type" href="options.html#'ruler'">'ruler'</a><br>
option is off):<br>
<br>
<span class="PreProc">"usr_03.txt" line 233 of 650 --35%-- col 45-52</span><br>
<br>
This shows the name of the file you are editing, the line number where the<br>
cursor is, the total number of lines, the percentage of the way through<br>
the file and the column of the cursor.<br>
Sometimes you will see a split column number. For example, "col 2-9".<br>
This indicates that the cursor is positioned on the second character, but<br>
because character one is a tab, occupying eight spaces worth of columns,<br>
the screen column is 9.<br>
<br>
2. Set the <a class="Type" href="options.html#'number'">'number'</a> option. This will display a line number in front of<br>
every line:<br>
<br>
<div class="helpExample"> :set number</div>
<br>
To switch this off again:<br>
<br>
<div class="helpExample"> :set nonumber</div>
<br>
Since <a class="Type" href="options.html#'number'">'number'</a> is a boolean option, prepending "no" to its name has the<br>
effect of switching it off. A boolean option has only these two values,<br>
it is either on or off.<br>
Vim has many options. Besides the boolean ones there are options with<br>
a numerical value and string options. You will see examples of this where<br>
they are used.<br>
<br>
3. Set the <a class="Type" href="options.html#'ruler'">'ruler'</a> option. This will display the cursor position in the<br>
lower right corner of the Vim window:<br>
<br>
<div class="helpExample"> :set ruler</div>
<br>
Using the <a class="Type" href="options.html#'ruler'">'ruler'</a> option has the advantage that it doesn't take much room,<br>
thus there is more space for your text.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.7" name="03.7">03.7</a> Scrolling around<br>
<br>
The <span class="Special">CTRL-U</span> command scrolls down half a screen of text. Think of looking<br>
through a viewing window at the text and moving this window up by half the<br>
height of the window. Thus the window moves up over the text, which is<br>
backward in the file. Don't worry if you have a little trouble remembering<br>
which end is up. Most users have the same problem.<br>
The <span class="Special">CTRL-D</span> command moves the viewing window down half a screen in the file,<br>
thus scrolls the text up half a screen.<br>
<br>
+----------------+<br>
| some text |<br>
| some text |<br>
| some text |<br>
+---------------+ | some text |<br>
| some text | <span class="Special">CTRL-U</span> --> | |<br>
| | | 123456 |<br>
| 123456 | +----------------+<br>
| 7890 |<br>
| | +----------------+<br>
| example | <span class="Special">CTRL-D</span> --> | 7890 |<br>
+---------------+ | |<br>
| example |<br>
| example |<br>
| example |<br>
| example |<br>
+----------------+<br>
<br>
To scroll one line at a time use <span class="Special">CTRL-E</span> (scroll up) and <span class="Special">CTRL-Y</span> (scroll down).<br>
Think of <span class="Special">CTRL-E</span> to give you one line Extra. (If you use MS-Windows compatible<br>
key mappings <span class="Special">CTRL-Y</span> will redo a change instead of scroll.)<br>
<br>
To scroll forward by a whole screen (except for two lines) use <span class="Special">CTRL-F</span>. The<br>
other way is backward, <span class="Special">CTRL-B</span> is the command to use. Fortunately <span class="Special">CTRL-F</span> is<br>
Forward and <span class="Special">CTRL-B</span> is Backward, that's easy to remember.<br>
<br>
A common issue is that after moving down many lines with "j" your cursor is at<br>
the bottom of the screen. You would like to see the context of the line with<br>
the cursor. That's done with the "zz" command.<br>
<br>
+------------------+ +------------------+<br>
| some text | | some text |<br>
| some text | | some text |<br>
| some text | | some text |<br>
| some text | zz --> | line with cursor |<br>
| some text | | some text |<br>
| some text | | some text |<br>
| line with cursor | | some text |<br>
+------------------+ +------------------+<br>
<br>
The "zt" command puts the cursor line at the top, "zb" at the bottom. There<br>
are a few more scrolling commands, see <a class="Identifier" href="quickref.html#Q_sc">Q_sc</a>. To always keep a few lines of<br>
context around the cursor, use the <a class="Type" href="options.html#'scrolloff'">'scrolloff'</a> option.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.8" name="03.8">03.8</a> Simple searches<br>
<br>
To search for a string, use the "/string" command. To find the word include,<br>
for example, use the command:<br>
<br>
<div class="helpExample"> /include</div>
<br>
You will notice that when you type the "/" the cursor jumps to the last line<br>
of the Vim window, like with colon commands. That is where you type the word.<br>
You can press the backspace key (backarrow or <span class="Special"><BS></span>) to make corrections. Use<br>
the <span class="Special"><Left></span> and <span class="Special"><Right></span> cursor keys when necessary.<br>
Pressing <span class="Special"><Enter></span> executes the command.<br>
<br>
<span class="Todo">Note</span>:<br>
The characters .*[]^%/\?~$ have special meanings. If you want to use<br>
them in a search you must put a \ in front of them. See below.<br>
<br>
To find the next occurrence of the same string use the "n" command. Use this<br>
to find the first #include after the cursor:<br>
<br>
<div class="helpExample"> /#include</div>
<br>
And then type "n" several times. You will move to each #include in the text.<br>
You can also use a count if you know which match you want. Thus "3n" finds<br>
the third match. Using a count with "/" doesn't work.<br>
<br>
The "?" command works like "/" but searches backwards:<br>
<br>
<div class="helpExample"> ?word</div>
<br>
The "<span class="Special">N</span>" command repeats the last search the opposite direction. Thus using<br>
"<span class="Special">N</span>" after a "/" command searches backwards, using "<span class="Special">N</span>" after "?" searches<br>
forward.<br>
<br>
<br>
IGNORING CASE<br>
<br>
Normally you have to type exactly what you want to find. If you don't care<br>
about upper or lowercase in a word, set the <a class="Type" href="options.html#'ignorecase'">'ignorecase'</a> option:<br>
<br>
<div class="helpExample"> :set ignorecase</div>
<br>
If you now search for "word", it will also match "Word" and "WORD". To match<br>
case again:<br>
<br>
<div class="helpExample"> :set noignorecase</div>
<br>
<br>
HISTORY<br>
<br>
Suppose you do three searches:<br>
<br>
<div class="helpExample"> /one<br>
/two<br>
/three</div>
<br>
Now let's start searching by typing a simple "/" without pressing <span class="Special"><Enter></span>. If<br>
you press <span class="Special"><Up></span> (the cursor key), Vim puts "/three" on the command line.<br>
Pressing <span class="Special"><Enter></span> at this point searches for three. If you do not press<br>
<span class="Special"><Enter></span>, but press <span class="Special"><Up></span> instead, Vim changes the prompt to "/two". Another<br>
press of <span class="Special"><Up></span> moves you to "/one".<br>
You can also use the <span class="Special"><Down></span> cursor key to move through the history of<br>
search commands in the other direction.<br>
<br>
If you know what a previously used pattern starts with, and you want to use it<br>
again, type that character before pressing <span class="Special"><Up></span>. With the previous example,<br>
you can type "/o<span class="Special"><Up></span>" and Vim will put "/one" on the command line.<br>
<br>
The commands starting with ":" also have a history. That allows you to recall<br>
a previous command and execute it again. These two histories are separate.<br>
<br>
<br>
SEARCHING FOR A WORD IN THE TEXT<br>
<br>
Suppose you see the word "TheLongFunctionName" in the text and you want to<br>
find the next occurrence of it. You could type "/TheLongFunctionName", but<br>
that's a lot of typing. And when you make a mistake Vim won't find it.<br>
There is an easier way: Position the cursor on the word and use the "*"<br>
command. Vim will grab the word under the cursor and use it as the search<br>
string.<br>
The "#" command does the same in the other direction. You can prepend a<br>
count: "3*" searches for the third occurrence of the word under the cursor.<br>
<br>
<br>
SEARCHING FOR WHOLE WORDS<br>
<br>
If you type "/the" it will also match "there". To only find words that end<br>
in "the" use:<br>
<br>
<div class="helpExample"> /the\></div>
<br>
The "\>" item is a special marker that only matches at the end of a word.<br>
Similarly "\<" only matches at the beginning of a word. Thus to search for<br>
the word "the" only:<br>
<br>
<div class="helpExample"> /\<the\></div>
<br>
This does not match "there" or "soothe". Notice that the "*" and "#" commands<br>
use these start-of-word and end-of-word markers to only find whole words (you<br>
can use "g*" and "g#" to match partial words).<br>
<br>
<br>
HIGHLIGHTING MATCHES<br>
<br>
While editing a program you see a variable called "nr". You want to check<br>
where it's used. You could move the cursor to "nr" and use the "*" command<br>
and press "n" to go along all the matches.<br>
There is another way. Type this command:<br>
<br>
<div class="helpExample"> :set hlsearch</div>
<br>
If you now search for "nr", Vim will highlight all matches. That is a very<br>
good way to see where the variable is used, without the need to type commands.<br>
To switch this off:<br>
<br>
<div class="helpExample"> :set nohlsearch</div>
<br>
Then you need to switch it on again if you want to use it for the next search<br>
command. If you only want to remove the highlighting, use this command:<br>
<br>
<div class="helpExample"> :nohlsearch</div>
<br>
This doesn't reset the option. Instead, it disables the highlighting. As<br>
soon as you execute a search command, the highlighting will be used again.<br>
Also for the "n" and "<span class="Special">N</span>" commands.<br>
<br>
<br>
TUNING SEARCHES<br>
<br>
There are a few options that change how searching works. These are the<br>
essential ones:<br>
<br>
<div class="helpExample"> :set incsearch</div>
<br>
This makes Vim display the match for the string while you are still typing it.<br>
Use this to check if the right match will be found. Then press <span class="Special"><Enter></span> to<br>
really jump to that location. Or type more to change the search string.<br>
<br>
<div class="helpExample"> :set nowrapscan</div>
<br>
This stops the search at the end of the file. Or, when you are searching<br>
backwards, at the start of the file. The <a class="Type" href="options.html#'wrapscan'">'wrapscan'</a> option is on by default,<br>
thus searching wraps around the end of the file.<br>
<br>
<br>
INTERMEZZO<br>
<br>
If you like one of the options mentioned before, and set it each time you use<br>
Vim, you can put the command in your Vim startup file.<br>
Edit the file, as mentioned at <a class="Identifier" href="usr_01.html#not-compatible">not-compatible</a>. Or use this command to<br>
find out where it is:<br>
<br>
<div class="helpExample"> :scriptnames</div>
<br>
Edit the file, for example with:<br>
<br>
<div class="helpExample"> :edit ~/.vimrc</div>
<br>
Then add a line with the command to set the option, just like you typed it in<br>
Vim. Example:<br>
<br>
<div class="helpExample"> Go:set hlsearch<Esc></div>
<br>
"G" moves to the end of the file. "o" starts a new line, where you type the<br>
":set" command. You end insert mode with <span class="Special"><Esc></span>. Then write the file:<br>
<br>
<div class="helpExample"> ZZ</div>
<br>
If you now start Vim again, the <a class="Type" href="options.html#'hlsearch'">'hlsearch'</a> option will already be set.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.9" name="03.9">03.9</a> Simple search patterns<br>
<br>
The Vim editor uses regular expressions to specify what to search for.<br>
Regular expressions are an extremely powerful and compact way to specify a<br>
search pattern. Unfortunately, this power comes at a price, because regular<br>
expressions are a bit tricky to specify.<br>
In this section we mention only a few essential ones. More about search<br>
patterns and commands in chapter 27 <a class="Identifier" href="usr_27.html">usr_27.txt</a>. You can find the full<br>
explanation here: <a class="Identifier" href="pattern.html#pattern">pattern</a>.<br>
<br>
<br>
BEGINNING AND END OF A LINE<br>
<br>
The ^ character matches the beginning of a line. On an English-US keyboard<br>
you find it above the 6. The pattern "include" matches the word include<br>
anywhere on the line. But the pattern "^include" matches the word include<br>
only if it is at the beginning of a line.<br>
The $ character matches the end of a line. Therefore, "was$" matches the<br>
word was only if it is at the end of a line.<br>
<br>
Let's mark the places where "/the" matches in this example line with "x"s:<br>
<br>
<span class="PreProc">the solder holding one of the chips melted and the</span><br>
xxx xxx xxx<br>
<br>
Using "/the$" we find this match:<br>
<br>
<span class="PreProc">the solder holding one of the chips melted and the</span><br>
xxx<br>
<br>
And with "/^the" we find this one:<br>
<span class="PreProc">the solder holding one of the chips melted and the</span><br>
xxx<br>
<br>
You can try searching with "/^the$", it will only match a single line<br>
consisting of "the". White space does matter here, thus if a line contains a<br>
space after the word, like "the ", the pattern will not match.<br>
<br>
<br>
MATCHING ANY SINGLE CHARACTER<br>
<br>
The . (dot) character matches any existing character. For example, the<br>
pattern "c.m" matches a string whose first character is a c, whose second<br>
character is anything, and whose third character is m. Example:<br>
<br>
<span class="PreProc">We use a computer that became the cummin winter.</span><br>
xxx xxx xxx<br>
<br>
<br>
MATCHING SPECIAL CHARACTERS<br>
<br>
If you really want to match a dot, you must avoid its special meaning by<br>
putting a backslash before it.<br>
If you search for "ter.", you will find these matches:<br>
<br>
<span class="PreProc">We use a computer that became the cummin winter.</span><br>
xxxx xxxx<br>
<br>
Searching for "ter\." only finds the second match.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_03.html#03.10" name="03.10">03.10</a> Using marks<br>
<br>
When you make a jump to a position with the "G" command, Vim remembers the<br>
position from before this jump. This position is called a mark. To go back<br>
where you came from, use this command:<br>
<br>
<div class="helpExample"> ``</div>
<br>
This ` is a backtick or open single-quote character.<br>
If you use the same command a second time you will jump back again. That's<br>
because the ` command is a jump itself, and the position from before this jump<br>
is remembered.<br>
<br>
Generally, every time you do a command that can move the cursor further than<br>
within the same line, this is called a jump. This includes the search<br>
commands "/" and "n" (it doesn't matter how far away the match is). But not<br>
the character searches with "fx" and "tx" or the word movements "w" and "e".<br>
Also, "j" and "k" are not considered to be a jump. Even when you use a<br>
count to make them move the cursor quite a long way away.<br>
<br>
The `` command jumps back and forth, between two points. The <span class="Special">CTRL-O</span> command<br>
jumps to older positions (Hint: O for older). <span class="Special">CTRL-I</span> then jumps back to newer<br>
positions (Hint: I is just next to O on the keyboard). Consider this sequence<br>
of commands:<br>
<br>
<div class="helpExample"> 33G<br>
/^The<br>
CTRL-O</div>
<br>
You first jump to line 33, then search for a line that starts with "The".<br>
Then with <span class="Special">CTRL-O</span> you jump back to line 33. Another <span class="Special">CTRL-O</span> takes you back to<br>
where you started. If you now use <span class="Special">CTRL-I</span> you jump to line 33 again. And<br>
to the match for "The" with another <span class="Special">CTRL-I</span>.<br>
<br>
<br>
| example text ^ |<br>
33G | example text | <span class="Special">CTRL-O</span> | <span class="Special">CTRL-I</span><br>
| example text | |<br>
V line 33 text ^ V<br>
| example text | |<br>
/^The | example text | <span class="Special">CTRL-O</span> | <span class="Special">CTRL-I</span><br>
V There you are | V<br>
example text<br>
<br>
<span class="Todo">Note</span>:<br>
<span class="Special">CTRL-I</span> is the same as <span class="Special"><Tab></span>.<br>
<br>
The ":jumps" command gives a list of positions you jumped to. The entry which<br>
you used last is marked with a ">".<br>
<br>
<br>
<span class="Statement">NAMED MARKS </span><a class="Constant" href="usr_03.html#bookmark" name="bookmark">bookmark</a><br>
<br>
Vim enables you to place your own marks in the text. The command "ma" marks<br>
the place under the cursor as mark a. You can place 26 marks (a through z) in<br>
your text. You can't see them, it's just a position that Vim remembers.<br>
To go to a mark, use the command `<span class="Special">{mark}</span>, where <span class="Special">{mark}</span> is the mark letter.<br>
Thus to move to the a mark:<br>
<br>
<div class="helpExample"> `a</div>
<br>
The command 'mark (single quotation mark, or apostrophe) moves you to the<br>
beginning of the line containing the mark. This differs from the `mark<br>
command, which moves you to marked column.<br>
<br>
The marks can be very useful when working on two related parts in a file.<br>
Suppose you have some text near the start of the file you need to look at,<br>
while working on some text near the end of the file.<br>
Move to the text at the start and place the s (start) mark there:<br>
<br>
<div class="helpExample"> ms</div>
<br>
Then move to the text you want to work on and put the e (end) mark there:<br>
<br>
<div class="helpExample"> me</div>
<br>
Now you can move around, and when you want to look at the start of the file,<br>
you use this to jump there:<br>
<br>
<div class="helpExample"> 's</div>
<br>
Then you can use '' to jump back to where you were, or 'e to jump to the text<br>
you were working on at the end.<br>
There is nothing special about using s for start and e for end, they are<br>
just easy to remember.<br>
<br>
You can use this command to get a list of marks:<br>
<br>
<div class="helpExample"> :marks</div>
<br>
You will notice a few special marks. These include:<br>
<br>
' The cursor position before doing a jump<br>
" The cursor position when last editing the file<br>
[ Start of the last change<br>
] End of the last change<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_04.html">usr_04.txt</a> Making small changes<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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。