代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>if_tcl - 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>
/ if_tcl<br />
<a name="top"></a><h1>if_tcl - 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="if_tcl.html" name="if_tcl.txt">if_tcl.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2016 Jan 01<br>
<br>
<br>
<span class="Identifier">VIM REFERENCE MANUAL by Ingo Wilken</span><br>
<br>
<br>
The Tcl Interface to Vim <a class="Constant" href="if_tcl.html#tcl" name="tcl">tcl</a> <a class="Constant" href="if_tcl.html#Tcl" name="Tcl">Tcl</a> <a class="Constant" href="if_tcl.html#TCL" name="TCL">TCL</a><br>
<br>
1. Commands <a class="Identifier" href="if_tcl.html#tcl-ex-commands">tcl-ex-commands</a><br>
2. Tcl commands <a class="Identifier" href="if_tcl.html#tcl-commands">tcl-commands</a><br>
3. Tcl variables <a class="Identifier" href="if_tcl.html#tcl-variables">tcl-variables</a><br>
4. Tcl window commands <a class="Identifier" href="if_tcl.html#tcl-window-cmds">tcl-window-cmds</a><br>
5. Tcl buffer commands <a class="Identifier" href="if_tcl.html#tcl-buffer-cmds">tcl-buffer-cmds</a><br>
6. Miscellaneous; Output from Tcl <a class="Identifier" href="if_tcl.html#tcl-misc">tcl-misc</a> <a class="Identifier" href="if_tcl.html#tcl-output">tcl-output</a><br>
7. Known bugs & problems <a class="Identifier" href="if_tcl.html#tcl-bugs">tcl-bugs</a><br>
8. Examples <a class="Identifier" href="if_tcl.html#tcl-examples">tcl-examples</a><br>
9. Dynamic loading <a class="Identifier" href="if_tcl.html#tcl-dynamic">tcl-dynamic</a><br>
<br>
<span class="Special">{Vi does not have any of these commands}</span> <a class="Constant" href="if_tcl.html#E280" name="E280">E280</a><br>
<br>
The Tcl interface only works when Vim was compiled with the <a class="Identifier" href="various.html#+tcl">+tcl</a> feature.<br>
<br>
WARNING: There are probably still some bugs. Please send bug reports,<br>
comments, ideas etc to <Ingo.Wilken@informatik.uni-oldenburg.de><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Commands <a class="Constant" href="if_tcl.html#tcl-ex-commands" name="tcl-ex-commands">tcl-ex-commands</a> <a class="Constant" href="if_tcl.html#E571" name="E571">E571</a> <a class="Constant" href="if_tcl.html#E572" name="E572">E572</a><br>
<br>
<a class="Constant" href="if_tcl.html#:tcl" name=":tcl">:tcl</a> <a class="Constant" href="if_tcl.html#:tc" name=":tc">:tc</a><br>
:tc[l] <span class="Special">{cmd}</span> Execute Tcl command <span class="Special">{cmd}</span>. A simple check if <a class="Comment" href="if_tcl.html#:tcl">:tcl</a><br>
is working:<br>
<div class="helpExample"> :tcl puts "Hello"</div>
<br>
:<span class="Special">[range]</span>tc[l] << <span class="Special">{endmarker}</span><br>
<span class="Special">{script}</span><br>
<span class="Special">{endmarker}</span><br>
Execute Tcl script <span class="Special">{script}</span>.<br>
<span class="Todo">Note</span>: This command doesn't work when the Tcl feature<br>
wasn't compiled in. To avoid errors, see<br>
<a class="Identifier" href="if_perl.html#script-here">script-here</a>.<br>
<br>
<span class="Special">{endmarker}</span> must NOT be preceded by any white space. If <span class="Special">{endmarker}</span> is<br>
omitted from after the "<<", a dot '.' must be used after <span class="Special">{script}</span>, like for<br>
the <a class="Identifier" href="insert.html#:append">:append</a> and <a class="Identifier" href="insert.html#:insert">:insert</a> commands.<br>
This form of the <a class="Identifier" href="if_tcl.html#:tcl">:tcl</a> command is mainly useful for including tcl code in Vim<br>
scripts.<br>
<br>
Example:<br>
<div class="helpExample"> function! DefineDate()<br>
tcl << EOF<br>
proc date {} {<br>
return [clock format [clock seconds]]<br>
}<br>
EOF<br>
endfunction</div>
<br>
To see what version of Tcl you have:<br>
<div class="helpExample"> :tcl puts [info patchlevel]</div>
<br>
<br>
<a class="Constant" href="if_tcl.html#:tcldo" name=":tcldo">:tcldo</a> <a class="Constant" href="if_tcl.html#:tcld" name=":tcld">:tcld</a><br>
:<span class="Special">[range]</span>tcld[o] <span class="Special">{cmd}</span> Execute Tcl command <span class="Special">{cmd}</span> for each line in <span class="Special">[range]</span><br>
with the variable "line" being set to the text of each<br>
line in turn, and "lnum" to the line number. Setting<br>
"line" will change the text, but <span class="Todo">note</span> that it is not<br>
possible to add or delete lines using this command.<br>
If <span class="Special">{cmd}</span> returns an error, the command is interrupted.<br>
The default for <span class="Special">[range]</span> is the whole file: "1,$".<br>
See <a class="Identifier" href="if_tcl.html#tcl-var-line">tcl-var-line</a> and <a class="Identifier" href="if_tcl.html#tcl-var-lnum">tcl-var-lnum</a>. <span class="Special">{not in Vi}</span><br>
<br>
<a class="Constant" href="if_tcl.html#:tclfile" name=":tclfile">:tclfile</a> <a class="Constant" href="if_tcl.html#:tclf" name=":tclf">:tclf</a><br>
:tclf[ile] <span class="Special">{file}</span> Execute the Tcl script in <span class="Special">{file}</span>. This is the same as<br>
":tcl source <span class="Special">{file}</span>", but allows file name completion.<br>
<span class="Special">{not in Vi}</span><br>
<br>
<br>
<span class="Todo">Note</span> that Tcl objects (like variables) persist from one command to the next,<br>
just as in the Tcl shell.<br>
<br>
Executing Tcl commands is not possible in the <a class="Identifier" href="eval.html#sandbox">sandbox</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. Tcl commands <a class="Constant" href="if_tcl.html#tcl-commands" name="tcl-commands">tcl-commands</a><br>
<br>
Tcl code gets all of its access to vim via commands in the "::vim" namespace.<br>
The following commands are implemented:<br>
<br>
<div class="helpExample"> ::vim::beep # Guess.<br>
::vim::buffer {n} # Create Tcl command for one buffer.<br>
::vim::buffer list # Create Tcl commands for all buffers.<br>
::vim::command [-quiet] {cmd} # Execute an Ex command.<br>
::vim::expr {expr} # Use Vim's expression evaluator.<br>
::vim::option {opt} # Get vim option.<br>
::vim::option {opt} {val} # Set vim option.<br>
::vim::window list # Create Tcl commands for all windows.</div>
<br>
Commands:<br>
::vim::beep <a class="Constant" href="if_tcl.html#tcl-beep" name="tcl-beep">tcl-beep</a><br>
Honk. Does not return a result.<br>
<br>
::vim::buffer <span class="Special">{n}</span> <a class="Constant" href="if_tcl.html#tcl-buffer" name="tcl-buffer">tcl-buffer</a><br>
::vim::buffer exists <span class="Special">{n}</span><br>
::vim::buffer list<br>
Provides access to vim buffers. With an integer argument, creates a<br>
buffer command (see <a class="Identifier" href="if_tcl.html#tcl-buffer-cmds">tcl-buffer-cmds</a>) for the buffer with that<br>
number, and returns its name as the result. Invalid buffer numbers<br>
result in a standard Tcl error. To test for valid buffer numbers,<br>
vim's internal functions can be used:<br>
<div class="helpExample"> set nbufs [::vim::expr bufnr("$")]<br>
set isvalid [::vim::expr "bufexists($n)"]</div>
The "list" option creates a buffer command for each valid buffer, and<br>
returns a list of the command names as the result.<br>
Example:<br>
<div class="helpExample"> set bufs [::vim::buffer list]<br>
foreach b $bufs { $b append end "The End!" }</div>
The "exists" option checks if a buffer with the given number exists.<br>
Example:<br>
<div class="helpExample"> if { [::vim::buffer exists $n] } { ::vim::command ":e #$n" }</div>
This command might be replaced by a variable in future versions.<br>
See also <a class="Identifier" href="if_tcl.html#tcl-var-current">tcl-var-current</a> for the current buffer.<br>
<br>
::vim::command <span class="Special">{cmd}</span> <a class="Constant" href="if_tcl.html#tcl-command" name="tcl-command">tcl-command</a><br>
::vim::command -quiet <span class="Special">{cmd}</span><br>
Execute the vim (ex-mode) command <span class="Special">{cmd}</span>. Any Ex command that affects<br>
a buffer or window uses the current buffer/current window. Does not<br>
return a result other than a standard Tcl error code. After this<br>
command is completed, the "::vim::current" variable is updated.<br>
The "-quiet" flag suppresses any error messages from vim.<br>
Examples:<br>
<div class="helpExample"> ::vim::command "set ts=8"<br>
::vim::command "%s/foo/bar/g"</div>
To execute normal-mode commands, use "normal" (see <a class="Identifier" href="various.html#:normal">:normal</a>):<br>
<div class="helpExample"> set cmd "jj"<br>
::vim::command "normal $cmd"</div>
See also <a class="Identifier" href="if_tcl.html#tcl-window-command">tcl-window-command</a> and <a class="Identifier" href="if_tcl.html#tcl-buffer-command">tcl-buffer-command</a>.<br>
<br>
::vim::expr <span class="Special">{expr}</span> <a class="Constant" href="if_tcl.html#tcl-expr" name="tcl-expr">tcl-expr</a><br>
Evaluates the expression <span class="Special">{expr}</span> using vim's internal expression<br>
evaluator (see <a class="Identifier" href="eval.html#expression">expression</a>). Any expression that queries a buffer<br>
or window property uses the current buffer/current window. Returns<br>
the result as a string. A <a class="Identifier" href="eval.html#List">List</a> is turned into a string by joining<br>
the items and inserting line breaks.<br>
Examples:<br>
<div class="helpExample"> set perl_available [::vim::expr has("perl")]</div>
See also <a class="Identifier" href="if_tcl.html#tcl-window-expr">tcl-window-expr</a> and <a class="Identifier" href="if_tcl.html#tcl-buffer-expr">tcl-buffer-expr</a>.<br>
<br>
::vim::option <span class="Special">{opt}</span> <a class="Constant" href="if_tcl.html#tcl-option" name="tcl-option">tcl-option</a><br>
::vim::option <span class="Special">{opt}</span> <span class="Special">{value}</span><br>
Without second argument, queries the value of a vim option. With this<br>
argument, sets the vim option to <span class="Special">{value}</span>, and returns the previous<br>
value as the result. Any options that are marked as 'local to buffer'<br>
or 'local to window' affect the current buffer/current window. The<br>
global value is not changed, use the ":set" command for that. For<br>
boolean options, <span class="Special">{value}</span> should be "0" or "1", or any of the keywords<br>
"on", "off" or "toggle". See <a class="Identifier" href="options.html#option-summary">option-summary</a> for a list of options.<br>
Example:<br>
<div class="helpExample"> ::vim::option ts 8</div>
See also <a class="Identifier" href="if_tcl.html#tcl-window-option">tcl-window-option</a> and <a class="Identifier" href="if_tcl.html#tcl-buffer-option">tcl-buffer-option</a>.<br>
<br>
::vim::window <span class="Special">{option}</span> <a class="Constant" href="if_tcl.html#tcl-window" name="tcl-window">tcl-window</a><br>
Provides access to vim windows. Currently only the "list" option is<br>
implemented. This creates a window command (see <a class="Identifier" href="if_tcl.html#tcl-window-cmds">tcl-window-cmds</a>) for<br>
each window, and returns a list of the command names as the result.<br>
Example:<br>
<div class="helpExample"> set wins [::vim::window list]<br>
foreach w $wins { $w height 4 }</div>
This command might be replaced by a variable in future versions.<br>
See also <a class="Identifier" href="if_tcl.html#tcl-var-current">tcl-var-current</a> for the current window.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. Tcl variables <a class="Constant" href="if_tcl.html#tcl-variables" name="tcl-variables">tcl-variables</a><br>
<br>
The ::vim namespace contains a few variables. These are created when the Tcl<br>
interpreter is called from vim and set to current values.<br>
<br>
<div class="helpExample"> ::vim::current # array containing "current" objects<br>
::vim::lbase # number of first line<br>
::vim::range # array containing current range numbers<br>
line # current line as a string (:tcldo only)<br>
lnum # current line number (:tcldo only)</div>
<br>
Variables:<br>
::vim::current <a class="Constant" href="if_tcl.html#tcl-var-current" name="tcl-var-current">tcl-var-current</a><br>
This is an array providing access to various "current" objects<br>
available in vim. The contents of this array are updated after<br>
"::vim::command" is called, as this might change vim's current<br>
settings (e.g., by deleting the current buffer).<br>
The "buffer" element contains the name of the buffer command for the<br>
current buffer. This can be used directly to invoke buffer commands<br>
(see <a class="Identifier" href="if_tcl.html#tcl-buffer-cmds">tcl-buffer-cmds</a>). This element is read-only.<br>
Example:<br>
<div class="helpExample"> $::vim::current(buffer) insert begin "Hello world"</div>
The "window" element contains the name of the window command for the<br>
current window. This can be used directly to invoke window commands<br>
(see <a class="Identifier" href="if_tcl.html#tcl-window-cmds">tcl-window-cmds</a>). This element is read-only.<br>
Example:<br>
<div class="helpExample"> $::vim::current(window) height 10</div>
<br>
::vim::lbase <a class="Constant" href="if_tcl.html#tcl-var-lbase" name="tcl-var-lbase">tcl-var-lbase</a><br>
This variable controls how Tcl treats line numbers. If it is set to<br>
'1', then lines and columns start at 1. This way, line numbers from<br>
Tcl commands and vim expressions are compatible. If this variable is<br>
set to '0', then line numbers and columns start at 0 in Tcl. This is<br>
useful if you want to treat a buffer as a Tcl list or a line as a Tcl<br>
string and use standard Tcl commands that return an index ("lsort" or<br>
"string first", for example). The default value is '1'. Currently,<br>
any non-zero values is treated as '1', but your scripts should not<br>
rely on this. See also <a class="Identifier" href="if_tcl.html#tcl-linenumbers">tcl-linenumbers</a>.<br>
<br>
::vim::range <a class="Constant" href="if_tcl.html#tcl-var-range" name="tcl-var-range">tcl-var-range</a><br>
This is an array with three elements, "start", "begin" and "end". It<br>
contains the line numbers of the start and end row of the current<br>
range. "begin" is the same as "start". This variable is read-only.<br>
See <a class="Identifier" href="if_tcl.html#tcl-examples">tcl-examples</a>.<br>
<br>
line <a class="Constant" href="if_tcl.html#tcl-var-line" name="tcl-var-line">tcl-var-line</a><br>
lnum <a class="Constant" href="if_tcl.html#tcl-var-lnum" name="tcl-var-lnum">tcl-var-lnum</a><br>
These global variables are only available if the ":tcldo" Ex command<br>
is being executed. They contain the text and line number of the<br>
current line. When the Tcl command invoked by ":tcldo" is completed,<br>
the current line is set to the contents of the "line" variable, unless<br>
the variable was unset by the Tcl command. The "lnum" variable is<br>
read-only. These variables are not in the "::vim" namespace so they<br>
can be used in ":tcldo" without much typing (this might be changed in<br>
future versions). See also <a class="Identifier" href="if_tcl.html#tcl-linenumbers">tcl-linenumbers</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
4. Tcl window commands <a class="Constant" href="if_tcl.html#tcl-window-cmds" name="tcl-window-cmds">tcl-window-cmds</a><br>
<br>
Window commands represent vim windows. They are created by several commands:<br>
::vim::window list <a class="Identifier" href="if_tcl.html#tcl-window">tcl-window</a><br>
"windows" option of a buffer command <a class="Identifier" href="if_tcl.html#tcl-buffer-windows">tcl-buffer-windows</a><br>
The ::vim::current(window) variable contains the name of the window command<br>
for the current window. A window command is automatically deleted when the<br>
corresponding vim window is closed.<br>
<br>
Let's assume the name of the window command is stored in the Tcl variable "win",<br>
i.e. "$win" calls the command. The following options are available:<br>
<br>
<div class="helpExample"> $win buffer # Create Tcl command for window's buffer.<br>
$win command {cmd} # Execute Ex command in windows context.<br>
$win cursor # Get current cursor position.<br>
$win cursor {var} # Set cursor position from array variable.<br>
$win cursor {row} {col} # Set cursor position.<br>
$win delcmd {cmd} # Call Tcl command when window is closed.<br>
$win expr {expr} # Evaluate vim expression in windows context.<br>
$win height # Report the window's height.<br>
$win height {n} # Set the window's height.<br>
$win option {opt} [val] # Get/Set vim option in windows context.</div>
<br>
Options:<br>
$win buffer <a class="Constant" href="if_tcl.html#tcl-window-buffer" name="tcl-window-buffer">tcl-window-buffer</a><br>
Creates a Tcl command for the window's buffer, and returns its name as<br>
the result. The name should be stored in a variable:<br>
<div class="helpExample"> set buf [$win buffer]</div>
$buf is now a valid Tcl command. See <a class="Identifier" href="if_tcl.html#tcl-buffer-cmds">tcl-buffer-cmds</a> for the<br>
available options.<br>
<br>
$win cursor <a class="Constant" href="if_tcl.html#tcl-window-cursor" name="tcl-window-cursor">tcl-window-cursor</a><br>
$win cursor <span class="Special">{var}</span><br>
$win cursor <span class="Special">{row}</span> <span class="Special">{col}</span><br>
Without argument, reports the current cursor position as a string.<br>
This can be converted to a Tcl array variable:<br>
<div class="helpExample"> array set here [$win cursor]</div>
"here(row)" and "here(column)" now contain the cursor position.<br>
With a single argument, the argument is interpreted as the name of a<br>
Tcl array variable, which must contain two elements "row" and "column".<br>
These are used to set the cursor to the new position:<br>
<div class="helpExample"> $win cursor here ;# not $here !</div>
With two arguments, sets the cursor to the specified row and column:<br>
<div class="helpExample"> $win cursor $here(row) $here(column)</div>
Invalid positions result in a standard Tcl error, which can be caught<br>
with "catch". The row and column values depend on the "::vim::lbase"<br>
variable. See <a class="Identifier" href="if_tcl.html#tcl-var-lbase">tcl-var-lbase</a>.<br>
<br>
$win delcmd <span class="Special">{cmd}</span> <a class="Constant" href="if_tcl.html#tcl-window-delcmd" name="tcl-window-delcmd">tcl-window-delcmd</a><br>
Registers the Tcl command <span class="Special">{cmd}</span> as a deletion callback for the window.<br>
This command is executed (in the global scope) just before the window<br>
is closed. Complex commands should be build with "list":<br>
<div class="helpExample"> $win delcmd [list puts vimerr "window deleted"]</div>
See also <a class="Identifier" href="if_tcl.html#tcl-buffer-delcmd">tcl-buffer-delcmd</a>.<br>
<br>
$win height <a class="Constant" href="if_tcl.html#tcl-window-height" name="tcl-window-height">tcl-window-height</a><br>
$win height <span class="Special">{n}</span><br>
Without argument, reports the window's current height. With an<br>
argument, tries to set the window's height to <span class="Special">{n}</span>, then reports the<br>
new height (which might be different from <span class="Special">{n}</span>).<br>
<br>
$win command <span class="Special">[-quiet]</span> <span class="Special">{cmd}</span> <a class="Constant" href="if_tcl.html#tcl-window-command" name="tcl-window-command">tcl-window-command</a><br>
$win expr <span class="Special">{expr}</span> <a class="Constant" href="if_tcl.html#tcl-window-expr" name="tcl-window-expr">tcl-window-expr</a><br>
$win option <span class="Special">{opt}</span> <span class="Special">[val]</span> <a class="Constant" href="if_tcl.html#tcl-window-option" name="tcl-window-option">tcl-window-option</a><br>
These are similar to "::vim::command" etc., except that everything is<br>
done in the context of the window represented by $win, instead of the<br>
current window. For example, setting an option that is marked 'local<br>
to window' affects the window $win. Anything that affects or queries<br>
a buffer uses the buffer displayed in this window (i.e. the buffer<br>
that is represented by "$win buffer"). See <a class="Identifier" href="if_tcl.html#tcl-command">tcl-command</a>, <a class="Identifier" href="if_tcl.html#tcl-expr">tcl-expr</a><br>
and <a class="Identifier" href="if_tcl.html#tcl-option">tcl-option</a> for more information.<br>
Example:<br>
<div class="helpExample"> $win option number on</div>
<br>
<span class="PreProc">==============================================================================</span><br>
5. Tcl buffer commands <a class="Constant" href="if_tcl.html#tcl-buffer-cmds" name="tcl-buffer-cmds">tcl-buffer-cmds</a><br>
<br>
Buffer commands represent vim buffers. They are created by several commands:<br>
::vim::buffer <span class="Special">{N}</span> <a class="Identifier" href="if_tcl.html#tcl-buffer">tcl-buffer</a><br>
::vim::buffer list <a class="Identifier" href="if_tcl.html#tcl-buffer">tcl-buffer</a><br>
"buffer" option of a window command <a class="Identifier" href="if_tcl.html#tcl-window-buffer">tcl-window-buffer</a><br>
The ::vim::current(buffer) variable contains the name of the buffer command<br>
for the current buffer. A buffer command is automatically deleted when the<br>
corresponding vim buffer is destroyed. Whenever the buffer's contents are<br>
changed, all marks in the buffer are automatically adjusted. Any changes to<br>
the buffer's contents made by Tcl commands can be undone with the "undo" vim<br>
command (see <a class="Identifier" href="undo.html#undo">undo</a>).<br>
<br>
Let's assume the name of the buffer command is stored in the Tcl variable "buf",<br>
i.e. "$buf" calls the command. The following options are available:<br>
<br>
<div class="helpExample"> $buf append {n} {str} # Append a line to buffer, after line {n}.<br>
$buf command {cmd} # Execute Ex command in buffers context.<br>
$buf count # Report number of lines in buffer.<br>
$buf delcmd {cmd} # Call Tcl command when buffer is deleted.<br>
$buf delete {n} # Delete a single line.<br>
$buf delete {n} {m} # Delete several lines.<br>
$buf expr {expr} # Evaluate vim expression in buffers context.<br>
$buf get {n} # Get a single line as a string.<br>
$buf get {n} {m} # Get several lines as a list.<br>
$buf insert {n} {str} # Insert a line in buffer, as line {n}.<br>
$buf last # Report line number of last line in buffer.<br>
$buf mark {mark} # Report position of buffer mark.<br>
$buf name # Report name of file in buffer.<br>
$buf number # Report number of this buffer.<br>
$buf option {opt} [val] # Get/Set vim option in buffers context.<br>
$buf set {n} {text} # Replace a single line.<br>
$buf set {n} {m} {list} # Replace several lines.<br>
$buf windows # Create Tcl commands for buffer's windows.</div>
<br>
<a class="Constant" href="if_tcl.html#tcl-linenumbers" name="tcl-linenumbers">tcl-linenumbers</a><br>
Most buffer commands take line numbers as arguments. How Tcl treats these<br>
numbers depends on the "::vim::lbase" variable (see <a class="Identifier" href="if_tcl.html#tcl-var-lbase">tcl-var-lbase</a>). Instead<br>
of line numbers, several keywords can be also used: "top", "start", "begin",<br>
"first", "bottom", "end" and "last".<br>
<br>
Options:<br>
$buf append <span class="Special">{n}</span> <span class="Special">{str}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-append" name="tcl-buffer-append">tcl-buffer-append</a><br>
$buf insert <span class="Special">{n}</span> <span class="Special">{str}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-insert" name="tcl-buffer-insert">tcl-buffer-insert</a><br>
Add a line to the buffer. With the "insert" option, the string<br>
becomes the new line <span class="Special">{n}</span>, with "append" it is inserted after line <span class="Special">{n}</span>.<br>
Example:<br>
<div class="helpExample"> $buf insert top "This is the beginning."<br>
$buf append end "This is the end."</div>
To add a list of lines to the buffer, use a loop:<br>
<div class="helpExample"> foreach line $list { $buf append $num $line ; incr num }</div>
<br>
$buf count <a class="Constant" href="if_tcl.html#tcl-buffer-count" name="tcl-buffer-count">tcl-buffer-count</a><br>
Reports the total number of lines in the buffer.<br>
<br>
$buf delcmd <span class="Special">{cmd}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-delcmd" name="tcl-buffer-delcmd">tcl-buffer-delcmd</a><br>
Registers the Tcl command <span class="Special">{cmd}</span> as a deletion callback for the buffer.<br>
This command is executed (in the global scope) just before the buffer<br>
is deleted. Complex commands should be build with "list":<br>
<div class="helpExample"> $buf delcmd [list puts vimerr "buffer [$buf number] gone"]</div>
See also <a class="Identifier" href="if_tcl.html#tcl-window-delcmd">tcl-window-delcmd</a>.<br>
<br>
$buf delete <span class="Special">{n}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-delete" name="tcl-buffer-delete">tcl-buffer-delete</a><br>
$buf delete <span class="Special">{n}</span> <span class="Special">{m}</span><br>
Deletes line <span class="Special">{n}</span> or lines <span class="Special">{n}</span> through <span class="Special">{m}</span> from the buffer.<br>
This example deletes everything except the last line:<br>
<div class="helpExample"> $buf delete first [expr [$buf last] - 1]</div>
<br>
$buf get <span class="Special">{n}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-get" name="tcl-buffer-get">tcl-buffer-get</a><br>
$buf get <span class="Special">{n}</span> <span class="Special">{m}</span><br>
Gets one or more lines from the buffer. For a single line, the result<br>
is a string; for several lines, a list of strings.<br>
Example:<br>
<div class="helpExample"> set topline [$buf get top]</div>
<br>
$buf last <a class="Constant" href="if_tcl.html#tcl-buffer-last" name="tcl-buffer-last">tcl-buffer-last</a><br>
Reports the line number of the last line. This value depends on the<br>
"::vim::lbase" variable. See <a class="Identifier" href="if_tcl.html#tcl-var-lbase">tcl-var-lbase</a>.<br>
<br>
$buf mark <span class="Special">{mark}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-mark" name="tcl-buffer-mark">tcl-buffer-mark</a><br>
Reports the position of the named mark as a string, similar to the<br>
cursor position of the "cursor" option of a window command (see<br>
<a class="Identifier" href="if_tcl.html#tcl-window-cursor">tcl-window-cursor</a>). This can be converted to a Tcl array variable:<br>
<div class="helpExample"> array set mpos [$buf mark "a"]</div>
"mpos(column)" and "mpos(row)" now contain the position of the mark.<br>
If the mark is not set, a standard Tcl error results.<br>
<br>
$buf name<br>
Reports the name of the file in the buffer. For a buffer without a<br>
file, this is an empty string.<br>
<br>
$buf number<br>
Reports the number of this buffer. See <a class="Identifier" href="windows.html#:buffers">:buffers</a>.<br>
This example deletes a buffer from vim:<br>
<div class="helpExample"> ::vim::command "bdelete [$buf number]"</div>
<br>
$buf set <span class="Special">{n}</span> <span class="Special">{string}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-set" name="tcl-buffer-set">tcl-buffer-set</a><br>
$buf set <span class="Special">{n}</span> <span class="Special">{m}</span> <span class="Special">{list}</span><br>
Replace one or several lines in the buffer. If the list contains more<br>
elements than there are lines to replace, they are inserted into the<br>
buffer. If the list contains fewer elements, any unreplaced line is<br>
deleted from the buffer.<br>
<br>
$buf windows <a class="Constant" href="if_tcl.html#tcl-buffer-windows" name="tcl-buffer-windows">tcl-buffer-windows</a><br>
Creates a window command for each window that displays this buffer, and<br>
returns a list of the command names as the result.<br>
Example:<br>
<div class="helpExample"> set winlist [$buf windows]<br>
foreach win $winlist { $win height 4 }</div>
See <a class="Identifier" href="if_tcl.html#tcl-window-cmds">tcl-window-cmds</a> for the available options.<br>
<br>
$buf command <span class="Special">[-quiet]</span> <span class="Special">{cmd}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-command" name="tcl-buffer-command">tcl-buffer-command</a><br>
$buf expr <span class="Special">{expr}</span> <a class="Constant" href="if_tcl.html#tcl-buffer-expr" name="tcl-buffer-expr">tcl-buffer-expr</a><br>
$buf option <span class="Special">{opt}</span> <span class="Special">[val]</span> <a class="Constant" href="if_tcl.html#tcl-buffer-option" name="tcl-buffer-option">tcl-buffer-option</a><br>
These are similar to "::vim::command" etc., except that everything is<br>
done in the context of the buffer represented by $buf, instead of the<br>
current buffer. For example, setting an option that is marked 'local<br>
to buffer' affects the buffer $buf. Anything that affects or queries<br>
a window uses the first window in vim's window list that displays this<br>
buffer (i.e. the first entry in the list returned by "$buf windows").<br>
See <a class="Identifier" href="if_tcl.html#tcl-command">tcl-command</a>, <a class="Identifier" href="if_tcl.html#tcl-expr">tcl-expr</a> and <a class="Identifier" href="if_tcl.html#tcl-option">tcl-option</a> for more information.<br>
Example:<br>
<div class="helpExample"> if { [$buf option modified] } { $buf command "w" }</div>
<br>
<span class="PreProc">==============================================================================</span><br>
6. Miscellaneous; Output from Tcl <a class="Constant" href="if_tcl.html#tcl-misc" name="tcl-misc">tcl-misc</a> <a class="Constant" href="if_tcl.html#tcl-output" name="tcl-output">tcl-output</a><br>
<br>
The standard Tcl commands "exit" and "catch" are replaced by custom versions.<br>
"exit" terminates the current Tcl script and returns to vim, which deletes the<br>
Tcl interpreter. Another call to ":tcl" then creates a new Tcl interpreter.<br>
"exit" does NOT terminate vim! "catch" works as before, except that it does<br>
not prevent script termination from "exit". An exit code != 0 causes the ex<br>
command that invoked the Tcl script to return an error.<br>
<br>
Two new I/O streams are available in Tcl, "vimout" and "vimerr". All output<br>
directed to them is displayed in the vim message area, as information messages<br>
and error messages, respectively. The standard Tcl output streams stdout and<br>
stderr are mapped to vimout and vimerr, so that a normal "puts" command can be<br>
used to display messages in vim.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
7. Known bugs & problems <a class="Constant" href="if_tcl.html#tcl-bugs" name="tcl-bugs">tcl-bugs</a><br>
<br>
Calling one of the Tcl Ex commands from inside Tcl (via "::vim::command") may<br>
have unexpected side effects. The command creates a new interpreter, which<br>
has the same abilities as the standard interpreter - making "::vim::command"<br>
available in a safe child interpreter therefore makes the child unsafe. (It<br>
would be trivial to block nested :tcl* calls or ensure that such calls from a<br>
safe interpreter create only new safe interpreters, but quite pointless -<br>
depending on vim's configuration, "::vim::command" may execute arbitrary code<br>
in any number of other scripting languages.) A call to "exit" within this new<br>
interpreter does not affect the old interpreter; it only terminates the new<br>
interpreter, then script processing continues normally in the old interpreter.<br>
<br>
Input from stdin is currently not supported.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
8. Examples: <a class="Constant" href="if_tcl.html#tcl-examples" name="tcl-examples">tcl-examples</a><br>
<br>
Here are a few small (and maybe useful) Tcl scripts.<br>
<br>
This script sorts the lines of the entire buffer (assume it contains a list<br>
of names or something similar):<br>
set buf $::vim::current(buffer)<br>
set lines [$buf get top bottom]<br>
set lines [lsort -dictionary $lines]<br>
$buf set top bottom $lines<br>
<br>
This script reverses the lines in the buffer. <span class="Todo">Note</span> the use of "::vim::lbase"<br>
and "$buf last" to work with any line number setting.<br>
set buf $::vim::current(buffer)<br>
set t $::vim::lbase<br>
set b [$buf last]<br>
while { $t < $b } {<br>
set tl [$buf get $t]<br>
set bl [$buf get $b]<br>
$buf set $t $bl<br>
$buf set $b $tl<br>
incr t<br>
incr b -1<br>
}<br>
<br>
This script adds a consecutive number to each line in the current range:<br>
set buf $::vim::current(buffer)<br>
set i $::vim::range(start)<br>
set n 1<br>
while { $i <= $::vim::range(end) } {<br>
set line [$buf get $i]<br>
$buf set $i "$n\t$line"<br>
incr i ; incr n<br>
}<br>
<br>
The same can also be done quickly with two Ex commands, using ":tcldo":<br>
:tcl set n 1<br>
:<span class="Special">[range]</span>tcldo set line "$n\t$line" ; incr n<br>
<br>
This procedure runs an Ex command on each buffer (idea stolen from Ron Aaron):<br>
proc eachbuf { cmd } {<br>
foreach b [::vim::buffer list] {<br>
$b command $cmd<br>
}<br>
}<br>
Use it like this:<br>
:tcl eachbuf %s/foo/bar/g<br>
Be careful with Tcl's string and backslash substitution, tough. If in doubt,<br>
surround the Ex command with curly braces.<br>
<br>
<br>
If you want to add some Tcl procedures permanently to vim, just place them in<br>
a file (e.g. "~/.vimrc.tcl" on Unix machines), and add these lines to your<br>
startup file (usually "~/.vimrc" on Unix):<br>
if has("tcl")<br>
tclfile ~/.vimrc.tcl<br>
endif<br>
<br>
<span class="PreProc">==============================================================================</span><br>
9. Dynamic loading <a class="Constant" href="if_tcl.html#tcl-dynamic" name="tcl-dynamic">tcl-dynamic</a><br>
<br>
On MS-Windows and Unix the Tcl library can be loaded dynamically. The<br>
<a class="Identifier" href="various.html#:version">:version</a> output then includes <a class="Identifier" href="various.html#+tcl/dyn">+tcl/dyn</a>.<br>
<br>
This means that Vim will search for the Tcl DLL or shared library file only<br>
when needed. When you don't use the Tcl interface you don't need it, thus you<br>
can use Vim without this file.<br>
<br>
<br>
<span class="PreProc">MS-Windows</span><br>
<br>
To use the Tcl interface the Tcl DLL must be in your search path. In a<br>
console window type "path" to see what directories are used. The <a class="Type" href="options.html#'tcldll'">'tcldll'</a><br>
option can be also used to specify the Tcl DLL.<br>
<br>
The name of the DLL must match the Tcl version Vim was compiled with.<br>
Currently the name is "tcl86.dll". That is for Tcl 8.6. To know for sure<br>
edit "gvim.exe" and search for "tcl\d*.dll\c".<br>
<br>
<br>
<span class="PreProc">Unix</span><br>
<br>
The <a class="Type" href="options.html#'tcldll'">'tcldll'</a> option can be used to specify the Tcl shared library file instead<br>
of DYNAMIC_TCL_DLL file what was specified at compile time. The version of<br>
the shared library must match the Tcl version Vim was compiled with.<br>
<br>
<span class="PreProc">==============================================================================</span><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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。