代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_26 - 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_26<br />
<a name="top"></a><h1>usr_26 - 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_26.html" name="usr_26.txt">usr_26.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2006 Apr 24<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
Repeating<br>
<br>
<br>
An editing task is hardly ever unstructured. A change often needs to be made<br>
several times. In this chapter a number of useful ways to repeat a change<br>
will be explained.<br>
<br>
<a class="Identifier" href="usr_26.html#26.1">26.1</a> Repeating with Visual mode<br>
<a class="Identifier" href="usr_26.html#26.2">26.2</a> Add and subtract<br>
<a class="Identifier" href="usr_26.html#26.3">26.3</a> Making a change in many files<br>
<a class="Identifier" href="usr_26.html#26.4">26.4</a> Using Vim from a shell script<br>
<br>
Next chapter: <a class="Identifier" href="usr_27.html">usr_27.txt</a> Search commands and patterns<br>
Previous chapter: <a class="Identifier" href="usr_25.html">usr_25.txt</a> Editing formatted text<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_26.html#26.1" name="26.1">26.1</a> Repeating with Visual mode<br>
<br>
Visual mode is very handy for making a change in any sequence of lines. You<br>
can see the highlighted text, thus you can check if the correct lines are<br>
changed. But making the selection takes some typing. The "gv" command<br>
selects the same area again. This allows you to do another operation on the<br>
same text.<br>
Suppose you have some lines where you want to change "2001" to "2002" and<br>
"2000" to "2001":<br>
<br>
<span class="PreProc">The financial results for 2001 are better</span><br>
<span class="PreProc">than for 2000. The income increased by 50%,</span><br>
<span class="PreProc">even though 2001 had more rain than 2000.</span><br>
<span class="PreProc">2000 2001</span><br>
<span class="PreProc">income 45,403 66,234</span><br>
<br>
First change "2001" to "2002". Select the lines in Visual mode, and use:<br>
<br>
<div class="helpExample"> :s/2001/2002/g</div>
<br>
Now use "gv" to reselect the same text. It doesn't matter where the cursor<br>
is. Then use ":s/2000/2001/g" to make the second change.<br>
Obviously, you can repeat these changes several times.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_26.html#26.2" name="26.2">26.2</a> Add and subtract<br>
<br>
When repeating the change of one number into another, you often have a fixed<br>
offset. In the example above, one was added to each year. Instead of typing<br>
a substitute command for each year that appears, the <span class="Special">CTRL-A</span> command can be<br>
used.<br>
Using the same text as above, search for a year:<br>
<br>
<div class="helpExample"> /19[0-9][0-9]\|20[0-9][0-9]</div>
<br>
Now press <span class="Special">CTRL-A</span>. The year will be increased by one:<br>
<br>
<span class="PreProc">The financial results for 2002 are better</span><br>
<span class="PreProc">than for 2000. The income increased by 50%,</span><br>
<span class="PreProc">even though 2001 had more rain than 2000.</span><br>
<span class="PreProc">2000 2001</span><br>
<span class="PreProc">income 45,403 66,234</span><br>
<br>
Use "n" to find the next year, and press "." to repeat the <span class="Special">CTRL-A</span> ("." is a<br>
bit quicker to type). Repeat "n" and "." for all years that appear.<br>
Hint: set the <a class="Type" href="options.html#'hlsearch'">'hlsearch'</a> option to see the matches you are going to change,<br>
then you can look ahead and do it faster.<br>
<br>
Adding more than one can be done by prepending the number to <span class="Special">CTRL-A</span>. Suppose<br>
you have this list:<br>
<br>
<span class="PreProc">1. item four</span><br>
<span class="PreProc">2. item five</span><br>
<span class="PreProc">3. item six</span><br>
<br>
Move the cursor to "1." and type:<br>
<br>
<div class="helpExample"> 3 CTRL-A</div>
<br>
The "1." will change to "4.". Again, you can use "." to repeat this on the<br>
other numbers.<br>
<br>
Another example:<br>
<br>
<span class="PreProc">006 foo bar</span><br>
<span class="PreProc">007 foo bar</span><br>
<br>
Using <span class="Special">CTRL-A</span> on these numbers results in:<br>
<br>
<span class="PreProc">007 foo bar</span><br>
<span class="PreProc">010 foo bar</span><br>
<br>
7 plus one is 10? What happened here is that Vim recognized "007" as an octal<br>
number, because there is a leading zero. This notation is often used in C<br>
programs. If you do not want a number with leading zeros to be handled as<br>
octal, use this:<br>
<br>
<div class="helpExample"> :set nrformats-=octal</div>
<br>
The <span class="Special">CTRL-X</span> command does subtraction in a similar way.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_26.html#26.3" name="26.3">26.3</a> Making a change in many files<br>
<br>
Suppose you have a variable called "x_cnt" and you want to change it to<br>
"x_counter". This variable is used in several of your C files. You need to<br>
change it in all files. This is how you do it.<br>
Put all the relevant files in the argument list:<br>
<br>
<div class="helpExample"> :args *.c</div>
<br>
This finds all C files and edits the first one. Now you can perform a<br>
substitution command on all these files:<br>
<br>
<div class="helpExample"> :argdo %s/\<x_cnt\>/x_counter/ge | update</div>
<br>
The ":argdo" command takes an argument that is another command. That command<br>
will be executed on all files in the argument list.<br>
The "%s" substitute command that follows works on all lines. It finds the<br>
word "x_cnt" with "\<x_cnt\>". The "\<" and "\>" are used to match the whole<br>
word only, and not "px_cnt" or "x_cnt2".<br>
The flags for the substitute command include "g" to replace all occurrences<br>
of "x_cnt" in the same line. The "e" flag is used to avoid an error message<br>
when "x_cnt" does not appear in the file. Otherwise ":argdo" would abort on<br>
the first file where "x_cnt" was not found.<br>
The "|" separates two commands. The following "update" command writes the<br>
file only if it was changed. If no "x_cnt" was changed to "x_counter" nothing<br>
happens.<br>
<br>
There is also the ":windo" command, which executes its argument in all<br>
windows. And ":bufdo" executes its argument on all buffers. Be careful with<br>
this, because you might have more files in the buffer list than you think.<br>
Check this with the ":buffers" command (or ":ls").<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_26.html#26.4" name="26.4">26.4</a> Using Vim from a shell script<br>
<br>
Suppose you have a lot of files in which you need to change the string<br>
"-person-" to "Jones" and then print it. How do you do that? One way is to<br>
do a lot of typing. The other is to write a shell script to do the work.<br>
The Vim editor does a superb job as a screen-oriented editor when using<br>
Normal mode commands. For batch processing, however, Normal mode commands do<br>
not result in clear, commented command files; so here you will use Ex mode<br>
instead. This mode gives you a nice command-line interface that makes it easy<br>
to put into a batch file. ("Ex command" is just another name for a<br>
command-line (:) command.)<br>
The Ex mode commands you need are as follows:<br>
<br>
<div class="helpExample"> %s/-person-/Jones/g<br>
write tempfile<br>
quit</div>
<br>
You put these commands in the file "change.vim". Now to run the editor in<br>
batch mode, use this shell script:<br>
<br>
<div class="helpExample"> for file in *.txt; do<br>
vim -e -s $file < change.vim<br>
lpr -r tempfile<br>
done</div>
<br>
The for-done loop is a shell construct to repeat the two lines in between,<br>
while the $file variable is set to a different file name each time.<br>
The second line runs the Vim editor in Ex mode (-e argument) on the file<br>
$file and reads commands from the file "change.vim". The -s argument tells<br>
Vim to operate in silent mode. In other words, do not keep outputting the<br>
:prompt, or any other prompt for that matter.<br>
The "lpr -r tempfile" command prints the resulting "tempfile" and deletes<br>
it (that's what the -r argument does).<br>
<br>
<br>
READING FROM STDIN<br>
<br>
Vim can read text on standard input. Since the normal way is to read commands<br>
there, you must tell Vim to read text instead. This is done by passing the<br>
"-" argument in place of a file. Example:<br>
<br>
<div class="helpExample"> ls | vim -</div>
<br>
This allows you to edit the output of the "ls" command, without first saving<br>
the text in a file.<br>
If you use the standard input to read text from, you can use the "-S"<br>
argument to read a script:<br>
<br>
<div class="helpExample"> producer | vim -S change.vim -</div>
<br>
<br>
NORMAL MODE SCRIPTS<br>
<br>
If you really want to use Normal mode commands in a script, you can use it<br>
like this:<br>
<br>
<div class="helpExample"> vim -s script file.txt ...</div>
<br>
<span class="Todo">Note</span>:<br>
"-s" has a different meaning when it is used without "-e". Here it<br>
means to source the "script" as Normal mode commands. When used with<br>
"-e" it means to be silent, and doesn't use the next argument as a<br>
file name.<br>
<br>
The commands in "script" are executed like you typed them. Don't forget that<br>
a line break is interpreted as pressing <span class="Special"><Enter></span>. In Normal mode that moves<br>
the cursor to the next line.<br>
To create the script you can edit the script file and type the commands.<br>
You need to imagine what the result would be, which can be a bit difficult.<br>
Another way is to record the commands while you perform them manually. This<br>
is how you do that:<br>
<br>
<div class="helpExample"> vim -w script file.txt ...</div>
<br>
All typed keys will be written to "script". If you make a small mistake you<br>
can just continue and remember to edit the script later.<br>
The "-w" argument appends to an existing script. That is good when you<br>
want to record the script bit by bit. If you want to start from scratch and<br>
start all over, use the "-W" argument. It overwrites any existing file.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_27.html">usr_27.txt</a> Search commands and patterns<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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。