代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_12 - 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_12<br />
<a name="top"></a><h1>usr_12 - 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_12.html" name="usr_12.txt">usr_12.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2007 May 11<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
Clever tricks<br>
<br>
<br>
By combining several commands you can make Vim do nearly everything. In this<br>
chapter a number of useful combinations will be presented. This uses the<br>
commands introduced in the previous chapters and a few more.<br>
<br>
<a class="Identifier" href="usr_12.html#12.1">12.1</a> Replace a word<br>
<a class="Identifier" href="usr_12.html#12.2">12.2</a> Change "Last, First" to "First Last"<br>
<a class="Identifier" href="usr_12.html#12.3">12.3</a> Sort a list<br>
<a class="Identifier" href="usr_12.html#12.4">12.4</a> Reverse line order<br>
<a class="Identifier" href="usr_12.html#12.5">12.5</a> Count words<br>
<a class="Identifier" href="usr_12.html#12.6">12.6</a> Find a man page<br>
<a class="Identifier" href="usr_12.html#12.7">12.7</a> Trim blanks<br>
<a class="Identifier" href="usr_12.html#12.8">12.8</a> Find where a word is used<br>
<br>
Next chapter: <a class="Identifier" href="usr_20.html">usr_20.txt</a> Typing command-line commands quickly<br>
Previous chapter: <a class="Identifier" href="usr_11.html">usr_11.txt</a> Recovering from a crash<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_12.html#12.1" name="12.1">12.1</a> Replace a word<br>
<br>
The substitute command can be used to replace all occurrences of a word with<br>
another word:<br>
<br>
<div class="helpExample"> :%s/four/4/g</div>
<br>
The "%" range means to replace in all lines. The "g" flag at the end causes<br>
all words in a line to be replaced.<br>
This will not do the right thing if your file also contains "thirtyfour".<br>
It would be replaced with "thirty4". To avoid this, use the "\<" item to<br>
match the start of a word:<br>
<br>
<div class="helpExample"> :%s/\<four/4/g</div>
<br>
Obviously, this still goes wrong on "fourteen". Use "\>" to match the end of<br>
a word:<br>
<br>
<div class="helpExample"> :%s/\<four\>/4/g</div>
<br>
If you are programming, you might want to replace "four" in comments, but not<br>
in the code. Since this is difficult to specify, add the "c" flag to have the<br>
substitute command prompt you for each replacement:<br>
<br>
<br>
<div class="helpExample"> :%s/\<four\>/4/gc</div>
<br>
<br>
REPLACING IN SEVERAL FILES<br>
<br>
Suppose you want to replace a word in more than one file. You could edit each<br>
file and type the command manually. It's a lot faster to use record and<br>
playback.<br>
Let's assume you have a directory with C++ files, all ending in ".cpp".<br>
There is a function called "GetResp" that you want to rename to "GetAnswer".<br>
<br>
vim *.cpp Start Vim, defining the argument list to<br>
contain all the C++ files. You are now in the<br>
first file.<br>
qq Start recording into the q register<br>
:%s/\<GetResp\>/GetAnswer/g<br>
Do the replacements in the first file.<br>
:wnext Write this file and move to the next one.<br>
q Stop recording.<br>
@q Execute the q register. This will replay the<br>
substitution and ":wnext". You can verify<br>
that this doesn't produce an error message.<br>
999@q Execute the q register on the remaining files.<br>
<br>
At the last file you will get an error message, because ":wnext" cannot move<br>
to the next file. This stops the execution, and everything is done.<br>
<br>
<span class="Todo">Note</span>:<br>
When playing back a recorded sequence, an error stops the execution.<br>
Therefore, make sure you don't get an error message when recording.<br>
<br>
There is one catch: If one of the .cpp files does not contain the word<br>
"GetResp", you will get an error and replacing will stop. To avoid this, add<br>
the "e" flag to the substitute command:<br>
<br>
<div class="helpExample"> :%s/\<GetResp\>/GetAnswer/ge</div>
<br>
The "e" flag tells ":substitute" that not finding a match is not an error.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_12.html#12.2" name="12.2">12.2</a> Change "Last, First" to "First Last"<br>
<br>
You have a list of names in this form:<br>
<br>
<span class="PreProc">Doe, John</span><br>
<span class="PreProc">Smith, Peter</span><br>
<br>
You want to change that to:<br>
<br>
<span class="PreProc">John Doe</span><br>
<span class="PreProc">Peter Smith</span><br>
<br>
This can be done with just one command:<br>
<br>
<div class="helpExample"> :%s/\([^,]*\), \(.*\)/\2 \1/</div>
<br>
Let's break this down in parts. Obviously it starts with a substitute<br>
command. The "%" is the line range, which stands for the whole file. Thus<br>
the substitution is done in every line in the file.<br>
The arguments for the substitute command are "/from/to/". The slashes<br>
separate the "from" pattern and the "to" string. This is what the "from"<br>
pattern contains:<br>
<span class="PreProc">\([^,]*\), \(.*\)</span><br>
<br>
The first part between \( \) matches "Last" \( \)<br>
match anything but a comma [^,]<br>
any number of times *<br>
matches ", " literally ,<br>
The second part between \( \) matches "First" \( \)<br>
any character .<br>
any number of times *<br>
<br>
In the "to" part we have "\2" and "\1". These are called backreferences.<br>
They refer to the text matched by the "\( \)" parts in the pattern. "\2"<br>
refers to the text matched by the second "\( \)", which is the "First" name.<br>
"\1" refers to the first "\( \)", which is the "Last" name.<br>
You can use up to nine backreferences in the "to" part of a substitute<br>
command. "\0" stands for the whole matched pattern. There are a few more<br>
special items in a substitute command, see <a class="Identifier" href="change.html#sub-replace-special">sub-replace-special</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_12.html#12.3" name="12.3">12.3</a> Sort a list<br>
<br>
In a Makefile you often have a list of files. For example:<br>
<br>
<span class="PreProc">OBJS = \</span><br>
<span class="PreProc">version.o \</span><br>
<span class="PreProc">pch.o \</span><br>
<span class="PreProc">getopt.o \</span><br>
<span class="PreProc">util.o \</span><br>
<span class="PreProc">getopt1.o \</span><br>
<span class="PreProc">inp.o \</span><br>
<span class="PreProc">patch.o \</span><br>
<span class="PreProc">backup.o</span><br>
<br>
To sort this list, filter the text through the external sort command:<br>
<br>
<div class="helpExample"> /^OBJS<br>
j<br>
:.,/^$/-1!sort</div>
<br>
This goes to the first line, where "OBJS" is the first thing in the line.<br>
Then it goes one line down and filters the lines until the next empty line.<br>
You could also select the lines in Visual mode and then use "!sort". That's<br>
easier to type, but more work when there are many lines.<br>
The result is this:<br>
<br>
<span class="PreProc">OBJS = \</span><br>
<span class="PreProc">backup.o</span><br>
<span class="PreProc">getopt.o \</span><br>
<span class="PreProc">getopt1.o \</span><br>
<span class="PreProc">inp.o \</span><br>
<span class="PreProc">patch.o \</span><br>
<span class="PreProc">pch.o \</span><br>
<span class="PreProc">util.o \</span><br>
<span class="PreProc">version.o \</span><br>
<br>
<br>
Notice that a backslash at the end of each line is used to indicate the line<br>
continues. After sorting, this is wrong! The "backup.o" line that was at<br>
the end didn't have a backslash. Now that it sorts to another place, it<br>
must have a backslash.<br>
The simplest solution is to add the backslash with "A \<span class="Special"><Esc></span>". You can<br>
keep the backslash in the last line, if you make sure an empty line comes<br>
after it. That way you don't have this problem again.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_12.html#12.4" name="12.4">12.4</a> Reverse line order<br>
<br>
The <a class="Identifier" href="repeat.html#:global">:global</a> command can be combined with the <a class="Identifier" href="change.html#:move">:move</a> command to move all the<br>
lines before the first line, resulting in a reversed file. The command is:<br>
<br>
<div class="helpExample"> :global/^/m 0</div>
<br>
Abbreviated:<br>
<br>
<div class="helpExample"> :g/^/m 0</div>
<br>
The "^" regular expression matches the beginning of the line (even if the line<br>
is blank). The <a class="Identifier" href="change.html#:move">:move</a> command moves the matching line to after the mythical<br>
zeroth line, so the current matching line becomes the first line of the file.<br>
As the <a class="Identifier" href="repeat.html#:global">:global</a> command is not confused by the changing line numbering,<br>
<a class="Identifier" href="repeat.html#:global">:global</a> proceeds to match all remaining lines of the file and puts each as<br>
the first.<br>
<br>
This also works on a range of lines. First move to above the first line and<br>
mark it with "mt". Then move the cursor to the last line in the range and<br>
type:<br>
<br>
<div class="helpExample"> :'t+1,.g/^/m 't</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_12.html#12.5" name="12.5">12.5</a> Count words<br>
<br>
Sometimes you have to write a text with a maximum number of words. Vim can<br>
count the words for you.<br>
When the whole file is what you want to count the words in, use this<br>
command:<br>
<br>
<div class="helpExample"> g CTRL-G</div>
<br>
Do not type a space after the g, this is just used here to make the command<br>
easy to read.<br>
The output looks like this:<br>
<br>
<span class="PreProc">Col 1 of 0; Line 141 of 157; Word 748 of 774; Byte 4489 of 4976</span><br>
<br>
You can see on which word you are (748), and the total number of words in the<br>
file (774).<br>
<br>
When the text is only part of a file, you could move to the start of the text,<br>
type "g <span class="Special">CTRL-G</span>", move to the end of the text, type "g <span class="Special">CTRL-G</span>" again, and then<br>
use your brain to compute the difference in the word position. That's a good<br>
exercise, but there is an easier way. With Visual mode, select the text you<br>
want to count words in. Then type g <span class="Special">CTRL-G</span>. The result:<br>
<br>
<span class="PreProc">Selected 5 of 293 Lines; 70 of 1884 Words; 359 of 10928 Bytes</span><br>
<br>
For other ways to count words, lines and other items, see <a class="Identifier" href="tips.html#count-items">count-items</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_12.html#12.6" name="12.6">12.6</a> Find a man page <a class="Constant" href="usr_12.html#find-manpage" name="find-manpage">find-manpage</a><br>
<br>
While editing a shell script or C program, you are using a command or function<br>
that you want to find the man page for (this is on Unix). Let's first use a<br>
simple way: Move the cursor to the word you want to find help on and press<br>
<br>
<div class="helpExample"> K</div>
<br>
Vim will run the external "man" program on the word. If the man page is<br>
found, it is displayed. This uses the normal pager to scroll through the text<br>
(mostly the "more" program). When you get to the end pressing <span class="Special"><Enter></span> will<br>
get you back into Vim.<br>
<br>
A disadvantage is that you can't see the man page and the text you are working<br>
on at the same time. There is a trick to make the man page appear in a Vim<br>
window. First, load the man filetype plugin:<br>
<br>
<div class="helpExample"> :runtime! ftplugin/man.vim</div>
<br>
Put this command in your vimrc file if you intend to do this often. Now you<br>
can use the ":Man" command to open a window on a man page:<br>
<br>
<div class="helpExample"> :Man csh</div>
<br>
You can scroll around and the text is highlighted. This allows you to find<br>
the help you were looking for. Use <span class="Special">CTRL-W</span> w to jump to the window with the<br>
text you were working on.<br>
To find a man page in a specific section, put the section number first.<br>
For example, to look in section 3 for "echo":<br>
<br>
<div class="helpExample"> :Man 3 echo</div>
<br>
To jump to another man page, which is in the text with the typical form<br>
"word(1)", press <span class="Special">CTRL-]</span> on it. Further ":Man" commands will use the same<br>
window.<br>
<br>
To display a man page for the word under the cursor, use this:<br>
<br>
<div class="helpExample"> \K</div>
<br>
(If you redefined the <span class="Special"><Leader></span>, use it instead of the backslash).<br>
For example, you want to know the return value of "strstr()" while editing<br>
this line:<br>
<br>
<span class="PreProc">if ( strstr (input, "aap") == )</span><br>
<br>
Move the cursor to somewhere on "strstr" and type "\K". A window will open<br>
to display the man page for strstr().<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_12.html#12.7" name="12.7">12.7</a> Trim blanks<br>
<br>
Some people find spaces and tabs at the end of a line useless, wasteful, and<br>
ugly. To remove whitespace at the end of every line, execute the following<br>
command:<br>
<br>
<div class="helpExample"> :%s/\s\+$//</div>
<br>
The line range "%" is used, thus this works on the whole file. The pattern<br>
that the ":substitute" command matches with is "\s\+$". This finds white<br>
space characters (\s), 1 or more of them (\+), before the end-of-line ($).<br>
Later will be explained how you write patterns like this <a class="Identifier" href="usr_27.html">usr_27.txt</a>.<br>
The "to" part of the substitute command is empty: "//". Thus it replaces<br>
with nothing, effectively deleting the matched white space.<br>
<br>
Another wasteful use of spaces is placing them before a tab. Often these can<br>
be deleted without changing the amount of white space. But not always!<br>
Therefore, you can best do this manually. Use this search command:<br>
<br>
<div class="helpExample"> / </div>
<br>
You cannot see it, but there is a space before a tab in this command. Thus<br>
it's "/<span class="Special"><Space><Tab></span>". Now use "x" to delete the space and check that the<br>
amount of white space doesn't change. You might have to insert a tab if it<br>
does change. Type "n" to find the next match. Repeat this until no more<br>
matches can be found.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_12.html#12.8" name="12.8">12.8</a> Find where a word is used<br>
<br>
If you are a UNIX user, you can use a combination of Vim and the grep command<br>
to edit all the files that contain a given word. This is extremely useful if<br>
you are working on a program and want to view or edit all the files that<br>
contain a specific variable.<br>
For example, suppose you want to edit all the C program files that contain<br>
the word "frame_counter". To do this you use the command:<br>
<br>
<div class="helpExample"> vim `grep -l frame_counter *.c`</div>
<br>
Let's look at this command in detail. The grep command searches through a set<br>
of files for a given word. Because the -l argument is specified, the command<br>
will only list the files containing the word and not print the matching lines.<br>
The word it is searching for is "frame_counter". Actually, this can be any<br>
regular expression. (<span class="Todo">Note</span>: What grep uses for regular expressions is not<br>
exactly the same as what Vim uses.)<br>
The entire command is enclosed in backticks (`). This tells the UNIX shell<br>
to run this command and pretend that the results were typed on the command<br>
line. So what happens is that the grep command is run and produces a list of<br>
files, these files are put on the Vim command line. This results in Vim<br>
editing the file list that is the output of grep. You can then use commands<br>
like ":next" and ":first" to browse through the files.<br>
<br>
<br>
FINDING EACH LINE<br>
<br>
The above command only finds the files in which the word is found. You still<br>
have to find the word within the files.<br>
Vim has a built-in command that you can use to search a set of files for a<br>
given string. If you want to find all occurrences of "error_string" in all C<br>
program files, for example, enter the following command:<br>
<br>
<div class="helpExample"> :grep error_string *.c</div>
<br>
This causes Vim to search for the string "error_string" in all the specified<br>
files (*.c). The editor will now open the first file where a match is found<br>
and position the cursor on the first matching line. To go to the next<br>
matching line (no matter in what file it is), use the ":cnext" command. To go<br>
to the previous match, use the ":cprev" command. Use ":clist" to see all the<br>
matches and where they are.<br>
The ":grep" command uses the external commands grep (on Unix) or findstr<br>
(on Windows). You can change this by setting the option <a class="Type" href="options.html#'grepprg'">'grepprg'</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_20.html">usr_20.txt</a> Typing command-line commands quickly<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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。