1 Star 0 Fork 0

hilarryxu/vimdoc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
usr_30.html 56.33 KB
一键复制 编辑 原始数据 按行查看 历史
hilarryxu 提交于 2017-08-15 10:58 . Init repo
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_30 - 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_30<br />
<a name="top"></a><h1>usr_30 - 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_30.html" name="usr_30.txt">usr_30.txt</a>&nbsp;&nbsp;&nbsp;&nbsp;For&nbsp;<span class="Identifier">Vim version 8.0.</span>&nbsp;&nbsp;Last change: 2007 Nov 10<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;Editing programs<br>
<br>
<br>
Vim has various commands that aid in writing computer programs.&nbsp;&nbsp;Compile a<br>
program and directly jump to reported errors.&nbsp;&nbsp;Automatically set the indent<br>
for many languages and format comments.<br>
<br>
<a class="Identifier" href="usr_30.html#30.1">30.1</a>&nbsp;&nbsp;Compiling<br>
<a class="Identifier" href="usr_30.html#30.2">30.2</a>&nbsp;&nbsp;Indenting C files<br>
<a class="Identifier" href="usr_30.html#30.3">30.3</a>&nbsp;&nbsp;Automatic indenting<br>
<a class="Identifier" href="usr_30.html#30.4">30.4</a>&nbsp;&nbsp;Other indenting<br>
<a class="Identifier" href="usr_30.html#30.5">30.5</a>&nbsp;&nbsp;Tabs and spaces<br>
<a class="Identifier" href="usr_30.html#30.6">30.6</a>&nbsp;&nbsp;Formatting comments<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Next chapter:&nbsp;<a class="Identifier" href="usr_31.html">usr_31.txt</a>&nbsp;&nbsp;Exploiting the GUI<br>
&nbsp;Previous chapter:&nbsp;<a class="Identifier" href="usr_29.html">usr_29.txt</a>&nbsp;&nbsp;Moving through programs<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_30.html#30.1" name="30.1">30.1</a>&nbsp;&nbsp;Compiling<br>
<br>
Vim has a set of so called &quot;quickfix&quot; commands.&nbsp;&nbsp;They enable you to compile a<br>
program from within Vim and then go through the errors generated and fix them<br>
(hopefully).&nbsp;&nbsp;You can then recompile and fix any new errors that are found<br>
until finally your program compiles without any error.<br>
<br>
The following command runs the program &quot;make&quot; (supplying it with any argument<br>
you give) and captures the results:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:make {arguments}</div>
<br>
If errors were generated, they are captured and the editor positions you where<br>
the first error occurred.<br>
&nbsp;&nbsp; Take a look at an example &quot;:make&quot; session.&nbsp;&nbsp;(Typical :make sessions generate<br>
far more errors and fewer stupid ones.)&nbsp;&nbsp;After typing &quot;:make&quot; the screen looks<br>
like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">:!make | &amp;tee /tmp/vim215953.err</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">gcc -g -Wall -o prog main.c sub.c</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">main.c: In function 'main':</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">main.c:6: too many arguments to function 'do_sub'</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">main.c: At top level:</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">main.c:10: parse error before '}'</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">make: *** [prog] Error 1</span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">2 returned</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&quot;main.c&quot; 11L, 111C</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">(3 of 6): too many arguments to function 'do_sub'</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Press ENTER or type command to continue</span><br>
<br>
From this you can see that you have errors in the file &quot;main.c&quot;.&nbsp;&nbsp;When you<br>
press&nbsp;<span class="Special">&lt;Enter&gt;</span>, Vim displays the file &quot;main.c&quot;, with the cursor positioned on<br>
line 6, the first line with an error.&nbsp;&nbsp;You did not need to specify the file or<br>
the line number, Vim knew where to go by looking in the error messages.<br>
<br>
&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;&nbsp;&nbsp;&nbsp;&nbsp;|int main()&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;&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;|<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i=3;&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;cursor -&gt; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_sub(&quot;foo&quot;);&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;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++i;&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;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (0);&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;&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;|<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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|(3 of 12): too many arguments to function 'do_sub' |<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+---------------------------------------------------+<br>
<br>
The following command goes to where the next error occurs:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:cnext</div>
<br>
Vim jumps to line 10, the last line in the file, where there is an extra '}'.<br>
&nbsp;&nbsp; When there is not enough room, Vim will shorten the error message.&nbsp;&nbsp;To see<br>
the whole message use:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:cc</div>
<br>
You can get an overview of all the error messages with the &quot;:clist&quot; command.<br>
The output looks like this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:clist</div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">3 main.c: 6:too many arguments to function 'do_sub'</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">5 main.c: 10:parse error before '}'</span><br>
<br>
Only the lines where Vim recognized a file name and line number are listed<br>
here.&nbsp;&nbsp;It assumes those are the interesting lines and the rest is just boring<br>
messages.&nbsp;&nbsp;However, sometimes unrecognized lines do contain something you want<br>
to see.&nbsp;&nbsp;Output from the linker, for example, about an undefined function.<br>
To see all the messages add a &quot;!&quot; to the command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:clist!</div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">1 gcc -g -Wall -o prog main.c sub.c</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">2 main.c: In function 'main':</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">3 main.c:6: too many arguments to function 'do_sub'</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">4 main.c: At top level:</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">5 main.c:10: parse error before '}'</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">6 make: *** [prog] Error 1</span><br>
<br>
Vim will highlight the current error.&nbsp;&nbsp;To go back to the previous error, use:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:cprevious</div>
<br>
Other commands to move around in the error list:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:cfirst&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to first error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:clast&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to last error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:cc 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to error nr 3<br>
<br>
<br>
USING ANOTHER COMPILER<br>
<br>
The name of the program to run when the &quot;:make&quot; command is executed is defined<br>
by the&nbsp;<a class="Type" href="options.html#'makeprg'">'makeprg'</a>&nbsp;option.&nbsp;&nbsp;Usually this is set to &quot;make&quot;, but Visual C++ users<br>
should set this to &quot;nmake&quot; by executing the following command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set makeprg=nmake</div>
<br>
You can also include arguments in this option.&nbsp;&nbsp;Special characters need to<br>
be escaped with a backslash.&nbsp;&nbsp;Example:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set makeprg=nmake\ -f\ project.mak</div>
<br>
You can include special Vim keywords in the command specification.&nbsp;&nbsp;The %<br>
character expands to the name of the current file.&nbsp;&nbsp;So if you execute the<br>
command:<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set makeprg=make\ %:S</div>
<br>
When you are editing main.c, then &quot;:make&quot; executes the following command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;make main.c</div>
<br>
This is not too useful, so you will refine the command a little and use the :r<br>
(root) modifier:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set makeprg=make\ %:r:S.o</div>
<br>
Now the command executed is as follows:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;make main.o</div>
<br>
More about these modifiers here:&nbsp;<a class="Identifier" href="cmdline.html#filename-modifiers">filename-modifiers</a>.<br>
<br>
<br>
OLD ERROR LISTS<br>
<br>
Suppose you &quot;:make&quot; a program.&nbsp;&nbsp;There is a warning message in one file and an<br>
error message in another.&nbsp;&nbsp;You fix the error and use &quot;:make&quot; again to check if<br>
it was really fixed.&nbsp;&nbsp;Now you want to look at the warning message.&nbsp;&nbsp;It doesn't<br>
show up in the last error list, since the file with the warning wasn't<br>
compiled again.&nbsp;&nbsp;You can go back to the previous error list with:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:colder</div>
<br>
Then use &quot;:clist&quot; and &quot;:cc&nbsp;<span class="Special">{nr}</span>&quot; to jump to the place with the warning.<br>
&nbsp;&nbsp; To go forward to the next error list:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:cnewer</div>
<br>
Vim remembers ten error lists.<br>
<br>
<br>
SWITCHING COMPILERS<br>
<br>
You have to tell Vim what format the error messages are that your compiler<br>
produces.&nbsp;&nbsp;This is done with the&nbsp;<a class="Type" href="options.html#'errorformat'">'errorformat'</a>&nbsp;option.&nbsp;&nbsp;The syntax of this<br>
option is quite complicated and it can be made to fit almost any compiler.<br>
You can find the explanation here:&nbsp;<a class="Identifier" href="quickfix.html#errorformat">errorformat</a>.<br>
<br>
You might be using various different compilers.&nbsp;&nbsp;Setting the&nbsp;<a class="Type" href="options.html#'makeprg'">'makeprg'</a>&nbsp;option,<br>
and especially the&nbsp;<a class="Type" href="options.html#'errorformat'">'errorformat'</a>&nbsp;each time is not easy.&nbsp;&nbsp;Vim offers a simple<br>
method for this.&nbsp;&nbsp;For example, to switch to using the Microsoft Visual C++<br>
compiler:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:compiler msvc</div>
<br>
This will find the Vim script for the &quot;msvc&quot; compiler and set the appropriate<br>
options.<br>
&nbsp;&nbsp; You can write your own compiler files.&nbsp;&nbsp;See&nbsp;<a class="Identifier" href="usr_41.html#write-compiler-plugin">write-compiler-plugin</a>.<br>
<br>
<br>
OUTPUT REDIRECTION<br>
<br>
The &quot;:make&quot; command redirects the output of the executed program to an error<br>
file.&nbsp;&nbsp;How this works depends on various things, such as the&nbsp;<a class="Type" href="options.html#'shell'">'shell'</a>.&nbsp;&nbsp;If your<br>
&quot;:make&quot; command doesn't capture the output, check the&nbsp;<a class="Type" href="options.html#'makeef'">'makeef'</a>&nbsp;and<br>
<a class="Type" href="options.html#'shellpipe'">'shellpipe'</a>&nbsp;options.&nbsp;&nbsp;The&nbsp;<a class="Type" href="options.html#'shellquote'">'shellquote'</a>&nbsp;and&nbsp;<a class="Type" href="options.html#'shellxquote'">'shellxquote'</a>&nbsp;options might also<br>
matter.<br>
<br>
In case you can't get &quot;:make&quot; to redirect the file for you, an alternative is<br>
to compile the program in another window and redirect the output into a file.<br>
Then have Vim read this file with:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:cfile {filename}</div>
<br>
Jumping to errors will work like with the &quot;:make&quot; command.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_30.html#30.2" name="30.2">30.2</a>&nbsp;&nbsp;Indenting C style text<br>
<br>
A program is much easier to understand when the lines have been properly<br>
indented.&nbsp;&nbsp;Vim offers various ways to make this less work.&nbsp;&nbsp;For C or C style<br>
programs like Java or C++, set the&nbsp;<a class="Type" href="options.html#'cindent'">'cindent'</a>&nbsp;option.&nbsp;&nbsp;Vim knows a lot about C<br>
programs and will try very hard to automatically set the indent for you.&nbsp;&nbsp;Set<br>
the&nbsp;<a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a>&nbsp;option to the amount of spaces you want for a deeper level.<br>
Four spaces will work fine.&nbsp;&nbsp;One &quot;:set&quot; command will do it:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set cindent shiftwidth=4</div>
<br>
With this option enabled, when you type something such as &quot;if (x)&quot;, the next<br>
line will automatically be indented an additional level.<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;&nbsp;&nbsp;&nbsp;&nbsp;if (flag)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Automatic indent&nbsp;&nbsp; ---&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_the_work();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Automatic unindent &lt;--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (other_flag) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Automatic indent&nbsp;&nbsp; ---&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_file();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;keep indent&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_some_more();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Automatic unindent &lt;--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
<br>
When you type something in curly braces ({}), the text will be indented at the<br>
start and unindented at the end.&nbsp;&nbsp;The unindenting will happen after typing the<br>
'}', since Vim can't guess what you are going to type.<br>
<br>
One side effect of automatic indentation is that it helps you catch errors in<br>
your code early.&nbsp;&nbsp;When you type a } to finish a function, only to find that<br>
the automatic indentation gives it more indent than what you expected, there<br>
is probably a } missing.&nbsp;&nbsp;Use the &quot;%&quot; command to find out which { matches the<br>
} you typed.<br>
&nbsp;&nbsp; A missing ) and ; also cause extra indent.&nbsp;&nbsp;Thus if you get more white<br>
space than you would expect, check the preceding lines.<br>
<br>
When you have code that is badly formatted, or you inserted and deleted lines,<br>
you need to re-indent the lines.&nbsp;&nbsp;The &quot;=&quot; operator does this.&nbsp;&nbsp;The simplest<br>
form is:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==</div>
<br>
This indents the current line.&nbsp;&nbsp;Like with all operators, there are three ways<br>
to use it.&nbsp;&nbsp;In Visual mode &quot;=&quot; indents the selected lines.&nbsp;&nbsp;A useful text<br>
object is &quot;a{&quot;.&nbsp;&nbsp;This selects the current {} block.&nbsp;&nbsp;Thus, to re-indent the<br>
code block the cursor is in:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=a{</div>
<br>
I you have really badly indented code, you can re-indent the whole file with:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gg=G</div>
<br>
However, don't do this in files that have been carefully indented manually.<br>
The automatic indenting does a good job, but in some situations you might want<br>
to overrule it.<br>
<br>
<br>
SETTING INDENT STYLE<br>
<br>
Different people have different styles of indentation.&nbsp;&nbsp;By default Vim does a<br>
pretty good job of indenting in a way that 90% of programmers do.&nbsp;&nbsp;There are<br>
different styles, however; so if you want to, you can customize the<br>
indentation style with the&nbsp;<a class="Type" href="options.html#'cinoptions'">'cinoptions'</a>&nbsp;option.<br>
&nbsp;&nbsp; By default&nbsp;<a class="Type" href="options.html#'cinoptions'">'cinoptions'</a>&nbsp;is empty and Vim uses the default style.&nbsp;&nbsp;You can<br>
add various items where you want something different.&nbsp;&nbsp;For example, to make<br>
curly braces be placed like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">if (flag)</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">{</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">i = 8;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">j = 0;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">}</span><br>
<br>
Use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set cinoptions+={2</div>
<br>
There are many of these items.&nbsp;&nbsp;See&nbsp;<a class="Identifier" href="indent.html#cinoptions-values">cinoptions-values</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_30.html#30.3" name="30.3">30.3</a>&nbsp;&nbsp;Automatic indenting<br>
<br>
You don't want to switch on the&nbsp;<a class="Type" href="options.html#'cindent'">'cindent'</a>&nbsp;option manually every time you edit<br>
a C file.&nbsp;&nbsp;This is how you make it work automatically:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:filetype indent on</div>
<br>
Actually, this does a lot more than switching on&nbsp;<a class="Type" href="options.html#'cindent'">'cindent'</a>&nbsp;for C files.&nbsp;&nbsp;First<br>
of all, it enables detecting the type of a file.&nbsp;&nbsp;That's the same as what is<br>
used for syntax highlighting.<br>
&nbsp;&nbsp; When the filetype is known, Vim will search for an indent file for this<br>
type of file.&nbsp;&nbsp;The Vim distribution includes a number of these for various<br>
programming languages.&nbsp;&nbsp;This indent file will then prepare for automatic<br>
indenting specifically for this file.<br>
<br>
If you don't like the automatic indenting, you can switch it off again:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:filetype indent off</div>
<br>
If you don't like the indenting for one specific type of file, this is how you<br>
avoid it.&nbsp;&nbsp;Create a file with just this one line:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:let b:did_indent = 1</div>
<br>
Now you need to write this in a file with a specific name:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">{directory}</span>/indent/<span class="Special">{filetype}</span>.vim<br>
<br>
The&nbsp;<span class="Special">{filetype}</span>&nbsp;is the name of the file type, such as &quot;cpp&quot; or &quot;java&quot;.&nbsp;&nbsp;You can<br>
see the exact name that Vim detected with this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set filetype</div>
<br>
In this file the output is:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">filetype=help</span><br>
<br>
Thus you would use &quot;help&quot; for&nbsp;<span class="Special">{filetype}</span>.<br>
&nbsp;&nbsp; For the&nbsp;<span class="Special">{directory}</span>&nbsp;part you need to use your runtime directory.&nbsp;&nbsp;Look at<br>
the output of this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set runtimepath</div>
<br>
Now use the first item, the name before the first comma.&nbsp;&nbsp;Thus if the output<br>
looks like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">runtimepath=~/.vim,/usr/local/share/vim/vim60/runtime,~/.vim/after</span><br>
<br>
You use &quot;~/.vim&quot; for&nbsp;<span class="Special">{directory}</span>.&nbsp;&nbsp;Then the resulting file name is:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">~/.vim/indent/help.vim</span><br>
<br>
Instead of switching the indenting off, you could write your own indent file.<br>
How to do that is explained here:&nbsp;<a class="Identifier" href="indent.html#indent-expression">indent-expression</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_30.html#30.4" name="30.4">30.4</a>&nbsp;&nbsp;Other indenting<br>
<br>
The most simple form of automatic indenting is with the&nbsp;<a class="Type" href="options.html#'autoindent'">'autoindent'</a>&nbsp;option.<br>
It uses the indent from the previous line.&nbsp;&nbsp;A bit smarter is the&nbsp;<a class="Type" href="options.html#'smartindent'">'smartindent'</a><br>
option.&nbsp;&nbsp;This is useful for languages where no indent file is available.<br>
<a class="Type" href="options.html#'smartindent'">'smartindent'</a>&nbsp;is not as smart as&nbsp;<a class="Type" href="options.html#'cindent'">'cindent'</a>, but smarter than&nbsp;<a class="Type" href="options.html#'autoindent'">'autoindent'</a>.<br>
&nbsp;&nbsp; With&nbsp;<a class="Type" href="options.html#'smartindent'">'smartindent'</a>&nbsp;set, an extra level of indentation is added for each {<br>
and removed for each }.&nbsp;&nbsp;An extra level of indentation will also be added for<br>
any of the words in the&nbsp;<a class="Type" href="options.html#'cinwords'">'cinwords'</a>&nbsp;option.&nbsp;&nbsp;Lines that begin with # are<br>
treated specially: all indentation is removed.&nbsp;&nbsp;This is done so that<br>
preprocessor directives will all start in column 1.&nbsp;&nbsp;The indentation is<br>
restored for the next line.<br>
<br>
<br>
CORRECTING INDENTS<br>
<br>
When you are using&nbsp;<a class="Type" href="options.html#'autoindent'">'autoindent'</a>&nbsp;or&nbsp;<a class="Type" href="options.html#'smartindent'">'smartindent'</a>&nbsp;to get the indent of the<br>
previous line, there will be many times when you need to add or remove one<br>
<a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a>&nbsp;worth of indent.&nbsp;&nbsp;A quick way to do this is using the&nbsp;<span class="Special">CTRL-D</span>&nbsp;and<br>
<span class="Special">CTRL-T</span>&nbsp;commands in Insert mode.<br>
&nbsp;&nbsp; For example, you are typing a shell script that is supposed to look like<br>
this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">if test -n a; then</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">echo a</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">echo &quot;-------&quot;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">fi</span><br>
<br>
Start off by setting these options:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set autoindent shiftwidth=3</div>
<br>
You start by typing the first line,&nbsp;<span class="Special">&lt;Enter&gt;</span>&nbsp;and the start of the second line:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">if test -n a; then</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">echo</span><br>
<br>
Now you see that you need an extra indent.&nbsp;&nbsp;Type&nbsp;<span class="Special">CTRL-T</span>.&nbsp;&nbsp;The result:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">if test -n a; then</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">echo</span><br>
<br>
The&nbsp;<span class="Special">CTRL-T</span>&nbsp;command, in Insert mode, adds one&nbsp;<a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a>&nbsp;to the indent, no<br>
matter where in the line you are.<br>
&nbsp;&nbsp; You continue typing the second line,&nbsp;<span class="Special">&lt;Enter&gt;</span>&nbsp;and the third line.&nbsp;&nbsp;This time<br>
the indent is OK.&nbsp;&nbsp;Then&nbsp;<span class="Special">&lt;Enter&gt;</span>&nbsp;and the last line.&nbsp;&nbsp;Now you have this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">if test -n a; then</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">echo a</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">echo &quot;-------&quot;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">fi</span><br>
<br>
To remove the superfluous indent in the last line press&nbsp;<span class="Special">CTRL-D</span>.&nbsp;&nbsp;This deletes<br>
one&nbsp;<a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a>&nbsp;worth of indent, no matter where you are in the line.<br>
&nbsp;&nbsp; When you are in Normal mode, you can use the &quot;&gt;&gt;&quot; and &quot;&lt;&lt;&quot; commands to<br>
shift lines.&nbsp;&nbsp;&quot;&gt;&quot; and &quot;&lt;&quot; are operators, thus you have the usual three ways to<br>
specify the lines you want to indent.&nbsp;&nbsp;A useful combination is:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&gt;i{</div>
<br>
This adds one indent to the current block of lines, inside {}.&nbsp;&nbsp;The { and }<br>
lines themselves are left unmodified.&nbsp;&nbsp;&quot;&gt;a{&quot; includes them.&nbsp;&nbsp;In this example<br>
the cursor is on &quot;printf&quot;:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;original text&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; after &quot;&gt;i{&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; after &quot;&gt;a{&quot;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">if (flag)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (flag)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (flag)</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">{&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><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">printf(&quot;yes&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;yes&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;yes&quot;);</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">flag = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag = 0;&nbsp;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">}&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><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_30.html#30.5" name="30.5">30.5</a>&nbsp;&nbsp;Tabs and spaces<br>
<br>
<a class="Type" href="options.html#'tabstop'">'tabstop'</a>&nbsp;is set to eight by default.&nbsp;&nbsp;Although you can change it, you quickly<br>
run into trouble later.&nbsp;&nbsp;Other programs won't know what tabstop value you<br>
used.&nbsp;&nbsp;They probably use the default value of eight, and your text suddenly<br>
looks very different.&nbsp;&nbsp;Also, most printers use a fixed tabstop value of eight.<br>
Thus it's best to keep&nbsp;<a class="Type" href="options.html#'tabstop'">'tabstop'</a>&nbsp;alone.&nbsp;&nbsp;(If you edit a file which was written<br>
with a different tabstop setting, see&nbsp;<a class="Identifier" href="usr_25.html#25.3">25.3</a>&nbsp;for how to fix that.)<br>
&nbsp;&nbsp; For indenting lines in a program, using a multiple of eight spaces makes<br>
you quickly run into the right border of the window.&nbsp;&nbsp;Using a single space<br>
doesn't provide enough visual difference.&nbsp;&nbsp;Many people prefer to use four<br>
spaces, a good compromise.<br>
&nbsp;&nbsp; Since a&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;is eight spaces and you want to use an indent of four spaces,<br>
you can't use a&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;character to make your indent.&nbsp;&nbsp;There are two ways to<br>
handle this:<br>
<br>
1.&nbsp;&nbsp;Use a mix of&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;and space characters.&nbsp;&nbsp;Since a&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;takes the place of<br>
&nbsp;&nbsp;&nbsp;&nbsp;eight spaces, you have fewer characters in your file.&nbsp;&nbsp;Inserting a&nbsp;<span class="Special">&lt;Tab&gt;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;is quicker than eight spaces.&nbsp;&nbsp;Backspacing works faster as well.<br>
<br>
2.&nbsp;&nbsp;Use spaces only.&nbsp;&nbsp;This avoids the trouble with programs that use a<br>
&nbsp;&nbsp;&nbsp;&nbsp;different tabstop value.<br>
<br>
Fortunately, Vim supports both methods quite well.<br>
<br>
<br>
SPACES AND TABS<br>
<br>
If you are using a combination of tabs and spaces, you just edit normally.<br>
The Vim defaults do a fine job of handling things.<br>
&nbsp;&nbsp; You can make life a little easier by setting the&nbsp;<a class="Type" href="options.html#'softtabstop'">'softtabstop'</a>&nbsp;option.<br>
This option tells Vim to make the&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;key look and feel as if tabs were set<br>
at the value of&nbsp;<a class="Type" href="options.html#'softtabstop'">'softtabstop'</a>, but actually use a combination of tabs and<br>
spaces.<br>
&nbsp;&nbsp; After you execute the following command, every time you press the&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;key<br>
the cursor moves to the next 4-column boundary:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set softtabstop=4</div>
<br>
When you start in the first column and press&nbsp;<span class="Special">&lt;Tab&gt;</span>, you get 4 spaces inserted<br>
in your text.&nbsp;&nbsp;The second time, Vim takes out the 4 spaces and puts in a&nbsp;<span class="Special">&lt;Tab&gt;</span><br>
(thus taking you to column 8).&nbsp;&nbsp;Thus Vim uses as many&nbsp;<span class="Special">&lt;Tab&gt;</span>s as possible, and<br>
then fills up with spaces.<br>
&nbsp;&nbsp; When backspacing it works the other way around.&nbsp;&nbsp;A&nbsp;<span class="Special">&lt;BS&gt;</span>&nbsp;will always delete<br>
the amount specified with&nbsp;<a class="Type" href="options.html#'softtabstop'">'softtabstop'</a>.&nbsp;&nbsp;Then&nbsp;<span class="Special">&lt;Tab&gt;</span>s are used as many as<br>
possible and spaces to fill the gap.<br>
&nbsp;&nbsp; The following shows what happens pressing&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;a few times, and then using<br>
<span class="Special">&lt;BS&gt;</span>.&nbsp;&nbsp;A &quot;.&quot; stands for a space and &quot;-------&gt;&quot; for a&nbsp;<span class="Special">&lt;Tab&gt;</span>.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">&lt;Tab&gt;</span>&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;<span class="Special">&lt;Tab&gt;&lt;Tab&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-------&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">&lt;Tab&gt;&lt;Tab&gt;&lt;Tab&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------&gt;....<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">&lt;Tab&gt;&lt;Tab&gt;&lt;Tab&gt;&lt;BS&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">&lt;Tab&gt;&lt;Tab&gt;&lt;Tab&gt;&lt;BS&gt;&lt;BS&gt;</span>&nbsp;&nbsp; ....<br>
<br>
An alternative is to use the&nbsp;<a class="Type" href="options.html#'smarttab'">'smarttab'</a>&nbsp;option.&nbsp;&nbsp;When it's set, Vim uses<br>
<a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a>&nbsp;for a&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;typed in the indent of a line, and a real&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;when<br>
typed after the first non-blank character.&nbsp;&nbsp;However,&nbsp;<span class="Special">&lt;BS&gt;</span>&nbsp;doesn't work like<br>
with&nbsp;<a class="Type" href="options.html#'softtabstop'">'softtabstop'</a>.<br>
<br>
<br>
JUST SPACES<br>
<br>
If you want absolutely no tabs in your file, you can set the&nbsp;<a class="Type" href="options.html#'expandtab'">'expandtab'</a><br>
option:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set expandtab</div>
<br>
When this option is set, the&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;key inserts a series of spaces.&nbsp;&nbsp;Thus you<br>
get the same amount of white space as if a&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;character was inserted, but<br>
there isn't a real&nbsp;<span class="Special">&lt;Tab&gt;</span>&nbsp;character in your file.<br>
&nbsp;&nbsp; The backspace key will delete each space by itself.&nbsp;&nbsp;Thus after typing one<br>
<span class="Special">&lt;Tab&gt;</span>&nbsp;you have to press the&nbsp;<span class="Special">&lt;BS&gt;</span>&nbsp;key up to eight times to undo it.&nbsp;&nbsp;If you are<br>
in the indent, pressing&nbsp;<span class="Special">CTRL-D</span>&nbsp;will be a lot quicker.<br>
<br>
<br>
CHANGING TABS IN SPACES (AND BACK)<br>
<br>
Setting&nbsp;<a class="Type" href="options.html#'expandtab'">'expandtab'</a>&nbsp;does not affect any existing tabs.&nbsp;&nbsp;In other words, any<br>
tabs in the document remain tabs.&nbsp;&nbsp;If you want to convert tabs to spaces, use<br>
the &quot;:retab&quot; command.&nbsp;&nbsp;Use these commands:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set expandtab<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%retab</div>
<br>
Now Vim will have changed all indents to use spaces instead of tabs.&nbsp;&nbsp;However,<br>
all tabs that come after a non-blank character are kept.&nbsp;&nbsp;If you want these to<br>
be converted as well, add a !:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%retab!</div>
<br>
This is a little bit dangerous, because it can also change tabs inside a<br>
string.&nbsp;&nbsp;To check if these exist, you could use this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/&quot;[^&quot;\t]*\t[^&quot;]*&quot;</div>
<br>
It's recommended not to use hard tabs inside a string.&nbsp;&nbsp;Replace them with<br>
&quot;\t&quot; to avoid trouble.<br>
<br>
The other way around works just as well:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set noexpandtab<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%retab!</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_30.html#30.6" name="30.6">30.6</a>&nbsp;&nbsp;Formatting comments<br>
<br>
One of the great things about Vim is that it understands comments.&nbsp;&nbsp;You can<br>
ask Vim to format a comment and it will do the right thing.<br>
&nbsp;&nbsp; Suppose, for example, that you have the following comment:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">/*</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">* This is a test</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">* of the text formatting.</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">*/</span><br>
<br>
You then ask Vim to format it by positioning the cursor at the start of the<br>
comment and type:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gq]/</div>
<br>
&quot;gq&quot; is the operator to format text.&nbsp;&nbsp;&quot;]/&quot; is the motion that takes you to the<br>
end of a comment.&nbsp;&nbsp;The result is:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">/*</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">* This is a test of the text formatting.</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">*/</span><br>
<br>
Notice that Vim properly handled the beginning of each line.<br>
&nbsp;&nbsp;An alternative is to select the text that is to be formatted in Visual mode<br>
and type &quot;gq&quot;.<br>
<br>
To add a new line to the comment, position the cursor on the middle line and<br>
press &quot;o&quot;.&nbsp;&nbsp;The result looks like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">/*</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">* This is a test of the text formatting.</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">*</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">*/</span><br>
<br>
Vim has automatically inserted a star and a space for you.&nbsp;&nbsp;Now you can type<br>
the comment text.&nbsp;&nbsp;When it gets longer than&nbsp;<a class="Type" href="options.html#'textwidth'">'textwidth'</a>, Vim will break the<br>
line.&nbsp;&nbsp;Again, the star is inserted automatically:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">/*</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">* This is a test of the text formatting.</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">* Typing a lot of text here will make Vim</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">* break</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">*/</span><br>
<br>
For this to work some flags must be present in&nbsp;<a class="Type" href="options.html#'formatoptions'">'formatoptions'</a>:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert the star when typing&nbsp;<span class="Special">&lt;Enter&gt;</span>&nbsp;in Insert mode<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;o&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert the star when using &quot;o&quot; or &quot;O&quot; in Normal mode<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break comment text according to&nbsp;<a class="Type" href="options.html#'textwidth'">'textwidth'</a><br>
<br>
See&nbsp;<a class="Identifier" href="change.html#fo-table">fo-table</a>&nbsp;for more flags.<br>
<br>
<br>
DEFINING A COMMENT<br>
<br>
The&nbsp;<a class="Type" href="options.html#'comments'">'comments'</a>&nbsp;option defines what a comment looks like.&nbsp;&nbsp;Vim distinguishes<br>
between a single-line comment and a comment that has a different start, end<br>
and middle part.<br>
&nbsp;&nbsp; Many single-line comments start with a specific character.&nbsp;&nbsp;In C++ // is<br>
used, in Makefiles #, in Vim scripts &quot;.&nbsp;&nbsp;For example, to make Vim understand<br>
C++ comments:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set comments=://</div>
<br>
The colon separates the flags of an item from the text by which the comment is<br>
recognized.&nbsp;&nbsp;The general form of an item in&nbsp;<a class="Type" href="options.html#'comments'">'comments'</a>&nbsp;is:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">{flags}</span>:<span class="Special">{text}</span><br>
<br>
The&nbsp;<span class="Special">{flags}</span>&nbsp;part can be empty, as in this case.<br>
&nbsp;&nbsp; Several of these items can be concatenated, separated by commas.&nbsp;&nbsp;This<br>
allows recognizing different types of comments at the same time.&nbsp;&nbsp;For example,<br>
let's edit an e-mail message.&nbsp;&nbsp;When replying, the text that others wrote is<br>
preceded with &quot;&gt;&quot; and &quot;!&quot; characters.&nbsp;&nbsp;This command would work:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set comments=n:&gt;,n:!</div>
<br>
There are two items, one for comments starting with &quot;&gt;&quot; and one for comments<br>
that start with &quot;!&quot;.&nbsp;&nbsp;Both use the flag &quot;n&quot;.&nbsp;&nbsp;This means that these comments<br>
nest.&nbsp;&nbsp;Thus a line starting with &quot;&gt;&quot; may have another comment after the &quot;&gt;&quot;.<br>
This allows formatting a message like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&gt; ! Did you see that site?</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&gt; ! It looks really great.</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&gt; I don't like it.&nbsp;&nbsp;The</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&gt; colors are terrible.</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">What is the URL of that</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">site?</span><br>
<br>
Try setting&nbsp;<a class="Type" href="options.html#'textwidth'">'textwidth'</a>&nbsp;to a different value, e.g., 80, and format the text by<br>
Visually selecting it and typing &quot;gq&quot;.&nbsp;&nbsp;The result is:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&gt; ! Did you see that site?&nbsp;&nbsp;It looks really great.</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&gt; I don't like it.&nbsp;&nbsp;The colors are terrible.</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">What is the URL of that site?</span><br>
<br>
You will notice that Vim did not move text from one type of comment to<br>
another.&nbsp;&nbsp;The &quot;I&quot; in the second line would have fit at the end of the first<br>
line, but since that line starts with &quot;&gt; !&quot; and the second line with &quot;&gt;&quot;, Vim<br>
knows that this is a different kind of comment.<br>
<br>
<br>
A THREE PART COMMENT<br>
<br>
A C comment starts with &quot;/*&quot;, has &quot;*&quot; in the middle and &quot;*/&quot; at the end.&nbsp;&nbsp;The<br>
entry in&nbsp;<a class="Type" href="options.html#'comments'">'comments'</a>&nbsp;for this looks like this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set comments=s1:/*,mb:*,ex:*/</div>
<br>
The start is defined with &quot;s1:/*&quot;.&nbsp;&nbsp;The &quot;s&quot; indicates the start of a<br>
three-piece comment.&nbsp;&nbsp;The colon separates the flags from the text by which the<br>
comment is recognized: &quot;/*&quot;.&nbsp;&nbsp;There is one flag: &quot;1&quot;.&nbsp;&nbsp;This tells Vim that the<br>
middle part has an offset of one space.<br>
&nbsp;&nbsp; The middle part &quot;mb:*&quot; starts with &quot;m&quot;, which indicates it is a middle<br>
part.&nbsp;&nbsp;The &quot;b&quot; flag means that a blank must follow the text.&nbsp;&nbsp;Otherwise Vim<br>
would consider text like &quot;*pointer&quot; also to be the middle of a comment.<br>
&nbsp;&nbsp; The end part &quot;ex:*/&quot; has the &quot;e&quot; for identification.&nbsp;&nbsp;The &quot;x&quot; flag has a<br>
special meaning.&nbsp;&nbsp;It means that after Vim automatically inserted a star,<br>
typing / will remove the extra space.<br>
<br>
For more details see&nbsp;<a class="Identifier" href="change.html#format-comments">format-comments</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter:&nbsp;<a class="Identifier" href="usr_31.html">usr_31.txt</a>&nbsp;&nbsp;Exploiting the GUI<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

搜索帮助