1 Star 0 Fork 0

hilarryxu/vimdoc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
usr_12.html 35.09 KB
一键复制 编辑 原始数据 按行查看 历史
hilarryxu 提交于 2017-08-15 10:58 . Init repo
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
<!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>&nbsp;&nbsp;&nbsp;&nbsp;For&nbsp;<span class="Identifier">Vim version 8.0.</span>&nbsp;&nbsp;Last change: 2007 May 11<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VIM USER MANUAL - by Bram Moolenaar<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Clever tricks<br>
<br>
<br>
By combining several commands you can make Vim do nearly everything.&nbsp;&nbsp;In this<br>
chapter a number of useful combinations will be presented.&nbsp;&nbsp;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>&nbsp;&nbsp;Replace a word<br>
<a class="Identifier" href="usr_12.html#12.2">12.2</a>&nbsp;&nbsp;Change &quot;Last, First&quot; to &quot;First Last&quot;<br>
<a class="Identifier" href="usr_12.html#12.3">12.3</a>&nbsp;&nbsp;Sort a list<br>
<a class="Identifier" href="usr_12.html#12.4">12.4</a>&nbsp;&nbsp;Reverse line order<br>
<a class="Identifier" href="usr_12.html#12.5">12.5</a>&nbsp;&nbsp;Count words<br>
<a class="Identifier" href="usr_12.html#12.6">12.6</a>&nbsp;&nbsp;Find a man page<br>
<a class="Identifier" href="usr_12.html#12.7">12.7</a>&nbsp;&nbsp;Trim blanks<br>
<a class="Identifier" href="usr_12.html#12.8">12.8</a>&nbsp;&nbsp;Find where a word is used<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Next chapter:&nbsp;<a class="Identifier" href="usr_20.html">usr_20.txt</a>&nbsp;&nbsp;Typing command-line commands quickly<br>
&nbsp;Previous chapter:&nbsp;<a class="Identifier" href="usr_11.html">usr_11.txt</a>&nbsp;&nbsp;Recovering from a crash<br>
Table of contents:&nbsp;<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>&nbsp;&nbsp;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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/four/4/g</div>
<br>
The &quot;%&quot; range means to replace in all lines.&nbsp;&nbsp;The &quot;g&quot; flag at the end causes<br>
all words in a line to be replaced.<br>
&nbsp;&nbsp; This will not do the right thing if your file also contains &quot;thirtyfour&quot;.<br>
It would be replaced with &quot;thirty4&quot;.&nbsp;&nbsp;To avoid this, use the &quot;\&lt;&quot; item to<br>
match the start of a word:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/\&lt;four/4/g</div>
<br>
Obviously, this still goes wrong on &quot;fourteen&quot;.&nbsp;&nbsp;Use &quot;\&gt;&quot; to match the end of<br>
a word:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/\&lt;four\&gt;/4/g</div>
<br>
If you are programming, you might want to replace &quot;four&quot; in comments, but not<br>
in the code.&nbsp;&nbsp;Since this is difficult to specify, add the &quot;c&quot; flag to have the<br>
substitute command prompt you for each replacement:<br>
<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/\&lt;four\&gt;/4/gc</div>
<br>
<br>
REPLACING IN SEVERAL FILES<br>
<br>
Suppose you want to replace a word in more than one file.&nbsp;&nbsp;You could edit each<br>
file and type the command manually.&nbsp;&nbsp;It's a lot faster to use record and<br>
playback.<br>
&nbsp;&nbsp; Let's assume you have a directory with C++ files, all ending in &quot;.cpp&quot;.<br>
There is a function called &quot;GetResp&quot; that you want to rename to &quot;GetAnswer&quot;.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim *.cpp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start Vim, defining the argument list to<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contain all the C++ files.&nbsp;&nbsp;You are now in the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;first file.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qq&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start recording into the q register<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/\&lt;GetResp\&gt;/GetAnswer/g<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do the replacements in the first file.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:wnext&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Write this file and move to the next one.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Stop recording.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@q&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Execute the q register.&nbsp;&nbsp;This will replay the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substitution and &quot;:wnext&quot;.&nbsp;&nbsp;You can verify<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that this doesn't produce an error message.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;999@q&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Execute the q register on the remaining files.<br>
<br>
At the last file you will get an error message, because &quot;:wnext&quot; cannot move<br>
to the next file.&nbsp;&nbsp;This stops the execution, and everything is done.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Todo">Note</span>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;When playing back a recorded sequence, an error stops the execution.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>
&quot;GetResp&quot;, you will get an error and replacing will stop.&nbsp;&nbsp;To avoid this, add<br>
the &quot;e&quot; flag to the substitute command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/\&lt;GetResp\&gt;/GetAnswer/ge</div>
<br>
The &quot;e&quot; flag tells &quot;:substitute&quot; 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>&nbsp;&nbsp;Change &quot;Last, First&quot; to &quot;First Last&quot;<br>
<br>
You have a list of names in this form:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Doe, John</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Smith, Peter</span><br>
<br>
You want to change that to:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">John Doe</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Peter Smith</span><br>
<br>
This can be done with just one command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/\([^,]*\), \(.*\)/\2 \1/</div>
<br>
Let's break this down in parts.&nbsp;&nbsp;Obviously it starts with a substitute<br>
command.&nbsp;&nbsp;The &quot;%&quot; is the line range, which stands for the whole file.&nbsp;&nbsp;Thus<br>
the substitution is done in every line in the file.<br>
&nbsp;&nbsp; The arguments for the substitute command are &quot;/from/to/&quot;.&nbsp;&nbsp;The slashes<br>
separate the &quot;from&quot; pattern and the &quot;to&quot; string.&nbsp;&nbsp;This is what the &quot;from&quot;<br>
pattern contains:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">\([^,]*\), \(.*\)</span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The first part between \( \) matches &quot;Last&quot;&nbsp;&nbsp;&nbsp;&nbsp; \(&nbsp;&nbsp;&nbsp;&nbsp; \)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;match anything but a comma&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[^,]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;any number of times&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matches &quot;, &quot; literally&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The second part between \( \) matches &quot;First&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\(&nbsp;&nbsp;\)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;any character&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;any number of times&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *<br>
<br>
In the &quot;to&quot; part we have &quot;\2&quot; and &quot;\1&quot;.&nbsp;&nbsp;These are called backreferences.<br>
They refer to the text matched by the &quot;\( \)&quot; parts in the pattern.&nbsp;&nbsp;&quot;\2&quot;<br>
refers to the text matched by the second &quot;\( \)&quot;, which is the &quot;First&quot; name.<br>
&quot;\1&quot; refers to the first &quot;\( \)&quot;, which is the &quot;Last&quot; name.<br>
&nbsp;&nbsp; You can use up to nine backreferences in the &quot;to&quot; part of a substitute<br>
command.&nbsp;&nbsp;&quot;\0&quot; stands for the whole matched pattern.&nbsp;&nbsp;There are a few more<br>
special items in a substitute command, see&nbsp;<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>&nbsp;&nbsp;Sort a list<br>
<br>
In a Makefile you often have a list of files.&nbsp;&nbsp;For example:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">OBJS = \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">version.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">pch.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">getopt.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">util.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">getopt1.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">inp.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">patch.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/^OBJS<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.,/^$/-1!sort</div>
<br>
This goes to the first line, where &quot;OBJS&quot; 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 &quot;!sort&quot;.&nbsp;&nbsp;That's<br>
easier to type, but more work when there are many lines.<br>
&nbsp;&nbsp; The result is this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">OBJS = \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">backup.o</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">getopt.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">getopt1.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">inp.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">patch.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">pch.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">util.o \</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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.&nbsp;&nbsp;After sorting, this is wrong!&nbsp;&nbsp;The &quot;backup.o&quot; line that was at<br>
the end didn't have a backslash.&nbsp;&nbsp;Now that it sorts to another place, it<br>
must have a backslash.<br>
&nbsp;&nbsp; The simplest solution is to add the backslash with &quot;A \<span class="Special">&lt;Esc&gt;</span>&quot;.&nbsp;&nbsp;You can<br>
keep the backslash in the last line, if you make sure an empty line comes<br>
after it.&nbsp;&nbsp;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>&nbsp;&nbsp;Reverse line order<br>
<br>
The&nbsp;<a class="Identifier" href="repeat.html#:global">:global</a>&nbsp;command can be combined with the&nbsp;<a class="Identifier" href="change.html#:move">:move</a>&nbsp;command to move all the<br>
lines before the first line, resulting in a reversed file.&nbsp;&nbsp;The command is:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:global/^/m 0</div>
<br>
Abbreviated:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:g/^/m 0</div>
<br>
The &quot;^&quot; regular expression matches the beginning of the line (even if the line<br>
is blank).&nbsp;&nbsp;The&nbsp;<a class="Identifier" href="change.html#:move">:move</a>&nbsp;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&nbsp;<a class="Identifier" href="repeat.html#:global">:global</a>&nbsp;command is not confused by the changing line numbering,<br>
<a class="Identifier" href="repeat.html#:global">:global</a>&nbsp;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.&nbsp;&nbsp;First move to above the first line and<br>
mark it with &quot;mt&quot;.&nbsp;&nbsp;Then move the cursor to the last line in the range and<br>
type:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:'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>&nbsp;&nbsp;Count words<br>
<br>
Sometimes you have to write a text with a maximum number of words.&nbsp;&nbsp;Vim can<br>
count the words for you.<br>
&nbsp;&nbsp; When the whole file is what you want to count the words in, use this<br>
command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>
&nbsp;&nbsp; The output looks like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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 &quot;g&nbsp;<span class="Special">CTRL-G</span>&quot;, move to the end of the text, type &quot;g&nbsp;<span class="Special">CTRL-G</span>&quot; again, and then<br>
use your brain to compute the difference in the word position.&nbsp;&nbsp;That's a good<br>
exercise, but there is an easier way.&nbsp;&nbsp;With Visual mode, select the text you<br>
want to count words in.&nbsp;&nbsp;Then type g&nbsp;<span class="Special">CTRL-G</span>.&nbsp;&nbsp;The result:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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&nbsp;<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>&nbsp;&nbsp;Find a man page&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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).&nbsp;&nbsp;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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;K</div>
<br>
Vim will run the external &quot;man&quot; program on the word.&nbsp;&nbsp;If the man page is<br>
found, it is displayed.&nbsp;&nbsp;This uses the normal pager to scroll through the text<br>
(mostly the &quot;more&quot; program).&nbsp;&nbsp;When you get to the end pressing&nbsp;<span class="Special">&lt;Enter&gt;</span>&nbsp;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.&nbsp;&nbsp;There is a trick to make the man page appear in a Vim<br>
window.&nbsp;&nbsp;First, load the man filetype plugin:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:runtime! ftplugin/man.vim</div>
<br>
Put this command in your vimrc file if you intend to do this often.&nbsp;&nbsp;Now you<br>
can use the &quot;:Man&quot; command to open a window on a man page:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:Man csh</div>
<br>
You can scroll around and the text is highlighted.&nbsp;&nbsp;This allows you to find<br>
the help you were looking for.&nbsp;&nbsp;Use&nbsp;<span class="Special">CTRL-W</span>&nbsp;w to jump to the window with the<br>
text you were working on.<br>
&nbsp;&nbsp; To find a man page in a specific section, put the section number first.<br>
For example, to look in section 3 for &quot;echo&quot;:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:Man 3 echo</div>
<br>
To jump to another man page, which is in the text with the typical form<br>
&quot;word(1)&quot;, press&nbsp;<span class="Special">CTRL-]</span>&nbsp;on it.&nbsp;&nbsp;Further &quot;:Man&quot; 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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\K</div>
<br>
(If you redefined the&nbsp;<span class="Special">&lt;Leader&gt;</span>, use it instead of the backslash).<br>
For example, you want to know the return value of &quot;strstr()&quot; while editing<br>
this line:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">if ( strstr (input, &quot;aap&quot;) == )</span><br>
<br>
Move the cursor to somewhere on &quot;strstr&quot; and type &quot;\K&quot;.&nbsp;&nbsp;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>&nbsp;&nbsp;Trim blanks<br>
<br>
Some people find spaces and tabs at the end of a line useless, wasteful, and<br>
ugly.&nbsp;&nbsp;To remove whitespace at the end of every line, execute the following<br>
command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/\s\+$//</div>
<br>
The line range &quot;%&quot; is used, thus this works on the whole file.&nbsp;&nbsp;The pattern<br>
that the &quot;:substitute&quot; command matches with is &quot;\s\+$&quot;.&nbsp;&nbsp;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&nbsp;<a class="Identifier" href="usr_27.html">usr_27.txt</a>.<br>
&nbsp;&nbsp; The &quot;to&quot; part of the substitute command is empty: &quot;//&quot;.&nbsp;&nbsp;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.&nbsp;&nbsp;Often these can<br>
be deleted without changing the amount of white space.&nbsp;&nbsp;But not always!<br>
Therefore, you can best do this manually.&nbsp;&nbsp;Use this search command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<br>
You cannot see it, but there is a space before a tab in this command.&nbsp;&nbsp;Thus<br>
it's &quot;/<span class="Special">&lt;Space&gt;&lt;Tab&gt;</span>&quot;.&nbsp;&nbsp; Now use &quot;x&quot; to delete the space and check that the<br>
amount of white space doesn't change.&nbsp;&nbsp;You might have to insert a tab if it<br>
does change.&nbsp;&nbsp;Type &quot;n&quot; to find the next match.&nbsp;&nbsp;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>&nbsp;&nbsp;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.&nbsp;&nbsp;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>
&nbsp;&nbsp; For example, suppose you want to edit all the C program files that contain<br>
the word &quot;frame_counter&quot;.&nbsp;&nbsp;To do this you use the command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim `grep -l frame_counter *.c`</div>
<br>
Let's look at this command in detail.&nbsp;&nbsp;The grep command searches through a set<br>
of files for a given word.&nbsp;&nbsp;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 &quot;frame_counter&quot;.&nbsp;&nbsp;Actually, this can be any<br>
regular expression.&nbsp;&nbsp;(<span class="Todo">Note</span>: What grep uses for regular expressions is not<br>
exactly the same as what Vim uses.)<br>
&nbsp;&nbsp; The entire command is enclosed in backticks (`).&nbsp;&nbsp;This tells the UNIX shell<br>
to run this command and pretend that the results were typed on the command<br>
line.&nbsp;&nbsp;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.&nbsp;&nbsp;This results in Vim<br>
editing the file list that is the output of grep.&nbsp;&nbsp;You can then use commands<br>
like &quot;:next&quot; and &quot;:first&quot; 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.&nbsp;&nbsp;You still<br>
have to find the word within the files.<br>
&nbsp;&nbsp; Vim has a built-in command that you can use to search a set of files for a<br>
given string.&nbsp;&nbsp;If you want to find all occurrences of &quot;error_string&quot; in all C<br>
program files, for example, enter the following command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:grep error_string *.c</div>
<br>
This causes Vim to search for the string &quot;error_string&quot; in all the specified<br>
files (*.c).&nbsp;&nbsp;The editor will now open the first file where a match is found<br>
and position the cursor on the first matching line.&nbsp;&nbsp;To go to the next<br>
matching line (no matter in what file it is), use the &quot;:cnext&quot; command.&nbsp;&nbsp;To go<br>
to the previous match, use the &quot;:cprev&quot; command.&nbsp;&nbsp;Use &quot;:clist&quot; to see all the<br>
matches and where they are.<br>
&nbsp;&nbsp; The &quot;:grep&quot; command uses the external commands grep (on Unix) or findstr<br>
(on Windows).&nbsp;&nbsp;You can change this by setting the option&nbsp;<a class="Type" href="options.html#'grepprg'">'grepprg'</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter:&nbsp;<a class="Identifier" href="usr_20.html">usr_20.txt</a>&nbsp;&nbsp;Typing command-line commands quickly<br>
<br>
Copyright: see&nbsp;<a class="Identifier" href="usr_01.html#manual-copyright">manual-copyright</a>&nbsp;&nbsp;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: -->
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hilarryxu/vimdoc.git
git@gitee.com:hilarryxu/vimdoc.git
hilarryxu
vimdoc
vimdoc
master

搜索帮助