1 Star 0 Fork 0

hilarryxu/vimdoc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
usr_10.html 62.96 KB
一键复制 编辑 原始数据 按行查看 历史
hilarryxu 提交于 2017-08-15 10:58 . Init repo
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_10 - 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_10<br />
<a name="top"></a><h1>usr_10 - 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_10.html" name="usr_10.txt">usr_10.txt</a>&nbsp;&nbsp;&nbsp;&nbsp;For&nbsp;<span class="Identifier">Vim version 8.0.</span>&nbsp;&nbsp;Last change: 2006 Nov 05<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; Making big changes<br>
<br>
<br>
In chapter 4 several ways to make small changes were explained.&nbsp;&nbsp;This chapter<br>
goes into making changes that are repeated or can affect a large amount of<br>
text.&nbsp;&nbsp;The Visual mode allows doing various things with blocks of text.&nbsp;&nbsp;Use<br>
an external program to do really complicated things.<br>
<br>
<a class="Identifier" href="usr_10.html#10.1">10.1</a>&nbsp;&nbsp;Record and playback commands<br>
<a class="Identifier" href="usr_10.html#10.2">10.2</a>&nbsp;&nbsp;Substitution<br>
<a class="Identifier" href="usr_10.html#10.3">10.3</a>&nbsp;&nbsp;Command ranges<br>
<a class="Identifier" href="usr_10.html#10.4">10.4</a>&nbsp;&nbsp;The global command<br>
<a class="Identifier" href="usr_10.html#10.5">10.5</a>&nbsp;&nbsp;Visual block mode<br>
<a class="Identifier" href="usr_10.html#10.6">10.6</a>&nbsp;&nbsp;Reading and writing part of a file<br>
<a class="Identifier" href="usr_10.html#10.7">10.7</a>&nbsp;&nbsp;Formatting text<br>
<a class="Identifier" href="usr_10.html#10.8">10.8</a>&nbsp;&nbsp;Changing case<br>
<a class="Identifier" href="usr_10.html#10.9">10.9</a>&nbsp;&nbsp;Using an external program<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Next chapter:&nbsp;<a class="Identifier" href="usr_11.html">usr_11.txt</a>&nbsp;&nbsp;Recovering from a crash<br>
&nbsp;Previous chapter:&nbsp;<a class="Identifier" href="usr_09.html">usr_09.txt</a>&nbsp;&nbsp;Using the GUI<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_10.html#10.1" name="10.1">10.1</a>&nbsp;&nbsp;Record and playback commands<br>
<br>
The &quot;.&quot; command repeats the preceding change.&nbsp;&nbsp;But what if you want to do<br>
something more complex than a single change?&nbsp;&nbsp;That's where command recording<br>
comes in.&nbsp;&nbsp;There are three steps:<br>
<br>
1. The &quot;q<span class="Special">{register}</span>&quot; command starts recording keystrokes into the register<br>
&nbsp;&nbsp; named&nbsp;<span class="Special">{register}</span>.&nbsp;&nbsp;The register name must be between a and z.<br>
2. Type your commands.<br>
3. To finish recording, press q (without any extra character).<br>
<br>
You can now execute the macro by typing the command &quot;@<span class="Special">{register}</span>&quot;.<br>
<br>
Take a look at how to use these commands in practice.&nbsp;&nbsp;You have a list of<br>
filenames that look like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">stdio.h</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">fcntl.h</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">unistd.h</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">stdlib.h</span><br>
<br>
And what you want is the following:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">#include &quot;stdio.h&quot;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">#include &quot;fcntl.h&quot;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">#include &quot;unistd.h&quot;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">#include &quot;stdlib.h&quot;</span><br>
<br>
You start by moving to the first character of the first line.&nbsp;&nbsp;Next you<br>
execute the following commands:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qa&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start recording a macro in register a.<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; Move to the beginning of the line.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i#include &quot;<span class="Special">&lt;Esc&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insert the string #include &quot; at the beginning<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;of the line.<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; Move to the end of the line.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&quot;<span class="Special">&lt;Esc&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Append the character double quotation mark (&quot;)<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;to the end of the line.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Go to the next line.<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 the macro.<br>
<br>
Now that you have done the work once, you can repeat the change by typing the<br>
command &quot;@a&quot; three times.<br>
&nbsp;&nbsp; The &quot;@a&quot; command can be preceded by a count, which will cause the macro to<br>
be executed that number of times.&nbsp;&nbsp;In this case you would type:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3@a</div>
<br>
<br>
MOVE AND EXECUTE<br>
<br>
You might have the lines you want to change in various places.&nbsp;&nbsp;Just move the<br>
cursor to each location and use the &quot;@a&quot; command.&nbsp;&nbsp;If you have done that once,<br>
you can do it again with &quot;@@&quot;.&nbsp;&nbsp;That's a bit easier to type.&nbsp;&nbsp;If you now<br>
execute register b with &quot;@b&quot;, the next &quot;@@&quot; will use register b.<br>
&nbsp;&nbsp; If you compare the playback method with using &quot;.&quot;, there are several<br>
differences.&nbsp;&nbsp;First of all, &quot;.&quot; can only repeat one change.&nbsp;&nbsp;As seen in the<br>
example above, &quot;@a&quot; can do several changes, and move around as well.<br>
Secondly, &quot;.&quot; can only remember the last change.&nbsp;&nbsp;Executing a register allows<br>
you to make any changes and then still use &quot;@a&quot; to replay the recorded<br>
commands.&nbsp;&nbsp;Finally, you can use 26 different registers.&nbsp;&nbsp;Thus you can remember<br>
26 different command sequences to execute.<br>
<br>
<br>
USING REGISTERS<br>
<br>
The registers used for recording are the same ones you used for yank and<br>
delete commands.&nbsp;&nbsp;This allows you to mix recording with other commands to<br>
manipulate the registers.<br>
&nbsp;&nbsp; Suppose you have recorded a few commands in register n.&nbsp;&nbsp;When you execute<br>
this with &quot;@n&quot; you notice you did something wrong.&nbsp;&nbsp;You could try recording<br>
again, but perhaps you will make another mistake.&nbsp;&nbsp;Instead, use this trick:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Go to the end of the file.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;o<span class="Special">&lt;Esc&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Create an empty line.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;np&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Put the text from the n register.&nbsp;&nbsp;You now see<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;the commands you typed as text in the file.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">{edits}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Change the commands that were wrong.&nbsp;&nbsp;This is<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;just like editing text.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Go to the start of the line.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;ny$&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Yank the corrected commands into the n<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;register.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delete the scratch line.<br>
<br>
Now you can execute the corrected commands with &quot;@n&quot;.&nbsp;&nbsp;(If your recorded<br>
commands include line breaks, adjust the last two items in the example to<br>
include all the lines.)<br>
<br>
<br>
APPENDING TO A REGISTER<br>
<br>
So far we have used a lowercase letter for the register name.&nbsp;&nbsp;To append to a<br>
register, use an uppercase letter.<br>
&nbsp;&nbsp; Suppose you have recorded a command to change a word to register c.&nbsp;&nbsp;It<br>
works properly, but you would like to add a search for the next word to<br>
change.&nbsp;&nbsp;This can be done with:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qC/word&lt;Enter&gt;q</div>
<br>
You start with &quot;qC&quot;, which records to the c register and appends.&nbsp;&nbsp;Thus<br>
writing to an uppercase register name means to append to the register with<br>
the same letter, but lowercase.<br>
<br>
This works both with recording and with yank and delete commands.&nbsp;&nbsp;For<br>
example, you want to collect a sequence of lines into the a register.&nbsp;&nbsp;Yank<br>
the first line with:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;aY</div>
<br>
Now move to the second line, and type:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;AY</div>
<br>
Repeat this command for all lines.&nbsp;&nbsp;The a register now contains all those<br>
lines, in the order you yanked them.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_10.html#10.2" name="10.2">10.2</a>&nbsp;&nbsp;Substitution&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;<a class="Constant" href="usr_10.html#find-replace" name="find-replace">find-replace</a><br>
<br>
The &quot;:substitute&quot; command enables you to perform string replacements on a<br>
whole range of lines.&nbsp;&nbsp;The general form of this command is as follows:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:[range]substitute/from/to/[flags]</div>
<br>
This command changes the &quot;from&quot; string to the &quot;to&quot; string in the lines<br>
specified with&nbsp;<span class="Special">[range]</span>.&nbsp;&nbsp;For example, you can change &quot;Professor&quot; to &quot;Teacher&quot;<br>
in all lines with the following command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%substitute/Professor/Teacher/</div>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Todo">Note</span>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The &quot;:substitute&quot; command is almost never spelled out completely.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Most of the time, people use the abbreviated version &quot;:s&quot;.&nbsp;&nbsp;From here<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on the abbreviation will be used.<br>
<br>
The &quot;%&quot; before the command specifies the command works on all lines.&nbsp;&nbsp;Without<br>
a range, &quot;:s&quot; only works on the current line.&nbsp;&nbsp;More about ranges in the next<br>
section&nbsp;<a class="Identifier" href="usr_10.html#10.3">10.3</a>.<br>
<br>
By default, the &quot;:substitute&quot; command changes only the first occurrence on<br>
each line.&nbsp;&nbsp;For example, the preceding command changes the line:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Professor Smith criticized Professor Johnson today.</span><br>
<br>
to:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Teacher Smith criticized Professor Johnson today.</span><br>
<br>
To change every occurrence on the line, you need to add the g (global) flag.<br>
The command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/Professor/Teacher/g</div>
<br>
results in (starting with the original line):<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Teacher Smith criticized Teacher Johnson today.</span><br>
<br>
Other flags include p (print), which causes the &quot;:substitute&quot; command to print<br>
out the last line it changes.&nbsp;&nbsp;The c (confirm) flag tells &quot;:substitute&quot; to ask<br>
you for confirmation before it performs each substitution.&nbsp;&nbsp;Enter the<br>
following:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%s/Professor/Teacher/c</div>
<br>
Vim finds the first occurrence of &quot;Professor&quot; and displays the text it is<br>
about to change.&nbsp;&nbsp;You get the following prompt:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replace with Teacher (y/n/a/q/l/^E/^Y)?</div>
<br>
At this point, you must enter one of the following answers:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Yes; make this change.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; No; skip this match.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; All; make this change and all remaining ones without<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;further confirmation.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Quit; don't make any more changes.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Last; make this change and then quit.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">CTRL-E</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scroll the text one line up.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">CTRL-Y</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scroll the text one line down.<br>
<br>
<br>
The &quot;from&quot; part of the substitute command is actually a pattern.&nbsp;&nbsp;The same<br>
kind as used for the search command.&nbsp;&nbsp;For example, this command only<br>
substitutes &quot;the&quot; when it appears at the start of a line:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:s/^the/these/</div>
<br>
If you are substituting with a &quot;from&quot; or &quot;to&quot; part that includes a slash, you<br>
need to put a backslash before it.&nbsp;&nbsp;A simpler way is to use another character<br>
instead of the slash.&nbsp;&nbsp;A plus, for example:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:s+one/two+one or two+</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_10.html#10.3" name="10.3">10.3</a>&nbsp;&nbsp;Command ranges<br>
<br>
The &quot;:substitute&quot; command, and many other : commands, can be applied to a<br>
selection of lines.&nbsp;&nbsp;This is called a range.<br>
&nbsp;&nbsp; The simple form of a range is&nbsp;<span class="Special">{number}</span>,<span class="Special">{number}</span>.&nbsp;&nbsp;For example:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:1,5s/this/that/g</div>
<br>
Executes the substitute command on the lines 1 to 5.&nbsp;&nbsp;Line 5 is included.<br>
The range is always placed before the command.<br>
<br>
A single number can be used to address one specific line:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:54s/President/Fool/</div>
<br>
Some commands work on the whole file when you do not specify a range.&nbsp;&nbsp;To make<br>
them work on the current line the &quot;.&quot; address is used.&nbsp;&nbsp;The &quot;:write&quot; command<br>
works like that.&nbsp;&nbsp;Without a range, it writes the whole file.&nbsp;&nbsp;To make it write<br>
only the current line into a file:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.write otherfile</div>
<br>
The first line always has number one.&nbsp;&nbsp;How about the last line?&nbsp;&nbsp;The &quot;$&quot;<br>
character is used for this.&nbsp;&nbsp;For example, to substitute in the lines from the<br>
cursor to the end:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.,$s/yes/no/</div>
<br>
The &quot;%&quot; range that we used before, is actually a short way to say &quot;1,$&quot;, from<br>
the first to the last line.<br>
<br>
<br>
USING A PATTERN IN A RANGE<br>
<br>
Suppose you are editing a chapter in a book, and want to replace all<br>
occurrences of &quot;grey&quot; with &quot;gray&quot;.&nbsp;&nbsp;But only in this chapter, not in the next<br>
one.&nbsp;&nbsp;You know that only chapter boundaries have the word &quot;Chapter&quot; in the<br>
first column.&nbsp;&nbsp;This command will work then:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:?^Chapter?,/^Chapter/s=grey=gray=g</div>
<br>
You can see a search pattern is used twice.&nbsp;&nbsp;The first &quot;?^Chapter?&quot; finds the<br>
line above the current position that matches this pattern.&nbsp;&nbsp;Thus the ?pattern?<br>
range is used to search backwards.&nbsp;&nbsp;Similarly, &quot;/^Chapter/&quot; is used to search<br>
forward for the start of the next chapter.<br>
&nbsp;&nbsp; To avoid confusion with the slashes, the &quot;=&quot; character was used in the<br>
substitute command here.&nbsp;&nbsp;A slash or another character would have worked as<br>
well.<br>
<br>
<br>
ADD AND SUBTRACT<br>
<br>
There is a slight error in the above command: If the title of the next chapter<br>
had included &quot;grey&quot; it would be replaced as well.&nbsp;&nbsp;Maybe that's what you<br>
wanted, but what if you didn't?&nbsp;&nbsp;Then you can specify an offset.<br>
&nbsp;&nbsp; To search for a pattern and then use the line above it:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/Chapter/-1</div>
<br>
You can use any number instead of the 1.&nbsp;&nbsp;To address the second line below the<br>
match:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/Chapter/+2</div>
<br>
The offsets can also be used with the other items in a range.&nbsp;&nbsp;Look at this<br>
one:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.+3,$-5</div>
<br>
This specifies the range that starts three lines below the cursor and ends<br>
five lines before the last line in the file.<br>
<br>
<br>
USING MARKS<br>
<br>
Instead of figuring out the line numbers of certain positions, remembering them<br>
and typing them in a range, you can use marks.<br>
&nbsp;&nbsp; Place the marks as mentioned in chapter 3.&nbsp;&nbsp;For example, use &quot;mt&quot; to mark<br>
the top of an area and &quot;mb&quot; to mark the bottom.&nbsp;&nbsp;Then you can use this range<br>
to specify the lines between the marks (including the lines with the marks):<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:'t,'b</div>
<br>
<br>
VISUAL MODE AND RANGES<br>
<br>
You can select text with Visual mode.&nbsp;&nbsp;If you then press &quot;:&quot; to start a colon<br>
command, you will see this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:'&lt;,'&gt;</div>
<br>
Now you can type the command and it will be applied to the range of lines that<br>
was visually selected.<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 using Visual mode to select part of a line, or using&nbsp;<span class="Special">CTRL-V</span>&nbsp;to<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select a block of text, the colon commands will still apply to whole<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lines.&nbsp;&nbsp;This might change in a future version of Vim.<br>
<br>
The '&lt; and '&gt; are actually marks, placed at the start and end of the Visual<br>
selection.&nbsp;&nbsp;The marks remain at their position until another Visual selection<br>
is made.&nbsp;&nbsp;Thus you can use the &quot;'&lt;&quot; command to jump to position where the<br>
Visual area started.&nbsp;&nbsp;And you can mix the marks with other items:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:'&gt;,$</div>
<br>
This addresses the lines from the end of the Visual area to the end of the<br>
file.<br>
<br>
<br>
A NUMBER OF LINES<br>
<br>
When you know how many lines you want to change, you can type the number and<br>
then &quot;:&quot;.&nbsp;&nbsp;For example, when you type &quot;5:&quot;, you will get:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.,.+4</div>
<br>
Now you can type the command you want to use.&nbsp;&nbsp;It will use the range &quot;.&quot;<br>
(current line) until &quot;.+4&quot; (four lines down).&nbsp;&nbsp;Thus it spans five lines.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_10.html#10.4" name="10.4">10.4</a>&nbsp;&nbsp;The global command<br>
<br>
The &quot;:global&quot; command is one of the more powerful features of Vim.&nbsp;&nbsp;It allows<br>
you to find a match for a pattern and execute a command there.&nbsp;&nbsp;The general<br>
form is:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:[range]global/{pattern}/{command}</div>
<br>
This is similar to the &quot;:substitute&quot; command.&nbsp;&nbsp;But, instead of replacing the<br>
matched text with other text, the command&nbsp;<span class="Special">{command}</span>&nbsp;is executed.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Todo">Note</span>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The command executed for &quot;:global&quot; must be one that starts with a<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;colon.&nbsp;&nbsp;Normal mode commands can not be used directly.&nbsp;&nbsp;The&nbsp;<a class="Identifier" href="various.html#:normal">:normal</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command can do this for you.<br>
<br>
Suppose you want to change &quot;foobar&quot; to &quot;barfoo&quot;, but only in C++ style<br>
comments.&nbsp;&nbsp;These comments start with &quot;//&quot;.&nbsp;&nbsp;Use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:g+//+s/foobar/barfoo/g</div>
<br>
This starts with &quot;:g&quot;.&nbsp;&nbsp;That is short for &quot;:global&quot;, just like &quot;:s&quot; is short<br>
for &quot;:substitute&quot;.&nbsp;&nbsp;Then the pattern, enclosed in plus characters.&nbsp;&nbsp;Since the<br>
pattern we are looking for contains a slash, this uses the plus character to<br>
separate the pattern.&nbsp;&nbsp;Next comes the substitute command that changes &quot;foobar&quot;<br>
into &quot;barfoo&quot;.<br>
&nbsp;&nbsp; The default range for the global command is the whole file.&nbsp;&nbsp;Thus no range<br>
was specified in this example.&nbsp;&nbsp;This is different from &quot;:substitute&quot;, which<br>
works on one line without a range.<br>
&nbsp;&nbsp; The command isn't perfect, since it also matches lines where &quot;//&quot; appears<br>
halfway a line, and the substitution will also take place before the &quot;//&quot;.<br>
<br>
Just like with &quot;:substitute&quot;, any pattern can be used.&nbsp;&nbsp;When you learn more<br>
complicated patterns later, you can use them here.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_10.html#10.5" name="10.5">10.5</a>&nbsp;&nbsp;Visual block mode<br>
<br>
With&nbsp;<span class="Special">CTRL-V</span>&nbsp;you can start selection of a rectangular area of text.&nbsp;&nbsp;There are<br>
a few commands that do something special with the text block.<br>
<br>
There is something special about using the &quot;$&quot; command in Visual block mode.<br>
When the last motion command used was &quot;$&quot;, all lines in the Visual selection<br>
will extend until the end of the line, also when the line with the cursor is<br>
shorter.&nbsp;&nbsp;This remains effective until you use a motion command that moves the<br>
cursor horizontally.&nbsp;&nbsp;Thus using &quot;j&quot; keeps it, &quot;h&quot; stops it.<br>
<br>
<br>
INSERTING TEXT<br>
<br>
The command&nbsp;&nbsp;&quot;I<span class="Special">{string}&lt;Esc&gt;</span>&quot; inserts the text&nbsp;<span class="Special">{string}</span>&nbsp;in each line, just<br>
left of the visual block.&nbsp;&nbsp;You start by pressing&nbsp;<span class="Special">CTRL-V</span>&nbsp;to enter visual block<br>
mode.&nbsp;&nbsp;Now you move the cursor to define your block.&nbsp;&nbsp;Next you type I to enter<br>
Insert mode, followed by the text to insert.&nbsp;&nbsp;As you type, the text appears on<br>
the first line only.<br>
&nbsp;&nbsp; After you press&nbsp;<span class="Special">&lt;Esc&gt;</span>&nbsp;to end the insert, the text will magically be<br>
inserted in the rest of the lines contained in the visual selection.&nbsp;&nbsp;Example:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">include one</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">include two</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">include three</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">include four</span><br>
<br>
Move the cursor to the &quot;o&quot; of &quot;one&quot; and press&nbsp;<span class="Special">CTRL-V</span>.&nbsp;&nbsp;Move it down with &quot;3j&quot;<br>
to &quot;four&quot;.&nbsp;&nbsp;You now have a block selection that spans four lines.&nbsp;&nbsp;Now type:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Imain.&lt;Esc&gt;</div>
<br>
The result:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">include main.one</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">include main.two</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">include main.three</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">include main.four</span><br>
<br>
If the block spans short lines that do not extend into the block, the text is<br>
not inserted in that line.&nbsp;&nbsp;For example, make a Visual block selection that<br>
includes the word &quot;long&quot; in the first and last line of this text, and thus has<br>
no text selected in the second line:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">This is a long line</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">short</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Any other long line</span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^ selected block<br>
<br>
Now use the command &quot;Ivery&nbsp;<span class="Special">&lt;Esc&gt;</span>&quot;.&nbsp;&nbsp;The result is:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">This is a very long line</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">short</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Any other very long line</span><br>
<br>
In the short line no text was inserted.<br>
<br>
If the string you insert contains a newline, the &quot;I&quot; acts just like a Normal<br>
insert command and affects only the first line of the block.<br>
<br>
The &quot;A&quot; command works the same way, except that it appends after the right<br>
side of the block.&nbsp;&nbsp;And it does insert text in a short line.&nbsp;&nbsp;Thus you can<br>
make a choice whether you do or don't want to append text to a short line.<br>
&nbsp;&nbsp; There is one special case for &quot;A&quot;: Select a Visual block and then use &quot;$&quot;<br>
to make the block extend to the end of each line.&nbsp;&nbsp;Using &quot;A&quot; now will append<br>
the text to the end of each line.<br>
&nbsp;&nbsp; Using the same example from above, and then typing &quot;$A XXX<span class="Special">&lt;Esc&gt;</span>, you get<br>
this result:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">This is a long line XXX</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">short XXX</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Any other long line XXX</span><br>
<br>
This really requires using the &quot;$&quot; command.&nbsp;&nbsp;Vim remembers that it was used.<br>
Making the same selection by moving the cursor to the end of the longest line<br>
with other movement commands will not have the same result.<br>
<br>
<br>
CHANGING TEXT<br>
<br>
The Visual block &quot;c&quot; command deletes the block and then throws you into Insert<br>
mode to enable you to type in a string.&nbsp;&nbsp;The string will be inserted in each<br>
line in the block.<br>
&nbsp;&nbsp; Starting with the same selection of the &quot;long&quot; words as above, then typing<br>
&quot;c_LONG_<span class="Special">&lt;Esc&gt;</span>&quot;, you get this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">This is a _LONG_ line</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">short</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Any other _LONG_ line</span><br>
<br>
Just like with &quot;I&quot; the short line is not changed.&nbsp;&nbsp;Also, you can't enter a<br>
newline in the new text.<br>
<br>
The &quot;C&quot; command deletes text from the left edge of the block to the end of<br>
line.&nbsp;&nbsp;It then puts you in Insert mode so that you can type in a string,<br>
which is added to the end of each line.<br>
&nbsp;&nbsp; Starting with the same text again, and typing &quot;Cnew text<span class="Special">&lt;Esc&gt;</span>&quot; you get:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">This is a new text</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">short</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Any other new text</span><br>
<br>
Notice that, even though only the &quot;long&quot; word was selected, the text after it<br>
is deleted as well.&nbsp;&nbsp;Thus only the location of the left edge of the visual<br>
block really matters.<br>
&nbsp;&nbsp; Again, short lines that do not reach into the block are excluded.<br>
<br>
Other commands that change the characters in the block:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; swap case&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (a -&gt; A and A -&gt; a)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; make uppercase&nbsp;&nbsp;(a -&gt; A and A -&gt; A)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; make lowercase&nbsp;&nbsp;(a -&gt; a and A -&gt; a)<br>
<br>
<br>
FILLING WITH A CHARACTER<br>
<br>
To fill the whole block with one character, use the &quot;r&quot; command.&nbsp;&nbsp;Again,<br>
starting with the same example text from above, and then typing &quot;rx&quot;:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">This is a xxxx line</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">short</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Any other xxxx line</span><br>
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Todo">Note</span>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If you want to include characters beyond the end of the line in the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;block, check out the&nbsp;<a class="Type" href="options.html#'virtualedit'">'virtualedit'</a>&nbsp;feature in chapter 25.<br>
<br>
<br>
SHIFTING<br>
<br>
The command &quot;&gt;&quot; shifts the selected text to the right one shift amount,<br>
inserting whitespace.&nbsp;&nbsp;The starting point for this shift is the left edge of<br>
the visual block.<br>
&nbsp;&nbsp; With the same example again, &quot;&gt;&quot; gives this result:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">This is a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long line</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">short</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Any other&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long line</span><br>
<br>
The shift amount is specified with the&nbsp;<a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a>&nbsp;option.&nbsp;&nbsp;To change it to<br>
use 4 spaces:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set shiftwidth=4</div>
<br>
The &quot;&lt;&quot; command removes one shift amount of whitespace at the left<br>
edge of the block.&nbsp;&nbsp;This command is limited by the amount of text that is<br>
there; so if there is less than a shift amount of whitespace available, it<br>
removes what it can.<br>
<br>
<br>
JOINING LINES<br>
<br>
The &quot;J&quot; command joins all selected lines together into one line.&nbsp;&nbsp;Thus it<br>
removes the line breaks.&nbsp;&nbsp;Actually, the line break, leading white space and<br>
trailing white space is replaced by one space.&nbsp;&nbsp;Two spaces are used after a<br>
line ending (that can be changed with the&nbsp;<a class="Type" href="options.html#'joinspaces'">'joinspaces'</a>&nbsp;option).<br>
&nbsp;&nbsp; Let's use the example that we got so familiar with now.&nbsp;&nbsp;The result of<br>
using the &quot;J&quot; command:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">This is a long line short Any other long line</span><br>
<br>
The &quot;J&quot; command doesn't require a blockwise selection.&nbsp;&nbsp;It works with &quot;v&quot; and<br>
&quot;V&quot; selection in exactly the same way.<br>
<br>
If you don't want the white space to be changed, use the &quot;gJ&quot; command.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_10.html#10.6" name="10.6">10.6</a>&nbsp;&nbsp;Reading and writing part of a file<br>
<br>
When you are writing an e-mail message, you may want to include another file.<br>
This can be done with the &quot;:read&nbsp;<span class="Special">{filename}</span>&quot; command.&nbsp;&nbsp;The text of the file is<br>
put below the cursor line.<br>
&nbsp;&nbsp; Starting with this text:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Hi John,</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Here is the diff that fixes the bug:</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Bye, Pierre.</span><br>
<br>
Move the cursor to the second line and type:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:read patch</div>
<br>
The file named &quot;patch&quot; will be inserted, with this result:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Hi John,</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Here is the diff that fixes the bug:</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">2c2</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&lt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt;= length; ++i)</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">---</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; length; ++i)</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Bye, Pierre.</span><br>
<br>
The &quot;:read&quot; command accepts a range.&nbsp;&nbsp;The file will be put below the last line<br>
number of this range.&nbsp;&nbsp;Thus &quot;:$r patch&quot; appends the file &quot;patch&quot; at the end of<br>
the file.<br>
&nbsp;&nbsp; What if you want to read the file above the first line?&nbsp;&nbsp;This can be done<br>
with the line number zero.&nbsp;&nbsp;This line doesn't really exist, you will get an<br>
error message when using it with most commands.&nbsp;&nbsp;But this command is allowed:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:0read patch</div>
<br>
The file &quot;patch&quot; will be put above the first line of the file.<br>
<br>
<br>
WRITING A RANGE OF LINES<br>
<br>
To write a range of lines to a file, the &quot;:write&quot; command can be used.<br>
Without a range it writes the whole file.&nbsp;&nbsp;With a range only the specified<br>
lines are written:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.,$write tempo</div>
<br>
This writes the lines from the cursor until the end of the file into the file<br>
&quot;tempo&quot;.&nbsp;&nbsp;If this file already exists you will get an error message.&nbsp;&nbsp;Vim<br>
protects you from accidentally overwriting an existing file.&nbsp;&nbsp;If you know what<br>
you are doing and want to overwrite the file, append !:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.,$write! tempo</div>
<br>
CAREFUL: The ! must follow the &quot;:write&quot; command immediately, without white<br>
space.&nbsp;&nbsp;Otherwise it becomes a filter command, which is explained later in<br>
this chapter.<br>
<br>
<br>
APPENDING TO A FILE<br>
<br>
In the first section of this chapter was explained how to collect a number of<br>
lines into a register.&nbsp;&nbsp;The same can be done to collect lines in a file.<br>
Write the first line with this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.write collection</div>
<br>
Now move the cursor to the second line you want to collect, and type this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:.write &gt;&gt;collection</div>
<br>
The &quot;&gt;&gt;&quot; tells Vim the &quot;collection&quot; file is not to be written as a new file,<br>
but the line must be appended at the end.&nbsp;&nbsp; You can repeat this as many times<br>
as you like.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_10.html#10.7" name="10.7">10.7</a>&nbsp;&nbsp;Formatting text<br>
<br>
When you are typing plain text, it's nice if the length of each line is<br>
automatically trimmed to fit in the window.&nbsp;&nbsp;To make this happen while<br>
inserting text, set the&nbsp;<a class="Type" href="options.html#'textwidth'">'textwidth'</a>&nbsp;option:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set textwidth=72</div>
<br>
You might remember that in the example vimrc file this command was used for<br>
every text file.&nbsp;&nbsp;Thus if you are using that vimrc file, you were already<br>
using it.&nbsp;&nbsp;To check the current value of&nbsp;<a class="Type" href="options.html#'textwidth'">'textwidth'</a>:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set textwidth</div>
<br>
Now lines will be broken to take only up to 72 characters.&nbsp;&nbsp;But when you<br>
insert text halfway a line, or when you delete a few words, the lines will get<br>
too long or too short.&nbsp;&nbsp;Vim doesn't automatically reformat the text.<br>
&nbsp;&nbsp; To tell Vim to format the current paragraph:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gqap</div>
<br>
This starts with the &quot;gq&quot; command, which is an operator.&nbsp;&nbsp;Following is &quot;ap&quot;,<br>
the text object that stands for &quot;a paragraph&quot;.&nbsp;&nbsp;A paragraph is separated from<br>
the next paragraph by an empty line.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Todo">Note</span>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A blank line, which contains white space, does NOT separate<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paragraphs.&nbsp;&nbsp;This is hard to notice!<br>
<br>
Instead of &quot;ap&quot; you could use any motion or text object.&nbsp;&nbsp;If your paragraphs<br>
are properly separated, you can use this command to format the whole file:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gggqG</div>
<br>
&quot;gg&quot; takes you to the first line, &quot;gq&quot; is the format operator and &quot;G&quot; the<br>
motion that jumps to the last line.<br>
<br>
In case your paragraphs aren't clearly defined, you can format just the lines<br>
you manually select.&nbsp;&nbsp;Move the cursor to the first line you want to format.<br>
Start with the command &quot;gqj&quot;.&nbsp;&nbsp;This formats the current line and the one below<br>
it.&nbsp;&nbsp;If the first line was short, words from the next line will be appended.<br>
If it was too long, words will be moved to the next line.&nbsp;&nbsp;The cursor moves to<br>
the second line.&nbsp;&nbsp;Now you can use &quot;.&quot; to repeat the command.&nbsp;&nbsp;Keep doing this<br>
until you are at the end of the text you want to format.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_10.html#10.8" name="10.8">10.8</a>&nbsp;&nbsp;Changing case<br>
<br>
You have text with section headers in lowercase.&nbsp;&nbsp;You want to make the word<br>
&quot;section&quot; all uppercase.&nbsp;&nbsp;Do this with the &quot;gU&quot; operator.&nbsp;&nbsp;Start with the<br>
cursor in the first column:<br>
<br>
<div class="helpExample">&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; gUw</div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; section header&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SECTION header<br>
<br>
The &quot;gu&quot; operator does exactly the opposite:<br>
<br>
<div class="helpExample">&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; guw</div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SECTION header&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;section header<br>
<br>
You can also use &quot;g~&quot; to swap case.&nbsp;&nbsp;All these are operators, thus they work<br>
with any motion command, with text objects and in Visual mode.<br>
&nbsp;&nbsp; To make an operator work on lines you double it.&nbsp;&nbsp;The delete operator is<br>
&quot;d&quot;, thus to delete a line you use &quot;dd&quot;.&nbsp;&nbsp;Similarly, &quot;gugu&quot; makes a whole line<br>
lowercase.&nbsp;&nbsp;This can be shortened to &quot;guu&quot;.&nbsp;&nbsp;&quot;gUgU&quot; is shortened to &quot;gUU&quot; and<br>
&quot;g~g~&quot; to &quot;g~~&quot;.&nbsp;&nbsp;Example:<br>
<br>
<div class="helpExample">&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;g~~&nbsp;</div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Some GIRLS have Fun&nbsp;&nbsp;&nbsp;&nbsp;----&gt;&nbsp;&nbsp; sOME girls HAVE fUN</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_10.html#10.9" name="10.9">10.9</a>&nbsp;&nbsp;Using an external program<br>
<br>
Vim has a very powerful set of commands, it can do anything.&nbsp;&nbsp;But there may<br>
still be something that an external command can do better or faster.<br>
&nbsp;&nbsp; The command &quot;!<span class="Special">{motion}{program}</span>&quot; takes a block of text and filters it<br>
through an external program.&nbsp;&nbsp;In other words, it runs the system command<br>
represented by&nbsp;<span class="Special">{program}</span>, giving it the block of text represented by&nbsp;<span class="Special">{motion}</span><br>
as input.&nbsp;&nbsp;The output of this command then replaces the selected block.<br>
&nbsp;&nbsp; Because this summarizes badly if you are unfamiliar with UNIX filters, take<br>
a look at an example.&nbsp;&nbsp;The sort command sorts a file.&nbsp;&nbsp;If you execute the<br>
following command, the unsorted file input.txt will be sorted and written to<br>
output.txt.&nbsp;&nbsp;(This works on both UNIX and Microsoft Windows.)<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort &lt;input.txt &gt;output.txt</div>
<br>
Now do the same thing in Vim.&nbsp;&nbsp;You want to sort lines 1 through 5 of a file.<br>
You start by putting the cursor on line 1.&nbsp;&nbsp;Next you execute the following<br>
command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!5G</div>
<br>
The &quot;!&quot; tells Vim that you are performing a filter operation.&nbsp;&nbsp;The Vim editor<br>
expects a motion command to follow, indicating which part of the file to<br>
filter.&nbsp;&nbsp;The &quot;5G&quot; command tells Vim to go to line 5, so it now knows that it<br>
is to filter lines 1 (the current line) through 5.<br>
&nbsp;&nbsp; In anticipation of the filtering, the cursor drops to the bottom of the<br>
screen and a ! prompt displays.&nbsp;&nbsp;You can now type in the name of the filter<br>
program, in this case &quot;sort&quot;.&nbsp;&nbsp;Therefore, your full command is as follows:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!5Gsort&lt;Enter&gt;</div>
<br>
The result is that the sort program is run on the first 5 lines.&nbsp;&nbsp;The output<br>
of the program replaces these lines.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line 55&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 11<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line 33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 22<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line 11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 33<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line 22&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 44<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line 44&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 55<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;last line&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last line<br>
<br>
The &quot;!!&quot; command filters the current line through a filter.&nbsp;&nbsp;In Unix the &quot;date&quot;<br>
command prints the current time and date.&nbsp;&nbsp;&quot;!!date<span class="Special">&lt;Enter&gt;</span>&quot; replaces the current<br>
line with the output of &quot;date&quot;.&nbsp;&nbsp;This is useful to add a timestamp to a file.<br>
<br>
<br>
WHEN IT DOESN'T WORK<br>
<br>
Starting a shell, sending it text and capturing the output requires that Vim<br>
knows how the shell works exactly.&nbsp;&nbsp;When you have problems with filtering,<br>
check the values of these options:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="Type" href="options.html#'shell'">'shell'</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; specifies the program that Vim uses to execute<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;external programs.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="Type" href="options.html#'shellcmdflag'">'shellcmdflag'</a>&nbsp;&nbsp;argument to pass a command to the shell<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="Type" href="options.html#'shellquote'">'shellquote'</a>&nbsp;&nbsp;&nbsp;&nbsp;quote to be used around the command<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="Type" href="options.html#'shellxquote'">'shellxquote'</a>&nbsp;&nbsp; quote to be used around the command and redirection<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="Type" href="options.html#'shelltype'">'shelltype'</a>&nbsp;&nbsp;&nbsp;&nbsp; kind of shell (only for the Amiga)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="Type" href="options.html#'shellslash'">'shellslash'</a>&nbsp;&nbsp;&nbsp;&nbsp;use forward slashes in the command (only for<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;MS-Windows and alikes)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="Type" href="options.html#'shellredir'">'shellredir'</a>&nbsp;&nbsp;&nbsp;&nbsp;string used to write the command output into a file<br>
<br>
On Unix this is hardly ever a problem, because there are two kinds of shells:<br>
&quot;sh&quot; like and &quot;csh&quot; like.&nbsp;&nbsp;Vim checks the&nbsp;<a class="Type" href="options.html#'shell'">'shell'</a>&nbsp;option and sets related<br>
options automatically, depending on whether it sees &quot;csh&quot; somewhere in<br>
<a class="Type" href="options.html#'shell'">'shell'</a>.<br>
&nbsp;&nbsp; On MS-Windows, however, there are many different shells and you might have<br>
to tune the options to make filtering work.&nbsp;&nbsp;Check the help for the options<br>
for more information.<br>
<br>
<br>
READING COMMAND OUTPUT<br>
<br>
To read the contents of the current directory into the file, use this:<br>
<br>
on Unix:<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:read !ls</div>
on MS-Windows:<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:read !dir</div>
<br>
The output of the &quot;ls&quot; or &quot;dir&quot; command is captured and inserted in the text,<br>
below the cursor.&nbsp;&nbsp;This is similar to reading a file, except that the &quot;!&quot; is<br>
used to tell Vim that a command follows.<br>
&nbsp;&nbsp; The command may have arguments.&nbsp;&nbsp;And a range can be used to tell where Vim<br>
should put the lines:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:0read !date -u</div>
<br>
This inserts the current time and date in UTC format at the top of the file.<br>
(Well, if you have a date command that accepts the &quot;-u&quot; argument.)&nbsp;&nbsp;<span class="Todo">Note</span>&nbsp;the<br>
difference with using &quot;!!date&quot;: that replaced a line, while &quot;:read !date&quot; will<br>
insert a line.<br>
<br>
<br>
WRITING TEXT TO A COMMAND<br>
<br>
The Unix command &quot;wc&quot; counts words.&nbsp;&nbsp;To count the words in the current file:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:write !wc</div>
<br>
This is the same write command as before, but instead of a file name the &quot;!&quot;<br>
character is used and the name of an external command.&nbsp;&nbsp;The written text will<br>
be passed to the specified command as its standard input.&nbsp;&nbsp;The output could<br>
look like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;47&nbsp;&nbsp;&nbsp;&nbsp; 249</span><br>
<br>
The &quot;wc&quot; command isn't verbose.&nbsp;&nbsp;This means you have 4 lines, 47 words and 249<br>
characters.<br>
<br>
Watch out for this mistake:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:write! wc</div>
<br>
This will write the file &quot;wc&quot; in the current directory, with force.&nbsp;&nbsp;White<br>
space is important here!<br>
<br>
<br>
REDRAWING THE SCREEN<br>
<br>
If the external command produced an error message, the display may have been<br>
messed up.&nbsp;&nbsp;Vim is very efficient and only redraws those parts of the screen<br>
that it knows need redrawing.&nbsp;&nbsp;But it can't know about what another program<br>
has written.&nbsp;&nbsp;To tell Vim to redraw the screen:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CTRL-L</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter:&nbsp;<a class="Identifier" href="usr_11.html">usr_11.txt</a>&nbsp;&nbsp;Recovering from a crash<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

搜索帮助