代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>repeat - 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>
/ repeat<br />
<a name="top"></a><h1>repeat - 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="repeat.html" name="repeat.txt">repeat.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2017 Jun 10<br>
<br>
<br>
<span class="Identifier">VIM REFERENCE MANUAL by Bram Moolenaar</span><br>
<br>
<br>
Repeating commands, Vim scripts and debugging <a class="Constant" href="repeat.html#repeating" name="repeating">repeating</a><br>
<br>
Chapter 26 of the user manual introduces repeating <a class="Identifier" href="usr_26.html">usr_26.txt</a>.<br>
<br>
1. Single repeats <a class="Identifier" href="repeat.html#single-repeat">single-repeat</a><br>
2. Multiple repeats <a class="Identifier" href="repeat.html#multi-repeat">multi-repeat</a><br>
3. Complex repeats <a class="Identifier" href="repeat.html#complex-repeat">complex-repeat</a><br>
4. Using Vim scripts <a class="Identifier" href="repeat.html#using-scripts">using-scripts</a><br>
5. Using Vim packages <a class="Identifier" href="repeat.html#packages">packages</a><br>
6. Creating Vim packages <a class="Identifier" href="repeat.html#package-create">package-create</a><br>
7. Debugging scripts <a class="Identifier" href="repeat.html#debug-scripts">debug-scripts</a><br>
8. Profiling <a class="Identifier" href="repeat.html#profiling">profiling</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Single repeats <a class="Constant" href="repeat.html#single-repeat" name="single-repeat">single-repeat</a><br>
<br>
<a class="Constant" href="repeat.html#." name=".">.</a><br>
. Repeat last change, with count replaced with <span class="Special">[count]</span>.<br>
Also repeat a yank command, when the 'y' flag is<br>
included in <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a>. Does not repeat a<br>
command-line command.<br>
<br>
Simple changes can be repeated with the "." command. Without a count, the<br>
count of the last change is used. If you enter a count, it will replace the<br>
last one. <a class="Identifier" href="eval.html#v:count">v:count</a> and <a class="Identifier" href="eval.html#v:count1">v:count1</a> will be set.<br>
<br>
If the last change included a specification of a numbered register, the<br>
register number will be incremented. See <a class="Identifier" href="undo.html#redo-register">redo-register</a> for an example how<br>
to use this.<br>
<br>
<span class="Todo">Note</span> that when repeating a command that used a Visual selection, the same SIZE<br>
of area is used, see <a class="Identifier" href="visual.html#visual-repeat">visual-repeat</a>.<br>
<br>
<a class="Constant" href="repeat.html#@:" name="@:">@:</a><br>
@: Repeat last command-line <span class="Special">[count]</span> times.<br>
<span class="Special">{not available when compiled without the</span><br>
<a class="Identifier" href="various.html#+cmdline_hist">+cmdline_hist</a><span class="Special"> feature}</span><br>
<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. Multiple repeats <a class="Constant" href="repeat.html#multi-repeat" name="multi-repeat">multi-repeat</a><br>
<br>
<a class="Constant" href="repeat.html#:g" name=":g">:g</a> <a class="Constant" href="repeat.html#:global" name=":global">:global</a> <a class="Constant" href="repeat.html#E148" name="E148">E148</a><br>
:<span class="Special">[range]</span>g[lobal]/<span class="Special">{pattern}</span>/<span class="Special">[cmd]</span><br>
Execute the Ex command <span class="Special">[cmd]</span> (default ":p") on the<br>
lines within <span class="Special">[range]</span> where <span class="Special">{pattern}</span> matches.<br>
<br>
:<span class="Special">[range]</span>g[lobal]!/<span class="Special">{pattern}</span>/<span class="Special">[cmd]</span><br>
Execute the Ex command <span class="Special">[cmd]</span> (default ":p") on the<br>
lines within <span class="Special">[range]</span> where <span class="Special">{pattern}</span> does NOT match.<br>
<br>
<a class="Constant" href="repeat.html#:v" name=":v">:v</a> <a class="Constant" href="repeat.html#:vglobal" name=":vglobal">:vglobal</a><br>
:<span class="Special">[range]</span>v[global]/<span class="Special">{pattern}</span>/<span class="Special">[cmd]</span><br>
Same as :g!.<br>
<br>
Instead of the '/' which surrounds the <span class="Special">{pattern}</span>, you can use any other<br>
single byte character, but not an alphabetic character, '\', '"' or '|'.<br>
This is useful if you want to include a '/' in the search pattern or<br>
replacement string.<br>
<br>
For the definition of a pattern, see <a class="Identifier" href="pattern.html#pattern">pattern</a>.<br>
<br>
<span class="Todo">NOTE</span> <span class="Special">[cmd]</span> may contain a range; see <a class="Identifier" href="tips.html#collapse">collapse</a> and <a class="Identifier" href="usr_25.html#edit-paragraph-join">edit-paragraph-join</a> for<br>
examples.<br>
<br>
The global commands work by first scanning through the <span class="Special">[range]</span> lines and<br>
marking each line where a match occurs (for a multi-line pattern, only the<br>
start of the match matters).<br>
In a second scan the <span class="Special">[cmd]</span> is executed for each marked line, as if the cursor<br>
was in that line. For ":v" and ":g!" the command is executed for each not<br>
marked line. If a line is deleted its mark disappears.<br>
The default for <span class="Special">[range]</span> is the whole buffer (1,$). Use "<span class="Special">CTRL-C</span>" to interrupt<br>
the command. If an error message is given for a line, the command for that<br>
line is aborted and the global command continues with the next marked or<br>
unmarked line.<br>
<a class="Constant" href="repeat.html#E147" name="E147">E147</a> <br>
When the command is used recursively, it only works on one line. Giving a<br>
range is then not allowed. This is useful to find all lines that match a<br>
pattern and do not match another pattern:<br>
<div class="helpExample"> :g/found/v/notfound/{cmd}</div>
This first finds all lines containing "found", but only executes <span class="Special">{cmd}</span> when<br>
there is no match for "notfound".<br>
<br>
To execute a non-Ex command, you can use the <a class="Comment" href="various.html#:normal">:normal</a> command:<br>
<div class="helpExample"> :g/pat/normal {commands}</div>
Make sure that <span class="Special">{commands}</span> ends with a whole command, otherwise Vim will wait<br>
for you to type the rest of the command for each match. The screen will not<br>
have been updated, so you don't know what you are doing. See <a class="Identifier" href="various.html#:normal">:normal</a>.<br>
<br>
The undo/redo command will undo/redo the whole global command at once.<br>
The previous context mark will only be set once (with "''" you go back to<br>
where the cursor was before the global command).<br>
<br>
The global command sets both the last used search pattern and the last used<br>
substitute pattern (this is vi compatible). This makes it easy to globally<br>
replace a string:<br>
:g/pat/s//PAT/g<br>
This replaces all occurrences of "pat" with "PAT". The same can be done with:<br>
:%s/pat/PAT/g<br>
Which is two characters shorter!<br>
<br>
When using "global" in Ex mode, a special case is using ":visual" as a<br>
command. This will move to a matching line, go to Normal mode to let you<br>
execute commands there until you use <a class="Identifier" href="intro.html#Q">Q</a> to return to Ex mode. This will be<br>
repeated for each matching line. While doing this you cannot use ":global".<br>
To abort this type <span class="Special">CTRL-C</span> twice.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. Complex repeats <a class="Constant" href="repeat.html#complex-repeat" name="complex-repeat">complex-repeat</a><br>
<br>
<a class="Constant" href="repeat.html#q" name="q">q</a> <a class="Constant" href="repeat.html#recording" name="recording">recording</a><br>
q<span class="Special">{0-9a-zA-Z"}</span> Record typed characters into register <span class="Special">{0-9a-zA-Z"}</span><br>
(uppercase to append). The 'q' command is disabled<br>
while executing a register, and it doesn't work inside<br>
a mapping and <a class="Identifier" href="various.html#:normal">:normal</a>.<br>
<br>
<span class="Todo">Note</span>: If the register being used for recording is also<br>
used for <a class="Identifier" href="change.html#y">y</a> and <a class="Identifier" href="change.html#p">p</a> the result is most likely not<br>
what is expected, because the put will paste the<br>
recorded macro and the yank will overwrite the<br>
recorded macro. <span class="Special">{Vi: no recording}</span><br>
<br>
q Stops recording. (Implementation <span class="Todo">note</span>: The 'q' that<br>
stops recording is not stored in the register, unless<br>
it was the result of a mapping) <span class="Special">{Vi: no recording}</span><br>
<br>
<a class="Constant" href="repeat.html#@" name="@">@</a><br>
@<span class="Special">{0-9a-z".=*+}</span> Execute the contents of register <span class="Special">{0-9a-z".=*+}</span> <span class="Special">[count]</span><br>
times. <span class="Todo">Note</span> that register '%' (name of the current<br>
file) and '#' (name of the alternate file) cannot be<br>
used.<br>
The register is executed like a mapping, that means<br>
that the difference between <a class="Type" href="options.html#'wildchar'">'wildchar'</a> and <a class="Type" href="options.html#'wildcharm'">'wildcharm'</a><br>
applies.<br>
For "@=" you are prompted to enter an expression. The<br>
result of the expression is then executed.<br>
See also <a class="Identifier" href="repeat.html#@:">@:</a>. <span class="Special">{Vi: only named registers}</span><br>
<br>
<a class="Constant" href="repeat.html#@@" name="@@">@@</a> <a class="Constant" href="repeat.html#E748" name="E748">E748</a><br>
@@ Repeat the previous @<span class="Special">{0-9a-z":*}</span> <span class="Special">[count]</span> times.<br>
<br>
:<span class="Special">[addr]</span>*<span class="Special">{0-9a-z".=+}</span> <a class="Constant" href="repeat.html#:@" name=":@">:@</a> <a class="Constant" href="repeat.html#:star" name=":star">:star</a><br>
:<span class="Special">[addr]</span>@<span class="Special">{0-9a-z".=*+}</span> Execute the contents of register <span class="Special">{0-9a-z".=*+}</span> as an Ex<br>
command. First set cursor at line <span class="Special">[addr]</span> (default is<br>
current line). When the last line in the register does<br>
not have a <span class="Special"><CR></span> it will be added automatically when<br>
the 'e' flag is present in <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a>.<br>
<span class="Todo">Note</span> that the ":*" command is only recognized when the<br>
'*' flag is present in <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a>. This is NOT the<br>
default when <a class="Type" href="options.html#'nocompatible'">'nocompatible'</a> is used.<br>
For ":@=" the last used expression is used. The<br>
result of evaluating the expression is executed as an<br>
Ex command.<br>
Mappings are not recognized in these commands.<br>
<span class="Special">{Vi: only in some versions}</span> Future: Will execute the<br>
register for each line in the address range.<br>
<br>
<a class="Constant" href="repeat.html#:@:" name=":@:">:@:</a><br>
:<span class="Special">[addr]</span>@: Repeat last command-line. First set cursor at line<br>
<span class="Special">[addr]</span> (default is current line). <span class="Special">{not in Vi}</span><br>
<br>
:<span class="Special">[addr]</span>@ <a class="Constant" href="repeat.html#:@@" name=":@@">:@@</a><br>
:<span class="Special">[addr]</span>@@ Repeat the previous :@<span class="Special">{0-9a-z"}</span>. First set cursor at<br>
line <span class="Special">[addr]</span> (default is current line). <span class="Special">{Vi: only in</span><br>
<span class="Special">some versions}</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
4. Using Vim scripts <a class="Constant" href="repeat.html#using-scripts" name="using-scripts">using-scripts</a><br>
<br>
For writing a Vim script, see chapter 41 of the user manual <a class="Identifier" href="usr_41.html">usr_41.txt</a>.<br>
<br>
<a class="Constant" href="repeat.html#:so" name=":so">:so</a> <a class="Constant" href="repeat.html#:source" name=":source">:source</a> <a class="Constant" href="repeat.html#load-vim-script" name="load-vim-script">load-vim-script</a><br>
:so[urce] <span class="Special">{file}</span> Read Ex commands from <span class="Special">{file}</span>. These are commands that<br>
start with a ":".<br>
Triggers the <a class="Identifier" href="autocmd.html#SourcePre">SourcePre</a> autocommand.<br>
<br>
:so[urce]! <span class="Special">{file}</span> Read Vim commands from <span class="Special">{file}</span>. These are commands<br>
that are executed from Normal mode, like you type<br>
them.<br>
When used after <a class="Identifier" href="repeat.html#:global">:global</a>, <a class="Identifier" href="editing.html#:argdo">:argdo</a>, <a class="Identifier" href="windows.html#:windo">:windo</a>,<br>
<a class="Identifier" href="windows.html#:bufdo">:bufdo</a>, in a loop or when another command follows<br>
the display won't be updated while executing the<br>
commands.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="repeat.html#:ru" name=":ru">:ru</a> <a class="Constant" href="repeat.html#:runtime" name=":runtime">:runtime</a><br>
:ru[ntime][!] <span class="Special">[where]</span> <span class="Special">{file}</span> ..<br>
Read Ex commands from <span class="Special">{file}</span> in each directory given<br>
by <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> and/or <a class="Type" href="options.html#'packpath'">'packpath'</a>. There is no error<br>
for non-existing files.<br>
<br>
Example:<br>
<div class="helpExample"> :runtime syntax/c.vim</div>
<br>
There can be multiple <span class="Special">{file}</span> arguments, separated by<br>
spaces. Each <span class="Special">{file}</span> is searched for in the first<br>
directory from <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>, then in the second<br>
directory, etc. Use a backslash to include a space<br>
inside <span class="Special">{file}</span> (although it's better not to use spaces<br>
in file names, it causes trouble).<br>
<br>
When [!] is included, all found files are sourced.<br>
When it is not included only the first found file is<br>
sourced.<br>
<br>
When <span class="Special">[where]</span> is omitted only <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> is used.<br>
Other values:<br>
START search under "start" in <a class="Type" href="options.html#'packpath'">'packpath'</a><br>
OPT search under "opt" in <a class="Type" href="options.html#'packpath'">'packpath'</a><br>
PACK search under "start" and "opt" in<br>
<a class="Type" href="options.html#'packpath'">'packpath'</a><br>
ALL first use <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>, then search<br>
under "start" and "opt" in <a class="Type" href="options.html#'packpath'">'packpath'</a><br>
<br>
When <span class="Special">{file}</span> contains wildcards it is expanded to all<br>
matching files. Example:<br>
<div class="helpExample"> :runtime! plugin/*.vim</div>
This is what Vim uses to load the plugin files when<br>
starting up. This similar command:<br>
<div class="helpExample"> :runtime plugin/*.vim</div>
would source the first file only.<br>
<br>
When <a class="Type" href="options.html#'verbose'">'verbose'</a> is one or higher, there is a message<br>
when no file could be found.<br>
When <a class="Type" href="options.html#'verbose'">'verbose'</a> is two or higher, there is a message<br>
about each searched file.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="repeat.html#:pa" name=":pa">:pa</a> <a class="Constant" href="repeat.html#:packadd" name=":packadd">:packadd</a> <a class="Constant" href="repeat.html#E919" name="E919">E919</a><br>
:pa[ckadd][!] <span class="Special">{name}</span> Search for an optional plugin directory in <a class="Type" href="options.html#'packpath'">'packpath'</a><br>
and source any plugin files found. The directory must<br>
match:<br>
<span class="PreProc">pack/*/opt/{name}</span><br>
The directory is added to <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> if it wasn't<br>
there yet.<br>
If the directory pack/*/opt/<span class="Special">{name}</span>/after exists it is<br>
added at the end of <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>.<br>
<br>
<span class="Todo">Note</span> that <span class="Special">{name}</span> is the directory name, not the name<br>
of the .vim file. All the files matching the pattern<br>
<span class="PreProc">pack/*/opt/{name}/plugin/**/*.vim</span><br>
will be sourced. This allows for using subdirectories<br>
below "plugin", just like with plugins in<br>
<a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>.<br>
<br>
If the filetype detection was not enabled yet (this<br>
is usually done with a "syntax enable" or "filetype<br>
on" command in your .vimrc file), this will also look<br>
for "<span class="Special">{name}</span>/ftdetect/*.vim" files.<br>
<br>
When the optional ! is added no plugin files or<br>
ftdetect scripts are loaded, only the matching<br>
directories are added to <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>. This is<br>
useful in your .vimrc. The plugins will then be<br>
loaded during initialization, see <a class="Identifier" href="starting.html#load-plugins">load-plugins</a>.<br>
<br>
Also see <a class="Identifier" href="repeat.html#pack-add">pack-add</a>.<br>
<br>
<a class="Constant" href="repeat.html#:packl" name=":packl">:packl</a> <a class="Constant" href="repeat.html#:packloadall" name=":packloadall">:packloadall</a><br>
:packl[oadall][!] Load all packages in the "start" directory under each<br>
entry in <a class="Type" href="options.html#'packpath'">'packpath'</a>.<br>
<br>
First all the directories found are added to<br>
<a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>, then the plugins found in the<br>
directories are sourced. This allows for a plugin to<br>
depend on something of another plugin, e.g. an<br>
"autoload" directory. See <a class="Identifier" href="repeat.html#packload-two-steps">packload-two-steps</a> for<br>
how this can be useful.<br>
<br>
This is normally done automatically during startup,<br>
after loading your .vimrc file. With this command it<br>
can be done earlier.<br>
<br>
Packages will be loaded only once. After this command<br>
it won't happen again. When the optional ! is added<br>
this command will load packages even when done before.<br>
<br>
An error only causes sourcing the script where it<br>
happens to be aborted, further plugins will be loaded.<br>
See <a class="Identifier" href="repeat.html#packages">packages</a>.<br>
<br>
:scripte[ncoding] <span class="Special">[encoding]</span> <a class="Constant" href="repeat.html#:scripte" name=":scripte">:scripte</a> <a class="Constant" href="repeat.html#:scriptencoding" name=":scriptencoding">:scriptencoding</a> <a class="Constant" href="repeat.html#E167" name="E167">E167</a><br>
Specify the character encoding used in the script.<br>
The following lines will be converted from <span class="Special">[encoding]</span><br>
to the value of the <a class="Type" href="options.html#'encoding'">'encoding'</a> option, if they are<br>
different. Examples:<br>
<div class="helpExample"> scriptencoding iso-8859-5<br>
scriptencoding cp932</div>
<br>
When <span class="Special">[encoding]</span> is empty, no conversion is done. This<br>
can be used to restrict conversion to a sequence of<br>
lines:<br>
<div class="helpExample"> scriptencoding euc-jp<br>
... lines to be converted ...<br>
scriptencoding<br>
... not converted ...</div>
<br>
When conversion isn't supported by the system, there<br>
is no error message and no conversion is done. When a<br>
line can't be converted there is no error and the<br>
original line is kept.<br>
<br>
Don't use "ucs-2" or "ucs-4", scripts cannot be in<br>
these encodings (they would contain NUL bytes).<br>
When a sourced script starts with a BOM (Byte Order<br>
Mark) in utf-8 format Vim will recognize it, no need<br>
to use ":scriptencoding utf-8" then.<br>
<br>
If you set the <a class="Type" href="options.html#'encoding'">'encoding'</a> option in your <a class="Identifier" href="starting.html#.vimrc">.vimrc</a>,<br>
<a class="Comment" href="repeat.html#:scriptencoding">:scriptencoding</a> must be placed after that. E.g.:<br>
<div class="helpExample"> set encoding=utf-8<br>
scriptencoding utf-8</div>
<br>
When compiled without the <a class="Identifier" href="various.html#+multi_byte">+multi_byte</a> feature this<br>
command is ignored.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="repeat.html#:scr" name=":scr">:scr</a> <a class="Constant" href="repeat.html#:scriptnames" name=":scriptnames">:scriptnames</a><br>
:scr[iptnames] List all sourced script names, in the order they were<br>
first sourced. The number is used for the script ID<br>
<a class="Identifier" href="map.html#<SID>"><SID></a>.<br>
<span class="Special">{not in Vi}</span> <span class="Special">{not available when compiled without the</span><br>
<a class="Identifier" href="various.html#+eval">+eval</a><span class="Special"> feature}</span><br>
<br>
<a class="Constant" href="repeat.html#:fini" name=":fini">:fini</a> <a class="Constant" href="repeat.html#:finish" name=":finish">:finish</a> <a class="Constant" href="repeat.html#E168" name="E168">E168</a><br>
:fini[sh] Stop sourcing a script. Can only be used in a Vim<br>
script file. This is a quick way to skip the rest of<br>
the file. If it is used after a <a class="Identifier" href="eval.html#:try">:try</a> but before the<br>
matching <a class="Identifier" href="eval.html#:finally">:finally</a> (if present), the commands<br>
following the ":finally" up to the matching <a class="Identifier" href="eval.html#:endtry">:endtry</a><br>
are executed first. This process applies to all<br>
nested ":try"s in the script. The outermost ":endtry"<br>
then stops sourcing the script. <span class="Special">{not in Vi}</span><br>
<br>
All commands and command sequences can be repeated by putting them in a named<br>
register and then executing it. There are two ways to get the commands in the<br>
register:<br>
- Use the record command "q". You type the commands once, and while they are<br>
being executed they are stored in a register. Easy, because you can see<br>
what you are doing. If you make a mistake, "p"ut the register into the<br>
file, edit the command sequence, and then delete it into the register<br>
again. You can continue recording by appending to the register (use an<br>
uppercase letter).<br>
- Delete or yank the command sequence into the register.<br>
<br>
Often used command sequences can be put under a function key with the ':map'<br>
command.<br>
<br>
An alternative is to put the commands in a file, and execute them with the<br>
':source!' command. Useful for long command sequences. Can be combined with<br>
the ':map' command to put complicated commands under a function key.<br>
<br>
The ':source' command reads Ex commands from a file line by line. You will<br>
have to type any needed keyboard input. The ':source!' command reads from a<br>
script file character by character, interpreting each character as if you<br>
typed it.<br>
<br>
Example: When you give the ":!ls" command you get the <a class="Identifier" href="message.html#hit-enter">hit-enter</a> prompt. If<br>
you ':source' a file with the line "!ls" in it, you will have to type the<br>
<span class="Special"><Enter></span> yourself. But if you ':source!' a file with the line ":!ls" in it,<br>
the next characters from that file are read until a <span class="Special"><CR></span> is found. You will<br>
not have to type <span class="Special"><CR></span> yourself, unless ":!ls" was the last line in the file.<br>
<br>
It is possible to put ':source[!]' commands in the script file, so you can<br>
make a top-down hierarchy of script files. The ':source' command can be<br>
nested as deep as the number of files that can be opened at one time (about<br>
15). The ':source!' command can be nested up to 15 levels deep.<br>
<br>
You can use the "<span class="Special"><sfile></span>" string (literally, this is not a special key) inside<br>
of the sourced file, in places where a file name is expected. It will be<br>
replaced by the file name of the sourced file. For example, if you have a<br>
"other.vimrc" file in the same directory as your ".vimrc" file, you can source<br>
it from your ".vimrc" file with this command:<br>
<div class="helpExample"> :source <sfile>:h/other.vimrc</div>
<br>
In script files terminal-dependent key codes are represented by<br>
terminal-independent two character codes. This means that they can be used<br>
in the same way on different kinds of terminals. The first character of a<br>
key code is 0x80 or 128, shown on the screen as "~@". The second one can be<br>
found in the list <a class="Identifier" href="intro.html#key-notation">key-notation</a>. Any of these codes can also be entered<br>
with <span class="Special">CTRL-V</span> followed by the three digit decimal code. This does NOT work for<br>
the <span class="Special"><t_xx></span> termcap codes, these can only be used in mappings.<br>
<br>
<a class="Constant" href="repeat.html#:source_crnl" name=":source_crnl">:source_crnl</a> <a class="Constant" href="repeat.html#W15" name="W15">W15</a><br>
MS-DOS, Win32 and OS/2: Files that are read with ":source" normally have<br>
<span class="Special"><CR><NL></span> <span class="Special"><EOL></span>s. These always work. If you are using a file with <span class="Special"><NL></span> <span class="Special"><EOL></span>s<br>
(for example, a file made on Unix), this will be recognized if <a class="Type" href="options.html#'fileformats'">'fileformats'</a><br>
is not empty and the first line does not end in a <span class="Special"><CR></span>. This fails if the<br>
first line has something like ":map <span class="Special"><F1></span> :help^M", where "^M" is a <span class="Special"><CR></span>. If<br>
the first line ends in a <span class="Special"><CR></span>, but following ones don't, you will get an error<br>
message, because the <span class="Special"><CR></span> from the first lines will be lost.<br>
<br>
Mac Classic: Files that are read with ":source" normally have <span class="Special"><CR></span> <span class="Special"><EOL></span>s.<br>
These always work. If you are using a file with <span class="Special"><NL></span> <span class="Special"><EOL></span>s (for example, a<br>
file made on Unix), this will be recognized if <a class="Type" href="options.html#'fileformats'">'fileformats'</a> is not empty and<br>
the first line does not end in a <span class="Special"><CR></span>. Be careful not to use a file with <span class="Special"><NL></span><br>
linebreaks which has a <span class="Special"><CR></span> in first line.<br>
<br>
On other systems, Vim expects ":source"ed files to end in a <span class="Special"><NL></span>. These<br>
always work. If you are using a file with <span class="Special"><CR><NL></span> <span class="Special"><EOL></span>s (for example, a<br>
file made on MS-DOS), all lines will have a trailing <span class="Special"><CR></span>. This may cause<br>
problems for some commands (e.g., mappings). There is no automatic <span class="Special"><EOL></span><br>
detection, because it's common to start with a line that defines a mapping<br>
that ends in a <span class="Special"><CR></span>, which will confuse the automaton.<br>
<br>
<a class="Constant" href="repeat.html#line-continuation" name="line-continuation">line-continuation</a><br>
Long lines in a ":source"d Ex command script file can be split by inserting<br>
a line continuation symbol "\" (backslash) at the start of the next line.<br>
There can be white space before the backslash, which is ignored.<br>
<br>
Example: the lines<br>
<div class="helpExample"> :set comments=sr:/*,mb:*,el:*/,<br>
\://,<br>
\b:#,<br>
\:%,<br>
\n:>,<br>
\fb:-</div>
are interpreted as if they were given in one line:<br>
:set comments=sr:/*,mb:*,el:*/,://,b:#,:%,n:>,fb:-<br>
<br>
All leading whitespace characters in the line before a backslash are ignored.<br>
<span class="Todo">Note</span> however that trailing whitespace in the line before it cannot be<br>
inserted freely; it depends on the position where a command is split up<br>
whether additional whitespace is allowed or not.<br>
<br>
When a space is required it's best to put it right after the backslash. A<br>
space at the end of a line is hard to see and may be accidentally deleted.<br>
<div class="helpExample"> :syn match Comment<br>
\ "very long regexp"<br>
\ keepend</div>
<br>
There is a problem with the ":append" and ":insert" commands:<br>
<div class="helpExample"> :1append<br>
\asdf<br>
.</div>
The backslash is seen as a line-continuation symbol, thus this results in the<br>
command:<br>
<div class="helpExample"> :1appendasdf<br>
.</div>
To avoid this, add the 'C' flag to the <a class="Type" href="options.html#'cpoptions'">'cpoptions'</a> option:<br>
<div class="helpExample"> :set cpo+=C<br>
:1append<br>
\asdf<br>
.<br>
:set cpo-=C</div>
<br>
<span class="Todo">Note</span> that when the commands are inside a function, you need to add the 'C'<br>
flag when defining the function, it is not relevant when executing it.<br>
<div class="helpExample"> :set cpo+=C<br>
:function Foo()<br>
:1append<br>
\asdf<br>
.<br>
:endfunction<br>
:set cpo-=C</div>
<br>
Rationale:<br>
Most programs work with a trailing backslash to indicate line<br>
continuation. Using this in Vim would cause incompatibility with Vi.<br>
For example for this Vi mapping:<br>
<div class="helpExample"> :map xx asdf\</div>
Therefore the unusual leading backslash is used.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
5. Using Vim packages <a class="Constant" href="repeat.html#packages" name="packages">packages</a><br>
<br>
A Vim package is a directory that contains one or more plugins. The<br>
advantages over normal plugins:<br>
- A package can be downloaded as an archive and unpacked in its own directory.<br>
Thus the files are not mixed with files of other plugins. That makes it<br>
easy to update and remove.<br>
- A package can be a git, mercurial, etc. repository. That makes it really<br>
easy to update.<br>
- A package can contain multiple plugins that depend on each other.<br>
- A package can contain plugins that are automatically loaded on startup and<br>
ones that are only loaded when needed with <a class="Comment" href="repeat.html#:packadd">:packadd</a>.<br>
<br>
<br>
<span class="PreProc">Using a package and loading automatically</span><br>
<br>
Let's assume your Vim files are in the "~/.vim" directory and you want to add a<br>
package from a zip archive "/tmp/foopack.zip":<br>
% mkdir -p ~/.vim/pack/foo<br>
% cd ~/.vim/pack/foo<br>
% unzip /tmp/foopack.zip<br>
<br>
The directory name "foo" is arbitrary, you can pick anything you like.<br>
<br>
You would now have these files under ~/.vim:<br>
pack/foo/README.txt<br>
pack/foo/start/foobar/plugin/foo.vim<br>
pack/foo/start/foobar/syntax/some.vim<br>
pack/foo/opt/foodebug/plugin/debugger.vim<br>
<br>
When Vim starts up, after processing your .vimrc, it scans all directories in<br>
<a class="Type" href="options.html#'packpath'">'packpath'</a> for plugins under the "pack/*/start" directory. First all those<br>
directories are added to <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>. Then all the plugins are loaded.<br>
See <a class="Identifier" href="repeat.html#packload-two-steps">packload-two-steps</a> for how these two steps can be useful.<br>
<br>
In the example Vim will find "pack/foo/start/foobar/plugin/foo.vim" and adds <br>
"~/.vim/pack/foo/start/foobar" to <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>.<br>
<br>
If the "foobar" plugin kicks in and sets the <a class="Type" href="options.html#'filetype'">'filetype'</a> to "some", Vim will<br>
find the syntax/some.vim file, because its directory is in <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>.<br>
<br>
Vim will also load ftdetect files, if there are any.<br>
<br>
<span class="Todo">Note</span> that the files under "pack/foo/opt" are not loaded automatically, only the<br>
ones under "pack/foo/start". See <a class="Identifier" href="repeat.html#pack-add">pack-add</a> below for how the "opt" directory<br>
is used.<br>
<br>
Loading packages automatically will not happen if loading plugins is disabled,<br>
see <a class="Identifier" href="starting.html#load-plugins">load-plugins</a>.<br>
<br>
To load packages earlier, so that <a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> gets updated:<br>
<div class="helpExample"> :packloadall</div>
This also works when loading plugins is disabled. The automatic loading will<br>
only happen once.<br>
<br>
If the package has an "after" directory, that directory is added to the end of<br>
<a class="Type" href="options.html#'runtimepath'">'runtimepath'</a>, so that anything there will be loaded later.<br>
<br>
<br>
<span class="PreProc">Using a single plugin and loading it automatically</span><br>
<br>
If you don't have a package but a single plugin, you need to create the extra<br>
directory level:<br>
% mkdir -p ~/.vim/pack/foo/start/foobar<br>
% cd ~/.vim/pack/foo/start/foobar<br>
% unzip /tmp/someplugin.zip<br>
<br>
You would now have these files:<br>
pack/foo/start/foobar/plugin/foo.vim<br>
pack/foo/start/foobar/syntax/some.vim<br>
<br>
From here it works like above.<br>
<br>
<br>
<span class="PreProc">Optional plugins</span><br>
<a class="Constant" href="repeat.html#pack-add" name="pack-add">pack-add</a><br>
To load an optional plugin from a pack use the <a class="Comment" href="repeat.html#:packadd">:packadd</a> command:<br>
<div class="helpExample"> :packadd foodebug</div>
This searches for "pack/*/opt/foodebug" in <a class="Type" href="options.html#'packpath'">'packpath'</a> and will find<br>
~/.vim/pack/foo/opt/foodebug/plugin/debugger.vim and source it.<br>
<br>
This could be done if some conditions are met. For example, depending on<br>
whether Vim supports a feature or a dependency is missing.<br>
<br>
You can also load an optional plugin at startup, by putting this command in<br>
your <a class="Identifier" href="starting.html#.vimrc">.vimrc</a>:<br>
<div class="helpExample"> :packadd! foodebug</div>
The extra "!" is so that the plugin isn't loaded if Vim was started with<br>
<a class="Identifier" href="starting.html#--noplugin">--noplugin</a>.<br>
<br>
It is perfectly normal for a package to only have files in the "opt"<br>
directory. You then need to load each plugin when you want to use it.<br>
<br>
<br>
<span class="PreProc">Where to put what</span><br>
<br>
Since color schemes, loaded with <a class="Comment" href="syntax.html#:colorscheme">:colorscheme</a>, are found below<br>
"pack/*/start" and "pack/*/opt", you could put them anywhere. We recommend<br>
you put them below "pack/*/opt", for example<br>
".vim/pack/mycolors/opt/dark/colors/very_dark.vim".<br>
<br>
Filetype plugins should go under "pack/*/start", so that they are always<br>
found. Unless you have more than one plugin for a file type and want to<br>
select which one to load with <a class="Comment" href="repeat.html#:packadd">:packadd</a>. E.g. depending on the compiler<br>
version:<br>
<div class="helpExample"> if foo_compiler_version > 34<br>
packadd foo_new<br>
else<br>
packadd foo_old<br>
endif</div>
<br>
The "after" directory is most likely not useful in a package. It's not<br>
disallowed though.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
6. Creating Vim packages <a class="Constant" href="repeat.html#package-create" name="package-create">package-create</a><br>
<br>
This assumes you write one or more plugins that you distribute as a package.<br>
<br>
If you have two unrelated plugins you would use two packages, so that Vim<br>
users can chose what they include or not. Or you can decide to use one<br>
package with optional plugins, and tell the user to add the ones he wants with<br>
<a class="Comment" href="repeat.html#:packadd">:packadd</a>.<br>
<br>
Decide how you want to distribute the package. You can create an archive or<br>
you could use a repository. An archive can be used by more users, but is a<br>
bit harder to update to a new version. A repository can usually be kept<br>
up-to-date easily, but it requires a program like "git" to be available.<br>
You can do both, github can automatically create an archive for a release.<br>
<br>
Your directory layout would be like this:<br>
start/foobar/plugin/foo.vim " always loaded, defines commands<br>
start/foobar/plugin/bar.vim " always loaded, defines commands<br>
start/foobar/autoload/foo.vim " loaded when foo command used<br>
start/foobar/doc/foo.txt " help for foo.vim<br>
start/foobar/doc/tags " help tags<br>
opt/fooextra/plugin/extra.vim " optional plugin, defines commands<br>
opt/fooextra/autoload/extra.vim " loaded when extra command used<br>
opt/fooextra/doc/extra.txt " help for extra.vim<br>
opt/fooextra/doc/tags " help tags<br>
<br>
This allows for the user to do:<br>
<div class="helpExample"> mkdir ~/.vim/pack/myfoobar<br>
cd ~/.vim/pack/myfoobar<br>
git clone <a href="https://github.com/you/foobar.git">https://github.com/you/foobar.git</a></div>
<br>
Here "myfoobar" is a name that the user can choose, the only condition is that<br>
it differs from other packages.<br>
<br>
In your documentation you explain what the plugins do, and tell the user how<br>
to load the optional plugin:<br>
<div class="helpExample"> :packadd! fooextra</div>
<br>
You could add this packadd command in one of your plugins, to be executed when<br>
the optional plugin is needed.<br>
<br>
Run the <a class="Comment" href="helphelp.html#:helptags">:helptags</a> command to generate the doc/tags file. Including this<br>
generated file in the package means that the user can drop the package in his<br>
pack directory and the help command works right away. Don't forget to re-run<br>
the command after changing the plugin help:<br>
<div class="helpExample"> :helptags path/start/foobar/doc<br>
:helptags path/opt/fooextra/doc</div>
<br>
<br>
<span class="PreProc">Dependencies between plugins</span><br>
<a class="Constant" href="repeat.html#packload-two-steps" name="packload-two-steps">packload-two-steps</a><br>
Suppose you have two plugins that depend on the same functionality. You can<br>
put the common functionality in an autoload directory, so that it will be<br>
found automatically. Your package would have these files:<br>
<br>
pack/foo/start/one/plugin/one.vim <br>
<div class="helpExample"> call foolib#getit()</div>
pack/foo/start/two/plugin/two.vim<br>
<div class="helpExample"> call foolib#getit()</div>
pack/foo/start/lib/autoload/foolib.vim<br>
<div class="helpExample"> func foolib#getit()</div>
<br>
This works, because loading packages will first add all found directories to<br>
<a class="Type" href="options.html#'runtimepath'">'runtimepath'</a> before sourcing the plugins.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
7. Debugging scripts <a class="Constant" href="repeat.html#debug-scripts" name="debug-scripts">debug-scripts</a><br>
<br>
Besides the obvious messages that you can add to your scripts to find out what<br>
they are doing, Vim offers a debug mode. This allows you to step through a<br>
sourced file or user function and set breakpoints.<br>
<br>
<span class="Todo">NOTE</span>: The debugging mode is far from perfect. Debugging will have side<br>
effects on how Vim works. You cannot use it to debug everything. For<br>
example, the display is messed up by the debugging messages.<br>
<span class="Special">{Vi does not have a debug mode}</span><br>
<br>
An alternative to debug mode is setting the <a class="Type" href="options.html#'verbose'">'verbose'</a> option. With a bigger<br>
number it will give more verbose messages about what Vim is doing.<br>
<br>
<br>
<span class="Statement">STARTING DEBUG MODE </span><a class="Constant" href="repeat.html#debug-mode" name="debug-mode">debug-mode</a><br>
<br>
To enter debugging mode use one of these methods:<br>
1. Start Vim with the <a class="Identifier" href="starting.html#-D">-D</a> argument:<br>
<div class="helpExample"> vim -D file.txt</div>
Debugging will start as soon as the first vimrc file is sourced. This is<br>
useful to find out what is happening when Vim is starting up. A side<br>
effect is that Vim will switch the terminal mode before initialisations<br>
have finished, with unpredictable results.<br>
For a GUI-only version (Windows, Macintosh) the debugging will start as<br>
soon as the GUI window has been opened. To make this happen early, add a<br>
":gui" command in the vimrc file.<br>
<a class="Constant" href="repeat.html#:debug" name=":debug">:debug</a><br>
2. Run a command with ":debug" prepended. Debugging will only be done while<br>
this command executes. Useful for debugging a specific script or user<br>
function. And for scripts and functions used by autocommands. Example:<br>
<div class="helpExample"> :debug edit test.txt.gz</div>
<br>
3. Set a breakpoint in a sourced file or user function. You could do this in<br>
the command line:<br>
<div class="helpExample"> vim -c "breakadd file */explorer.vim" .</div>
This will run Vim and stop in the first line of the "explorer.vim" script.<br>
Breakpoints can also be set while in debugging mode.<br>
<br>
In debugging mode every executed command is displayed before it is executed.<br>
Comment lines, empty lines and lines that are not executed are skipped. When<br>
a line contains two commands, separated by "|", each command will be displayed<br>
separately.<br>
<br>
<br>
DEBUG MODE<br>
<br>
Once in debugging mode, the usual Ex commands can be used. For example, to<br>
inspect the value of a variable:<br>
<div class="helpExample"> echo idx</div>
When inside a user function, this will print the value of the local variable<br>
"idx". Prepend "g:" to get the value of a global variable:<br>
<div class="helpExample"> echo g:idx</div>
All commands are executed in the context of the current function or script.<br>
You can also set options, for example setting or resetting <a class="Type" href="options.html#'verbose'">'verbose'</a> will show<br>
what happens, but you might want to set it just before executing the lines you<br>
are interested in:<br>
<div class="helpExample"> :set verbose=20</div>
<br>
Commands that require updating the screen should be avoided, because their<br>
effect won't be noticed until after leaving debug mode. For example:<br>
<div class="helpExample"> :help</div>
won't be very helpful.<br>
<br>
There is a separate command-line history for debug mode.<br>
<br>
The line number for a function line is relative to the start of the function.<br>
If you have trouble figuring out where you are, edit the file that defines<br>
the function in another Vim, search for the start of the function and do<br>
"99j". Replace "99" with the line number.<br>
<br>
Additionally, these commands can be used:<br>
<a class="Constant" href="repeat.html#>cont" name=">cont">>cont</a><br>
cont Continue execution until the next breakpoint is hit.<br>
<a class="Constant" href="repeat.html#>quit" name=">quit">>quit</a><br>
quit Abort execution. This is like using <span class="Special">CTRL-C</span>, some<br>
things might still be executed, doesn't abort<br>
everything. Still stops at the next breakpoint.<br>
<a class="Constant" href="repeat.html#>next" name=">next">>next</a><br>
next Execute the command and come back to debug mode when<br>
it's finished. This steps over user function calls<br>
and sourced files.<br>
<a class="Constant" href="repeat.html#>step" name=">step">>step</a><br>
step Execute the command and come back to debug mode for<br>
the next command. This steps into called user<br>
functions and sourced files.<br>
<a class="Constant" href="repeat.html#>interrupt" name=">interrupt">>interrupt</a><br>
interrupt This is like using <span class="Special">CTRL-C</span>, but unlike ">quit" comes<br>
back to debug mode for the next command that is<br>
executed. Useful for testing <a class="Identifier" href="eval.html#:finally">:finally</a> and <a class="Identifier" href="eval.html#:catch">:catch</a><br>
on interrupt exceptions.<br>
<a class="Constant" href="repeat.html#>finish" name=">finish">>finish</a><br>
finish Finish the current script or user function and come<br>
back to debug mode for the command after the one that<br>
sourced or called it.<br>
<a class="Constant" href="repeat.html#>bt" name=">bt">>bt</a><br>
<a class="Constant" href="repeat.html#>backtrace" name=">backtrace">>backtrace</a><br>
<a class="Constant" href="repeat.html#>where" name=">where">>where</a><br>
backtrace Show the call stacktrace for current debugging session.<br>
bt<br>
where<br>
<a class="Constant" href="repeat.html#>frame" name=">frame">>frame</a><br>
frame <span class="Special">N</span> Goes to <span class="Special">N</span> backtrace level. + and - signs make movement<br>
relative. E.g., ":frame +3" goes three frames up.<br>
<a class="Constant" href="repeat.html#>up" name=">up">>up</a><br>
up Goes one level up from call stacktrace.<br>
<a class="Constant" href="repeat.html#>down" name=">down">>down</a><br>
down Goes one level down from call stacktrace.<br>
<br>
About the additional commands in debug mode:<br>
- There is no command-line completion for them, you get the completion for the<br>
normal Ex commands only.<br>
- You can shorten them, up to a single character, unless more than one command<br>
starts with the same letter. "f" stands for "finish", use "fr" for "frame".<br>
- Hitting <span class="Special"><CR></span> will repeat the previous one. When doing another command, this<br>
is reset (because it's not clear what you want to repeat).<br>
- When you want to use the Ex command with the same name, prepend a colon:<br>
":cont", ":next", ":finish" (or shorter).<br>
<br>
The backtrace shows the hierarchy of function calls, e.g.:<br>
<span class="PreProc">>bt</span><br>
<span class="PreProc">3 function One[3]</span><br>
<span class="PreProc">2 Two[3]</span><br>
<span class="PreProc">->1 Three[3]</span><br>
<span class="PreProc">0 Four</span><br>
<span class="PreProc">line 1: let four = 4</span><br>
<br>
The "->" points to the current frame. Use "up", "down" and "frame <span class="Special">N</span>" to<br>
select another frame.<br>
<br>
In the current frame you can evaluate the local function variables. There is<br>
no way to see the command at the current line yet.<br>
<br>
<br>
DEFINING BREAKPOINTS<br>
<a class="Constant" href="repeat.html#:breaka" name=":breaka">:breaka</a> <a class="Constant" href="repeat.html#:breakadd" name=":breakadd">:breakadd</a><br>
:breaka[dd] func <span class="Special">[lnum]</span> <span class="Special">{name}</span><br>
Set a breakpoint in a function. Example:<br>
<div class="helpExample"> :breakadd func Explore</div>
Doesn't check for a valid function name, thus the breakpoint<br>
can be set before the function is defined.<br>
<br>
:breaka[dd] file <span class="Special">[lnum]</span> <span class="Special">{name}</span><br>
Set a breakpoint in a sourced file. Example:<br>
<div class="helpExample"> :breakadd file 43 .vimrc</div>
<br>
:breaka[dd] here<br>
Set a breakpoint in the current line of the current file.<br>
Like doing:<br>
<div class="helpExample"> :breakadd file <cursor-line> <current-file></div>
<span class="Todo">Note</span> that this only works for commands that are executed when<br>
sourcing the file, not for a function defined in that file.<br>
<br>
The <span class="Special">[lnum]</span> is the line number of the breakpoint. Vim will stop at or after<br>
this line. When omitted line 1 is used.<br>
<br>
<a class="Constant" href="repeat.html#:debug-name" name=":debug-name">:debug-name</a><br>
<span class="Special">{name}</span> is a pattern that is matched with the file or function name. The<br>
pattern is like what is used for autocommands. There must be a full match (as<br>
if the pattern starts with "^" and ends in "$"). A "*" matches any sequence<br>
of characters. <a class="Type" href="options.html#'ignorecase'">'ignorecase'</a> is not used, but "\c" can be used in the pattern<br>
to ignore case <a class="Identifier" href="pattern.html#/\c">/\c</a>. Don't include the () for the function name!<br>
<br>
The match for sourced scripts is done against the full file name. If no path<br>
is specified the current directory is used. Examples:<br>
<div class="helpExample"> breakadd file explorer.vim</div>
matches "explorer.vim" in the current directory.<br>
<div class="helpExample"> breakadd file *explorer.vim</div>
matches ".../plugin/explorer.vim", ".../plugin/iexplorer.vim", etc.<br>
<div class="helpExample"> breakadd file */explorer.vim</div>
matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory.<br>
<br>
The match for functions is done against the name as it's shown in the output<br>
of ":function". For local functions this means that something like "<span class="Special"><SNR></span>99_"<br>
is prepended.<br>
<br>
<span class="Todo">Note</span> that functions are first loaded and later executed. When they are loaded<br>
the "file" breakpoints are checked, when they are executed the "func"<br>
breakpoints.<br>
<br>
<br>
DELETING BREAKPOINTS<br>
<a class="Constant" href="repeat.html#:breakd" name=":breakd">:breakd</a> <a class="Constant" href="repeat.html#:breakdel" name=":breakdel">:breakdel</a> <a class="Constant" href="repeat.html#E161" name="E161">E161</a><br>
:breakd[el] <span class="Special">{nr}</span><br>
Delete breakpoint <span class="Special">{nr}</span>. Use <a class="Identifier" href="repeat.html#:breaklist">:breaklist</a> to see the number of<br>
each breakpoint.<br>
<br>
:breakd[el] *<br>
Delete all breakpoints.<br>
<br>
:breakd[el] func <span class="Special">[lnum]</span> <span class="Special">{name}</span><br>
Delete a breakpoint in a function.<br>
<br>
:breakd[el] file <span class="Special">[lnum]</span> <span class="Special">{name}</span><br>
Delete a breakpoint in a sourced file.<br>
<br>
:breakd[el] here<br>
Delete a breakpoint at the current line of the current file.<br>
<br>
When <span class="Special">[lnum]</span> is omitted, the first breakpoint in the function or file is<br>
deleted.<br>
The <span class="Special">{name}</span> must be exactly the same as what was typed for the ":breakadd"<br>
command. "explorer", "*explorer.vim" and "*explorer*" are different.<br>
<br>
<br>
LISTING BREAKPOINTS<br>
<a class="Constant" href="repeat.html#:breakl" name=":breakl">:breakl</a> <a class="Constant" href="repeat.html#:breaklist" name=":breaklist">:breaklist</a><br>
:breakl[ist]<br>
List all breakpoints.<br>
<br>
<br>
OBSCURE<br>
<br>
<a class="Constant" href="repeat.html#:debugg" name=":debugg">:debugg</a> <a class="Constant" href="repeat.html#:debuggreedy" name=":debuggreedy">:debuggreedy</a><br>
:debugg[reedy]<br>
Read debug mode commands from the normal input stream, instead<br>
of getting them directly from the user. Only useful for test<br>
scripts. Example:<br>
<div class="helpExample"> echo 'q^Mq' | vim -e -s -c debuggreedy -c 'breakadd file script.vim' -S script.vim</div>
<br>
:0debugg[reedy]<br>
Undo ":debuggreedy": get debug mode commands directly from the<br>
user, don't use typeahead for debug commands.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
8. Profiling <a class="Constant" href="repeat.html#profile" name="profile">profile</a> <a class="Constant" href="repeat.html#profiling" name="profiling">profiling</a><br>
<br>
Profiling means that Vim measures the time that is spent on executing<br>
functions and/or scripts. The <a class="Identifier" href="various.html#+profile">+profile</a> feature is required for this.<br>
It is only included when Vim was compiled with "huge" features.<br>
<span class="Special">{Vi does not have profiling}</span><br>
<br>
You can also use the <a class="Identifier" href="eval.html#reltime()">reltime()</a> function to measure time. This only requires<br>
the <a class="Identifier" href="various.html#+reltime">+reltime</a> feature, which is present more often.<br>
<br>
For profiling syntax highlighting see <a class="Identifier" href="syntax.html#:syntime">:syntime</a>.<br>
<br>
For example, to profile the one_script.vim script file:<br>
<div class="helpExample"> :profile start /tmp/one_script_profile<br>
:profile file one_script.vim<br>
:source one_script.vim<br>
:exit</div>
<br>
<br>
:prof[ile] start <span class="Special">{fname}</span> <a class="Constant" href="repeat.html#:prof" name=":prof">:prof</a> <a class="Constant" href="repeat.html#:profile" name=":profile">:profile</a> <a class="Constant" href="repeat.html#E750" name="E750">E750</a><br>
Start profiling, write the output in <span class="Special">{fname}</span> upon exit.<br>
"~/" and environment variables in <span class="Special">{fname}</span> will be expanded.<br>
If <span class="Special">{fname}</span> already exists it will be silently overwritten.<br>
The variable <a class="Identifier" href="eval.html#v:profiling">v:profiling</a> is set to one.<br>
<br>
:prof[ile] pause<br>
Don't profile until the following ":profile continue". Can be<br>
used when doing something that should not be counted (e.g., an<br>
external command). Does not nest.<br>
<br>
:prof[ile] continue<br>
Continue profiling after ":profile pause".<br>
<br>
:prof[ile] func <span class="Special">{pattern}</span><br>
Profile function that matches the pattern <span class="Special">{pattern}</span>.<br>
See <a class="Identifier" href="repeat.html#:debug-name">:debug-name</a> for how <span class="Special">{pattern}</span> is used.<br>
<br>
:prof[ile][!] file <span class="Special">{pattern}</span><br>
Profile script file that matches the pattern <span class="Special">{pattern}</span>.<br>
See <a class="Identifier" href="repeat.html#:debug-name">:debug-name</a> for how <span class="Special">{pattern}</span> is used.<br>
This only profiles the script itself, not the functions<br>
defined in it.<br>
When the [!] is added then all functions defined in the script<br>
will also be profiled.<br>
<span class="Todo">Note</span> that profiling only starts when the script is loaded<br>
after this command. A :profile command in the script itself<br>
won't work.<br>
<br>
<br>
:profd[el] ... <a class="Constant" href="repeat.html#:profd" name=":profd">:profd</a> <a class="Constant" href="repeat.html#:profdel" name=":profdel">:profdel</a><br>
Stop profiling for the arguments specified. See <a class="Identifier" href="repeat.html#:breakdel">:breakdel</a><br>
for the arguments.<br>
<br>
<br>
You must always start with a ":profile start fname" command. The resulting<br>
file is written when Vim exits. Here is an example of the output, with line<br>
numbers prepended for the explanation:<br>
<br>
<span class="PreProc">1 FUNCTION Test2()</span><br>
<span class="PreProc">2 Called 1 time</span><br>
<span class="PreProc">3 Total time: 0.155251</span><br>
<span class="PreProc">4 Self time: 0.002006</span><br>
<span class="PreProc">5 </span><br>
<span class="PreProc">6 count total (s) self (s)</span><br>
<span class="PreProc">7 9 0.000096 for i in range(8)</span><br>
<span class="PreProc">8 8 0.153655 0.000410 call Test3()</span><br>
<span class="PreProc">9 8 0.000070 endfor</span><br>
<span class="PreProc">10 " Ask a question</span><br>
<span class="PreProc">11 1 0.001341 echo input("give me an answer: ")</span><br>
<br>
The header (lines 1-4) gives the time for the whole function. The "Total"<br>
time is the time passed while the function was executing. The "Self" time is<br>
the "Total" time reduced by time spent in:<br>
- other user defined functions<br>
- sourced scripts<br>
- executed autocommands<br>
- external (shell) commands<br>
<br>
Lines 7-11 show the time spent in each executed line. Lines that are not<br>
executed do not count. Thus a comment line is never counted.<br>
<br>
The Count column shows how many times a line was executed. <span class="Todo">Note</span> that the<br>
"for" command in line 7 is executed one more time as the following lines.<br>
That is because the line is also executed to detect the end of the loop.<br>
<br>
The time Vim spends waiting for user input isn't counted at all. Thus how<br>
long you take to respond to the input() prompt is irrelevant.<br>
<br>
Profiling should give a good indication of where time is spent, but keep in<br>
mind there are various things that may clobber the results:<br>
<br>
- The accuracy of the time measured depends on the gettimeofday() system<br>
function. It may only be as accurate as 1/100 second, even though the times<br>
are displayed in micro seconds.<br>
<br>
- Real elapsed time is measured, if other processes are busy they may cause<br>
delays at unpredictable moments. You may want to run the profiling several<br>
times and use the lowest results.<br>
<br>
- If you have several commands in one line you only get one time. Split the<br>
line to see the time for the individual commands.<br>
<br>
- The time of the lines added up is mostly less than the time of the whole<br>
function. There is some overhead in between.<br>
<br>
- Functions that are deleted before Vim exits will not produce profiling<br>
information. You can check the <a class="Identifier" href="eval.html#v:profiling">v:profiling</a> variable if needed:<br>
<div class="helpExample"> :if !v:profiling<br>
: delfunc MyFunc<br>
:endif</div>
<br>
- Profiling may give weird results on multi-processor systems, when sleep<br>
mode kicks in or the processor frequency is reduced to save power.<br>
<br>
- The "self" time is wrong when a function is used recursively.<br>
<br>
<br>
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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。