<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dutor &#187; Vim</title>
	<atom:link href="http://www.dutor.net/index.php/category/toolkits/vim-toolkits/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dutor.net</link>
	<description>熟读而精思，循序而渐进，厚积而薄发。</description>
	<lastBuildDate>Tue, 17 Jan 2012 14:44:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>提升效率的若干Vim技巧</title>
		<link>http://www.dutor.net/index.php/2011/09/efficient-vim-tips/</link>
		<comments>http://www.dutor.net/index.php/2011/09/efficient-vim-tips/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 05:23:58 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2633</guid>
		<description><![CDATA[<ul>
	<li><strong>G, gg</strong>: 光标移动至文件首/尾；</li>

	<li><strong>zz, zt, zb</strong>: 将光标所在行居中/置顶/置尾；</li>

	<li><strong>H, M, L</strong>: 定位光标到当前窗口的首/中/尾；</li>

	<li><strong>*, #, n, N</strong>: 向前/后定位当前光标所在word，n/N沿相应/相反方向重复定位；</li>

	<li><strong>^a, ^x</strong>: 若当前光标所在word是数字，可递增/递减该数字，同时支持decimal和hexadecimal；</li>

	<li><strong>^, g_</strong>: 即Shift+6，定位光标到当前行首/尾的第一个非空白字符；</li>

	<li><strong>^d, ^t</strong>: insert模式下，缩进/反缩进当前行；</li>

	<li><strong>^w</strong>: insert模式下，向后删除一个word；</li>

	<li><strong>^y</strong>: insert模式下，复制上一行同列字符；</li>

	<li><strong>^x^f</strong>: insert模式下，补全路径名；</li>

	<li><strong><span style="color: #0000FF;">^x^n</span></strong>: insert模式下，补全tag（需要tags文件的支持）；</li>
	<li><strong><span style="color: #0000FF;">^x^l</span></strong>: insert模式下，补全行（根据已有行）；</li>
	<li><strong>I, A</strong>: 定位光标至当前行首/尾，并进入insert模式，I会忽略行首空白；</li>

	<li><strong>D, C</strong>: 删除光标所在位置到行尾的字符，C会进入insert模式；</li>

	<li><strong>cib</strong>: 或者ci(或者ci)，删除当前括号内的所有字符并进入insert模式。c还可以是d或者其他编辑字符，i还可以是a（此时会将括号一同删除），b还可以是B(大括号)、t(html标签)或者具体的配对符号，如(), [], {}, '', "", &#60;>。
<span style="color: #FF0000;">参加:h text-objects；</span></li>

	<li><strong>%</strong>: normal模式下%会跳转至配对括号；</li>

	<li><strong>%</strong>: lastline模式下代表当前buffer的文件名，可以有许多修饰字符，例如:sp %:r.cpp会分割当前窗口，并打开当前文件对应的cpp文件，%:r代表文件名消除最后一个后缀之后的字符串。
<span style="color: #FF0000;">参见:h filename-modifiers；</span></li>

	<li><strong>:set op?</strong> : 显示选项op的当前值；</li>

	<li><strong>:set op!</strong> : 反转开关式选项op，比如:set nu!开关行号显示，:set paste!开关paste模式</li>

</ul>

注：
1. 非特别说明，命令均在normal模式；
2. 字符前的^指Ctrl；
3. 技巧来自于实践，技艺提升于运用。]]></description>
			<content:encoded><![CDATA[<p>　　前段时间一篇关于<a href="http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/" target="_blank">Vim练级的文章</a>大火，酷壳也有<a href="http://coolshell.cn/articles/5426.html" target="_blank">翻译</a>，还贴出一张<a href="http://coolshell.cn/articles/5479.html" target="_blank">Cheat Sheet</a>。<br />
　　Vim能力强大，功能繁多，快捷键更是数不胜数，以至于苦逼的程序员们根本无法完全掌握。事实上，每个使用Vim的程序员，包括高级用户，只是在使用Vim所提供功能的一个很小的子集，而且也只需要使用一个很小的子集。在学会基本的编辑技巧的基础上，根据自己的需要，掌握一些“高级”技巧，可以极大的提高编辑效率。这里约略地列出我平时习惯使用的有限的一些技巧，希望你能够发现自己不知道却对你也适用的某一个。</p>
<ul>
<li><strong>G, gg</strong>: 光标移动至文件首/尾；</li>
<li><strong>zz, zt, zb</strong>: 将光标所在行居中/置顶/置尾；</li>
<li><strong>H, M, L</strong>: 定位光标到当前窗口的首/中/尾；</li>
<li><strong>*, #, n, N</strong>: 向前/后定位当前光标所在word，n/N沿相应/相反方向重复定位；</li>
<li><strong>^a, ^x</strong>: 若当前光标所在word是数字，可递增/递减该数字，同时支持decimal和hexadecimal；</li>
<li><strong>^, g_</strong>: 即Shift+6，定位光标到当前行首/尾的第一个非空白字符；</li>
<li><strong>^d, ^t</strong>: insert模式下，缩进/反缩进当前行；</li>
<li><strong>^w</strong>: insert模式下，向后删除一个word；</li>
<li><strong>^y</strong>: insert模式下，复制上一行同列字符；</li>
<li><strong>^x^f</strong>: insert模式下，补全路径名；</li>
<li><strong><span style="color: #0000FF;">^x^n</span></strong>: insert模式下，补全tag（需要tags文件的支持）；</li>
<li><strong><span style="color: #0000FF;">^x^l</span></strong>: insert模式下，补全行（根据已有行）；</li>
<li><strong>I, A</strong>: 定位光标至当前行首/尾，并进入insert模式，I会忽略行首空白；</li>
<li><strong>D, C</strong>: 删除光标所在位置到行尾的字符，C会进入insert模式；</li>
<li><strong>cib</strong>: 或者ci(或者ci)，删除当前括号内的所有字符并进入insert模式。c还可以是d或者其他编辑字符，i还可以是a（此时会将括号一同删除），b还可以是B(大括号)、t(html标签)或者具体的配对符号，如(), [], {}, &#8221;, &#8220;&#8221;, &lt;>。<br />
<span style="color: #FF0000;">参见:h text-objects；</span></li>
<li><strong>%</strong>: normal模式下%会跳转至配对括号；</li>
<li><strong>%</strong>: lastline模式下代表当前buffer的文件名，可以有许多修饰字符，例如:sp %:r.cpp会分割当前窗口，并打开当前文件对应的cpp文件，%:r代表文件名消除最后一个后缀之后的字符串。<br />
<span style="color: #FF0000;">参见:h filename-modifiers；</span></li>
<li><strong>:set op?</strong> : 显示选项op的当前值；</li>
<li><strong>:set op!</strong> : 反转开关式选项op，比如:set nu!开关行号显示，:set paste!开关paste模式</li>
<li><strong>K</strong>: 即Shift+k，根据光标所在word查阅man手册，非常实用的功能，当然前提是系统手册中已经有相应的条目了。通常需要安装manpages-dev, manpages-posix和manpages-posix-dev。</li>
<li><strong>:g/pattern/cmd</strong> : 这个命令很实用，但我用的并不太多，因为很多情况下它的功能可以有s命令完成。它对匹配pattern的所有行执行cmd命令，比如:g/^#/d删除所有以#开始的行。</li>
</ul>
<p>注：<br />
1. 非特别说明，命令均在normal模式；<br />
2. 字符前的^指Ctrl；<br />
3. 技巧来自于实践，技艺提升于运用。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/09/efficient-vim-tips/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>要冷静，注意素质</title>
		<link>http://www.dutor.net/index.php/2011/07/kubi/</link>
		<comments>http://www.dutor.net/index.php/2011/07/kubi/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 13:17:23 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2614</guid>
		<description><![CDATA[　　闲着也是闲着啊，来公司学习啊，好久没写博客了呀，欲望很强烈啊，那就写吧！我用Vim写啊，我骄傲啊，我还自己写了脚本啊，能用wiki语法写博客啊，写完可以自动处理成HTML啊，HTML啊！

　　好啊，写了一个多小时啦，加了不少代码了啊，得处理一下啊，啊，怎么不行啊，自定义的命令找不到啦，啊，文件扩展名写错了啊，那就改名啊！

　　苦逼的时候到了啊，为什么不保存文件退出到shell改啊，为什么装逼要在Vim里面改啊，提示我说会删除当前buffer啊，我说删除就删除啊，总得提示我文件没保存啊，尼玛它居然没提示啊，啥都没有啦！]]></description>
			<content:encoded><![CDATA[<p>　　闲着也是闲着啊，来公司学习啊，好久没写博客了呀，欲望很强烈啊，那就写吧！我用Vim写啊，我骄傲啊，我还自己写了脚本啊，能用wiki语法写博客啊，写完可以自动处理成HTML啊，HTML啊！</p>
<p>　　好啊，写了一个多小时啦，加了不少代码了啊，得处理一下啊，啊，怎么不行啊，自定义的命令找不到啦，啊，文件扩展名写错了啊，那就改名啊！</p>
<p>　　苦逼的时候到了啊，为什么不保存文件退出到shell改啊，为什么装逼要在Vim里面改啊，提示我说会删除当前buffer啊，我说删除就删除啊，总得提示我文件没保存啊，尼玛它居然没提示啊，啥都没有啦！</p>
<p>　　buffer删除了啊，恢复都恢复不了啊！</p>
<p>　　100多G的分区啊，我grep了10多分钟倒出来尽是尼玛垃圾啊！</p>
<p>　　硬盘没有那我就搜刮内存吧，/dev/mem不让我访问啊，尼玛我用超级用户都不行啊，Operation Not Permitted啊，尼玛这是不是我的机器啊，尼玛大爷我花了几千大洋买下你还不让爷看你赤裸裸的真相啊！</p>
<p>　　内核你麻痹啊！</p>
<p>　　Vi你个贱货啊，大爷辛辛苦苦地写博客啊，苦逼的我写的就是苦逼的你啊，大爷夸你美丽如花啊，洋洋洒洒轰轰烈烈几千字就这么被你给生吞啦，屁都尼玛没放一个啊，嚣张啊，臭流氓啊！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/07/kubi/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>vimrc被重复加载</title>
		<link>http://www.dutor.net/index.php/2011/06/vimrc-loaded-twice/</link>
		<comments>http://www.dutor.net/index.php/2011/06/vimrc-loaded-twice/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 14:13:25 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2611</guid>
		<description><![CDATA[　　重装了系统，Vim升级到了7.3。
　　之前，对于特定的文件类型建立了一些模版，类型的文件时候自动加载相应的模版。模版保存在$HOME/.vim/templates/下，比如C文件的模版为tpl.c。在.vimrc中有下面的配置：

<pre lang="vim" line="1">
function! LoadTemplate(extension)
    silent! :execute '0r $HOME/.vim/templates/'. "tpl.".a:extension
endfunction
" Load templates only when the file is NEW
au BufNewFile * silent! call LoadTemplate('%:e')
</pre>]]></description>
			<content:encoded><![CDATA[<p>　　重装了系统，Vim升级到了7.3。<br />
　　之前，对于特定的文件类型建立了一些模版，类型的文件时候自动加载相应的模版。模版保存在$HOME/.vim/templates/下，比如C文件的模版为tpl.c。在.vimrc中有下面的配置：</p>

<div class="wp_codebox"><table><tr id="p26111"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2611code1"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">function</span><span style="color: #000000;">!</span> LoadTemplate<span style="color: #000000;">&#40;</span>extension<span style="color: #000000;">&#41;</span>
    silent<span style="color: #000000;">!</span> <span style="color: #000000;">:</span><span style="color: #804040;">execute</span> <span style="color: #C5A22D;">'0r $HOME/.vim/templates/'</span><span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;tpl.&quot;</span><span style="color: #000000;">.</span>a<span style="color: #000000;">:</span>extension
endfunction
<span style="color: #adadad; font-style: italic;">&quot; Load templates only when the file is NEW</span>
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span> <span style="color: #000000;">*</span> silent<span style="color: #000000;">!</span> <span style="color: #804040;">call</span> LoadTemplate<span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'%:e'</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>　　升级后，发现新建文件时，模版被加载了两遍。开始怀疑是由于某种未知原因，autocmd被执行了两次，于是找到了filetype.vim，发现该脚步对重复加载有判断：</p>

<div class="wp_codebox"><table><tr id="p26112"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2611code2"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot; Listen very carefully, I will say this only once</span>
<span style="color: #804040;">if</span> <span style="color: #25BB4D;">exists</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;did_load_filetypes&quot;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">finish</span>
<span style="color: #804040;">endif</span>
<span style="color: #804040;">let</span> did_load_filetypes = <span style="color: #000000; font-weight:bold;">1</span></pre></td></tr></table></div>

<p>finish命令结束对当前脚步的读取。</p>
<p>    接着在.vimrc中也加了类似的判断：</p>

<div class="wp_codebox"><table><tr id="p26113"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2611code3"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">if</span> <span style="color: #25BB4D;">exists</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;did_load_vimrc&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #804040;">finish</span>
<span style="color: #804040;">endif</span>
<span style="color: #804040;">let</span> did_load_vimrc = <span style="color: #000000; font-weight:bold;">1</span></pre></td></tr></table></div>

<p>问题就消失了。</p>
<p>    为什么.vimrc为被加载两次呢？我在/etc/vimrc中找到了答案：</p>

<div class="wp_codebox"><table><tr id="p26114"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2611code4"><pre class="vim" style="font-family:monospace;">runtime<span style="color: #000000;">!</span> archlinux<span style="color: #000000;">.</span>vim
source <span style="color: #000000;">/</span>home<span style="color: #000000;">/</span>dutor<span style="color: #000000;">/.</span>vimrc</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/06/vimrc-loaded-twice/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>[Vim]使用Vim画ASCII图</title>
		<link>http://www.dutor.net/index.php/2011/04/vim-plugins-drawit-ascii-chart/</link>
		<comments>http://www.dutor.net/index.php/2011/04/vim-plugins-drawit-ascii-chart/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 09:02:32 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[drawit]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2560</guid>
		<description><![CDATA[基本使用：
<ul>
	<li> \di 进入画图模式；</li>
	<li> \ds 离开画图模式；</li>
	<li> 上下左右方向键，移动并画图；</li>
	<li> Shift+上下左右方向键，只移动光标；</li>
	<li> 空格键，打开/关闭擦除模式，擦除模式下，移动光标时光标处字符被空格取代；</li>
	<li> &#62;, &#60;, ^, v，画箭头；</li>
	<li> \&#62;, \&#60;, \^, \v，画粗箭头；</li>
	<li>可视化模式，即Ctrl + v后加motion后选中的文本块，可以使用下面快捷键：
<ul>
	<li> \a 画箭头，区块开始处，指向区块结束处；</li>
	<li> \b 画矩形框；</li>
	<li> \c 画幕布，会提示行数，列数使用&#38;textwidth选项，默认78列；</li>
	<li> \e 画椭圆；</li>
	<li> \l 划线。</li>
</ul>
</li>
	<li> 其他参考:h DrawIt。</li>
</ul>
　　建议：类似上面框图，先画好框架，然后利用Vim的替换模式（普通模式下按R）进行标识。]]></description>
			<content:encoded><![CDATA[<p>　　DrawIt是一个Vim插件，用来在Vim编辑器中使用键盘（主要是方向键）画ASCII图。下面就我使用DrawIt.vim画的C函数调用的堆栈示意图。</p>
<pre>
               +-----------------------+
               |          0            | <----0xbfffffff
               +-----------------------+
               |    filename           |
               +-----------------------+
               |    environment        |
               |    variables          |
               +-----------------------+
               |    ...............    |
               +-----------------------+
               |    arguments          |
+------+       +-----------------------+               |
|      |       |    return address     |               |
|      v       +-----------------------+               |
|    %ebp----> |    old %ebp           |               |
|              +-----------------------+               |
|              |                       |               |
|              |    local variables    |               |
|    %esp----> |                       |               |
|              +-----------------------+         stack |
|              |    argument 2         |               | growing
|              +-----------------------+     direction |
|              |    argument 1         |               |
|              +-----------------------+               |
|              |    return address     |               |
|              +-----------------------+               |
+--------------+    old %ebp           | <-----%ebp    |
               +-----------------------+               |
               |                       |               |
               |    local variables    |               |
               |                       | <-----%esp    |
               +-----------------------+               |
               | %$#!@^&#038;*^%$#$@!)<)>(@ |              _|_
               +-----------------------+              \ /
               | %$#!@^&#038;*^%$#$@!)<)>(@ |               '
               +-----------------------+
</pre>
<p>　　基本使用：</p>
<ul>
<li> \di 进入画图模式； </li>
<li> \ds 离开画图模式； </li>
<li> 上下左右方向键，移动并画图； </li>
<li> Shift+上下左右方向键，只移动光标； </li>
<li> 空格键，打开/关闭擦除模式，擦除模式下，移动光标时光标处字符被空格取代； </li>
<li> >, <, ^, v，画箭头； </li>
<li> \>, \<, \^, \v，画粗箭头； </li>
<li>可视化模式，即Ctrl + v后加motion后选中的文本块，可以使用下面快捷键：
<ul>
<li> \a 画箭头，区块开始处，指向区块结束处； </li>
<li> \b 画矩形框； </li>
<li> \c 画幕布，会提示行数，列数使用&#038;textwidth选项，默认78列； </li>
<li> \e 画椭圆； </li>
<li> \l 划线。 </li>
</ul>
</li>
<li> 其他参考:h DrawIt。 </li>
</ul>
<p>　　建议：类似上面框图，先画好框架，然后利用Vim的替换模式（普通模式下按R）进行标识。<br />
　　到此<a href="http://www.vim.org/scripts/script.php?script_id=40" target="_blank">下载DrawIt</a>。下载后，使用Vim打开，执行:so %安装即可。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/04/vim-plugins-drawit-ascii-chart/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>[Vim]列编辑&amp;VisIncr.vim</title>
		<link>http://www.dutor.net/index.php/2011/02/vim-visincr/</link>
		<comments>http://www.dutor.net/index.php/2011/02/vim-visincr/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 07:28:19 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2515</guid>
		<description><![CDATA[　　多数情况下，咱们编辑文档是逐行进行的。偶尔我们可能还需要按列编辑，比如项目编号，比如只有若干列不同的多行文本等。Vim为列模式编辑提供了比较“简洁”的支持，即可视化文本块（Visual Block）模式，它是三种可视化模式的一种（一种使用命令v按字符选取区域，一种使用命令V按行选取区域，另外一种就是这里的按矩形块选取区域，使用命令Ctrl-v）。例如，现在想要把一段C++代码中连续几行(比如3行)代码的某一列后面的部分注释掉，我们要做的就是把光标定位到该列，按下Ctrl-v，按两下j使该列3行高亮显示，再按下I，输入C++注释符//，然后按退出键<ESC>，搞定，Vim会为你完成剩下的工作。关于Visual Block模式下可以进行的其它简单操作，可以使用:h visual-operators查看。
　　但，简单的Vim命令的功能也仅限于此。若想完成更复杂的功能，就不得不动用高级一点的技巧了。比如为文档的每一行加上行号可以使用命令
<pre lang="vim">
:g/^/s//\=line(".")/    " 等价于:g/^/s/^/\=line(".")/
</pre>
　　解释一下：
<ul>
<li>:g/pat/，命令g查找模式pat（此处为^，行首，即每一行都会匹配），为每一个匹配行执行接下来的命令；</li>
<li>s/pat/str/，命令s在当前行查找模式pat，并使用str替代之；</li>
<li>\=，指示此处的字符串将由接下来的表达式的产生；</li>
<li>line(expr)，函数line返回由字符串expr指示的行号，"."代表当前行。</li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>　　多数情况下，咱们编辑文档是逐行进行的。偶尔我们可能还需要按列编辑，比如项目编号，比如只有若干列不同的多行文本等。Vim为列模式编辑提供了比较“简洁”的支持，即可视化文本块（Visual Block）模式，它是三种可视化模式的一种（一种使用命令v按字符选取区域，一种使用命令V按行选取区域，另外一种就是这里的按矩形块选取区域，使用命令Ctrl-v）。例如，现在想要把一段C++代码中连续几行(比如3行)代码的某一列后面的部分注释掉，我们要做的就是把光标定位到该列，按下Ctrl-v，按两下j使该列3行高亮显示，再按下I，输入C++注释符//，然后按退出键<ESC>，搞定，Vim会为你完成剩下的工作。关于Visual Block模式下可以进行的其它简单操作，可以使用:h visual-operators查看。<br />
　　但，简单的Vim命令的功能也仅限于此。若想完成更复杂的功能，就不得不动用高级一点的技巧了。比如为文档的每一行加上行号可以使用命令</p>

<div class="wp_codebox"><table><tr id="p25155"><td class="code" id="p2515code5"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>g<span style="color: #000000;">/^/</span>s<span style="color: #000000;">//</span>\=<span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">/</span>    <span style="color: #C5A22D;">&quot; 等价于:g/^/s/^/<span style="">\=</span>line(&quot;</span><span style="color: #000000;">.</span><span style="color: #C5A22D;">&quot;)/</span></pre></td></tr></table></div>

<p>　　解释一下：</p>
<ul>
<li>:g/pat/，命令g查找模式pat（此处为^，行首，即每一行都会匹配），为每一个匹配行执行接下来的命令；</li>
<li>s/pat/str/，命令s在当前行查找模式pat，并使用str替代之；</li>
<li>\=，指示此处的字符串将由接下来的表达式的产生；</li>
<li>line(expr)，函数line返回由字符串expr指示的行号，&#8221;.&#8221;代表当前行。</li>
</ul>
<p>　　仅仅为了演示，在下面文本的第2列前逐行依次插入需要0 2 4 6 8。</p>
<pre>
...
The global commands work by first scanning through the [range] lines and
marking each line where a match occurs (for a multi-line pattern, only the
start of the match matters). In a second scan the [cmd] is executed for
each marked line with its line number prepended. For ":v" and ":g!" the
command is executed for each not marked line.
...
</pre>
<p>　　首先将光标定位到第二列的字符h上，然后在标准模式依次执行Ctrl-v, 4j, I, 输入字符#(仅作占位用)，<ESC>退出。此时第二列均为字符#。此时执行命令</p>

<div class="wp_codebox"><table><tr id="p25156"><td class="code" id="p2515code6"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span><span style="color: #C5A22D;">'&lt;,'</span><span style="color: #000000;">&gt;</span>g<span style="color: #000000;">/</span>#<span style="color: #000000;">/</span>s<span style="color: #000000;">//</span>\=<span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">*</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">-</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;'&lt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">/</span>  <span style="color: #C5A22D;">&quot; 等价于'&lt;,'&gt;:g/#/s/#/<span style="">\=</span>2*(line(&quot;</span><span style="color: #000000;">.</span><span style="color: #C5A22D;">&quot;) - line(&quot;</span><span style="color: #C5A22D;">'&lt;&quot;))</span></pre></td></tr></table></div>

<p>这里面唯一需要解释的是&#8217;&lt;和&#8217;>分别表示最近一次Visual Area的开始处和结束处，用在这里就分别表示开始行和结束行。</p>
<p>　　上面的命令一定让列位感到无聊吧，嗯，Vim的众多插件就是专门干这种又脏又累又无聊的活计的。VisIncr就是一个按列产生递增/递减序列的插件。它不仅可以生成数字序列，还可以生成各种格式的日期序列（月日年周），而且对于数字序列还提供左右对齐的选项。好了，漫长的前戏终于结束了，下面的主角是VisIncr。</p>
<pre>
Examples:

	LEFT JUSTIFIED INCREMENTING EXAMPLES
	:I                              :I 2            *ex-visincr-I*
	            Use ctrl-V to                   Use ctrl-V to
	Original    Select, :I          Original    Select, :I 2
	   8            8                  8            8
	   8            9                  8            10
	   8            10                 8            12
	   8            11                 8            14
	   8            12                 8            16

	:I -1                           :I -2
	            Use ctrl-V to                   Use ctrl-V to
	Original    Select, :I -1       Original    Select, :I -3
	   8            8                  8            8
	   8            7                  8            5
	   8            6                  8            2
	   8            5                  8            -1
	   8            4                  8            -4

	RIGHT JUSTIFIED INCREMENTING EXAMPLES
	:II                             :II 2
	            Use ctrl-V to                   Use ctrl-V to
	Original    Select, :II         Original    Select, :II 2
	   8             8                 8             8
	   8             9                 8            10
	   8            10                 8            12
	   8            11                 8            14
	   8            12                 8            16

	:II -1                          :II -2
	            Use ctrl-V to                   Use ctrl-V to
	Original    Select, :II -1      Original    Select, :II -3
	   8            8                  8             8
	   8            7                  8             5
	   8            6                  8             2
	   8            5                  8            -1
	   8            4                  8            -4

	DATE INCREMENTING EXAMPLES
	:IMDY                                   *ex-visincr-IMDY*
	          Use ctrl-V to                   Use ctrl-V to
	Original  Select, :IMDY         Original  Select, :IMDY 7
	06/10/03     6/10/03            06/10/03     6/10/03
	06/10/03     6/11/03            06/10/03     6/17/03
	06/10/03     6/12/03            06/10/03     6/24/03
	06/10/03     6/13/03            06/10/03     6/1/03
	06/10/03     6/14/03            06/10/03     6/8/03

	:IYMD                                   *ex-visincr-IYMD*
	          Use ctrl-V to                   Use ctrl-V to
	Original  Select, :IYMD         Original  Select, :IYMD 7
	03/06/10    03/06/10            03/06/10    03/06/10
	03/06/10    03/06/11            03/06/10    03/06/17
	03/06/10    03/06/12            03/06/10    03/06/24
	03/06/10    03/06/13            03/06/10    03/07/ 1
	03/06/10    03/06/14            03/06/10    03/07/ 8

	:IDMY                                   *ex-visincr-IDMY*
	          Use ctrl-V to                   Use ctrl-V to
	Original  Select, :IDMY         Original  Select, :IDMY 7
	10/06/03    10/06/03            10/06/03    10/06/03
	10/06/03    11/06/03            10/06/03    17/06/03
	10/06/03    12/06/03            10/06/03    24/06/03
	10/06/03    13/06/03            10/06/03     1/07/03
	10/06/03    14/06/03            10/06/03     8/07/03

	ALPHABETIC INCREMENTING EXAMPLES
	:IA                                     *ex-visincr-IA*
	          Use ctrl-V to                 Use ctrl-V to
	Original  Select, :IA         Original  Select, :IA 2
	   a)          a)                A)           A)
	   a)          b)                A)           C)
	   a)          c)                A)           E)
	   a)          d)                A)           G)

	DAYNAME INCREMENTING EXAMPLES
	:ID                                     *ex-visincr-ID*
	          Use ctrl-V to                 Use ctrl-V to
	Original  Select, :ID         Original  Select, :ID 2
	  Sun       Sun                 Sun         Sun
	  Sun       Mon                 Sun         Tue
	  Sun       Tue                 Sun         Thu
	  Sun       Wed                 Sun         Sat
	  Sun       Thu                 Sun         Mon

	:ID
	          Use ctrl-V to                 Use ctrl-V to
	Original  Select, :ID         Original  Select, :ID 2
	 Sunday     Sunday             Sunday     Sunday
	 Sunday     Monday             Sunday     Monday
	 Sunday     Tuesday            Sunday     Tuesday
	 Sunday     Wednesday          Sunday     Wednesday
	 Sunday     Thursday           Sunday     Thursday

	MONTHNAME INCREMENTING EXAMPLES
	:IM                                     *ex-visincr-IM*
	          Use ctrl-V to                 Use ctrl-V to
	Original  Select, :IM         Original  Select, :IM 2
	  Jan       Jan                 Jan       Jan
	  Jan       Feb                 Jan       Mar
	  Jan       Mar                 Jan       May
	  Jan       Apr                 Jan       Jul
	  Jan       May                 Jan       Sep

	:IM
	          Use ctrl-V to                 Use ctrl-V to
	Original  Select, :IM         Original  Select, :IM 2
	 January    January            January    January
	 January    February           January    March
	 January    March              January    May
	 January    April              January    July
	 January    May                January    September
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/02/vim-visincr/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Vim]surround.vim</title>
		<link>http://www.dutor.net/index.php/2010/10/vim-surround/</link>
		<comments>http://www.dutor.net/index.php/2010/10/vim-surround/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 14:30:38 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2478</guid>
		<description><![CDATA[　　写程序时，尤其在C/C++程序中，有大量的配对的符号（surrounding）：( ), [ ], { }, < > ' ', " "，另外标记语言（如XML）更是由无数的配对标记组成：<xml></xml>, <p></p>. 如果能够快速地处理这些surroundings，就能大大提升编程的效率。
　　Vim本身就有这种配对符号的能力，在Vim中这叫做text object，可以使用:h text-objects查看这些text objects。你会发现Vim只能对这些配对符所包含的文本或者整个text object进行删除和修改，却不能对surrounding进行修改，更不能为普通文本添加surrounding。
　　既然有这种需求，就肯定会有热心人士努力，来满足这种需求，方便了自己，也方便了整个Vim用户群。<a href="http://www.vim.org/account/profile.php?user_id=9012" target="_blank">Tim Pope同志</a>就为Vim写了这款插件，surround.vim：

<blockquote>
This plugin is a tool for dealing with pairs of "surroundings."  Examples of surroundings include parentheses, quotes, and HTML tags.  They are closely related to what Vim refers to as &#124;text-objects&#124;.  Provided are mappings to allow for removing, changing, and adding surroundings.
</blockquote>]]></description>
			<content:encoded><![CDATA[<p>　　写程序时，尤其在C/C++程序中，有大量的配对的符号（surrounding）：( ), [ ], { }, < > &#8216; &#8216;, &#8221; &#8220;，另外标记语言（如XML）更是由无数的配对标记组成：<xml></xml>,
</p>
<p>. 如果能够快速地处理这些surroundings，就能大大提升编程的效率。<br />
　　Vim本身就有这种配对符号的能力，在Vim中这叫做text object，可以使用:h text-objects查看这些text objects。你会发现Vim只能对这些配对符所包含的文本或者整个text object进行删除和修改，却不能对surrounding进行修改，更不能为普通文本添加surrounding。<br />
　　既然有这种需求，就肯定会有热心人士努力，来满足这种需求，方便了自己，也方便了整个Vim用户群。<a href="http://www.vim.org/account/profile.php?user_id=9012" target="_blank">Tim Pope同志</a>就为Vim写了这款插件，surround.vim：</p>
<blockquote><p>
This plugin is a tool for dealing with pairs of &#8220;surroundings.&#8221;  Examples of surroundings include parentheses, quotes, and HTML tags.  They are closely related to what Vim refers to as |text-objects|.  Provided are mappings to allow for removing, changing, and adding surroundings.
</p></blockquote>
<p>　　下面是surround.vim插件帮助文档中的示例：</p>
<pre>
  Old text                  Command     New text ~
  "Hello *world!"           ds"         Hello world!
  [123+4*56]/2              cs])        (123+456)/2
  "Look ma, I'm *HTML!"     cs"&lt;q>      &lt;q>Look ma, I'm HTML!&lt;/q>
  if *x>3 {                 ysW(        if ( x>3 ) {
  my $str = *whee!;         vlllls'     my $str = 'whee!';
  &lt;div>Yo!*&lt;/div>           dst         Yo!
  &lt;div>Yo!*&lt;/div>           cst&lt;p>      &lt;p>Yo!&lt;/p>
</pre>
<p>其中，*表示光标所在位置。<br />
　　下面是surround.vim插件支持的快捷键的列表：</p>
<pre>
Normal mode
-----------
ds  - delete a surrounding
cs  - change a surrounding
ys  - add a surrounding
yS  - add a surrounding and place the surrounded text on a new line + indent it
yss - add a surrounding to the whole line
ySs - add a surrounding to the whole line, place it on a new line + indent it
ySS - same as ySs

Visual mode
-----------
s   - in visual mode, add a surrounding
S   - in visual mode, add a surrounding but place text on new line + indent it

Insert mode
-----------
&lt;CTRL-s> - in insert mode, add a surrounding
&lt;CTRL-s>&lt;CTRL-s> - in insert mode, add a new line + surrounding + indent
&lt;CTRL-g>s - same as &lt;CTRL-s>
&lt;CTRL-g>S - same as &lt;CTRL-s>&lt;CTRL-s>
</pre>
<p>　　关于这些快捷键，更加详析的解释参见该插件的help文档。<br />
　　需要注意的一点是，安装此插件后，在Visual Mode内原来的s与S（substitute）命令便不再有效，如果你经常在V模式下使用替换命令，你可能需要对该插件略作修改，将V模式下对应的键映射代码注释掉。<br />
　　另外，如果你在终端中使用Vim，Insert Mode中使用Ctrl + s键时，则可能会使终端冻结（Ctrl + q解除冻结）。此时你可以使用对应的Ctrl + g版本的快捷键。<br />
　　最后，你可以在<a href="http://www.vim.org/scripts/script.php?script_id=1697" target="_blank">这里下载该插件</a>，安装方式和其它插件相同：把得到的zip文件解压缩到.vim下即可，为了使用help文档，可能还需要执行一次:helptags ~/.vim/doc。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/10/vim-surround/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>[Vim]配对类符号相关命令</title>
		<link>http://www.dutor.net/index.php/2010/06/vim-pair-char/</link>
		<comments>http://www.dutor.net/index.php/2010/06/vim-pair-char/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 14:35:51 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2316</guid>
		<description><![CDATA[　　代码中编辑一些配对符号内的内容是十分普遍的，这些配对符号包括：'', "", (), {}, [], <>等等。Vim提供了一些命令来方便的编辑这些符号所包含的内容，将光标定位于某符号（如(或者)）：
<ul>
	<li>ci: 例如，ci(，或者ci)，将会修改()之间的文本；</li>
	<li>di: 剪切配对符号之间文本；</li>
	<li>yi: 复制；</li>
	<li>ca: 同ci，但修改内容包括配对符号本身；</li>
	<li>da: 同di，但剪切内容包括配对符号本身；</li>
	<li>ya: 同yi，但复制内容包括配对符号本身。</li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>　　代码中编辑一些配对符号内的内容是十分普遍的，这些配对符号包括：&#8221;, &#8220;&#8221;, (), {}, [], <>等等。Vim提供了一些命令来方便的编辑这些符号所包含的内容，将光标定位于某符号（如(或者)）：</p>
<ul>
<li>ci: 例如，ci(，或者ci)，将会修改()之间的文本；</li>
<li>di: 剪切配对符号之间文本；</li>
<li>yi: 复制；</li>
<li>ca: 同ci，但修改内容包括配对符号本身；</li>
<li>da: 同di，但剪切内容包括配对符号本身；</li>
<li>ya: 同yi，但复制内容包括配对符号本身。</li>
</ul>
<p>PS. dib等同于di(。diB等同于di{。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/06/vim-pair-char/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Vim]我的vimrc</title>
		<link>http://www.dutor.net/index.php/2010/06/my-vimrc/</link>
		<comments>http://www.dutor.net/index.php/2010/06/my-vimrc/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 11:59:14 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2309</guid>
		<description><![CDATA[　　我的.vimrc，贴出来给大家瞧瞧。有一些不太优雅的，或者个人色彩太强的，或者晦涩的，或者基于特定插件的部分已经被滤掉了。需要注意的是，对于gVim（Windows或者Linux/Unix），我把菜单栏和工具栏都隐藏了，不习惯的话把相关行注释即可。
　　下面是一些键映射，仅供参考。
<pre lang="vim">
" escape for <ESC>
imap jj <esc>
" ' for `
map ' `
" save the file
" map <leader>w :w<cr>
map ,w :w<cr>
" quit
map ,q :q<cr>
" save and quit
map ,z ZZ
" yank from current line to the EOF
map ,yy "+yG
" paste from clipboard
map ,p "+p
" do substitution globally
map ,s :%s/
" do substitution in current line
map zs :s/
" roll up half screen
"map <tab> <C-u>
" roll down half screen
"map <space> <C-d>
" open the Calendar
map <F4> :Calendar<cr>
" open the NERDTree
map <F10> :NERDTree<cr>
" insert a \n
map ,<cr> i<cr><esc>
" Edit .vimrc
map ,,, :tabnew $HOME/.vimrc<cr>
</pre>]]></description>
			<content:encoded><![CDATA[<p>　　我的.vimrc，贴出来给大家瞧瞧。有一些不太优雅的，或者个人色彩太强的，或者晦涩的，或者基于特定插件的部分已经被滤掉了。需要注意的是，对于gVim（Windows或者Linux/Unix），我把菜单栏和工具栏都隐藏了，不习惯的话把相关行注释即可。</p>

<div class="wp_codebox"><table><tr id="p23097"><td class="code" id="p2309code7"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot;===================================================================</span>
<span style="color: #adadad; font-style: italic;">&quot; Author:       Dutor@dutor.net.</span>
<span style="color: #adadad; font-style: italic;">&quot; Email:        Xdutor@gmail.com</span>
<span style="color: #adadad; font-style: italic;">&quot; Last Edited:  Dec 12 2009</span>
<span style="color: #adadad; font-style: italic;">&quot;===================================================================</span>
<span style="color: #adadad; font-style: italic;">
&quot; --------------------set file encoding-------------------------</span>
<span style="color: #804040;">set</span> <span style="color: #804040;">fileencoding</span>=utf<span style="color: #000000;">-</span><span style="color: #000000; font-weight:bold;">8</span> <span style="color: #C5A22D;">&quot; default file encoding
set fileencodings=gbk,gb2312,gb18030,utf-8,cp936 &quot;</span> recognizable <span style="color: #668080;">encoding</span>
<span style="color: #804040;">set</span> <span style="color: #668080;">formatoptions</span><span style="color: #000000;">+</span>=mM
<span style="color: #C5A22D;">&quot;set autowrite      &quot;</span> auto saves changes when quitting and swiching buffer
<span style="color: #804040;">set</span> <span style="color: #668080;">ambiwidth</span>=double <span style="color: #C5A22D;">&quot; ambicious code
set nocompatible    &quot;</span> use vim defaults
<span style="color: #804040;">set</span> <span style="color: #668080;">wildmenu</span>        <span style="color: #C5A22D;">&quot; Turn on wild menu
set wildmode=full   &quot;</span> Set the completion <span style="color: #25BB4D;">mode</span> <span style="color: #668080;">to</span> <span style="color: #C5A22D;">&quot;full&quot;</span>
<span style="color: #804040;">set</span> <span style="color: #668080;">ls</span>=<span style="color: #000000; font-weight:bold;">2</span>            <span style="color: #C5A22D;">&quot; allways show status line
set tabstop=4       &quot;</span> numbers of spaces of tab character
<span style="color: #804040;">set</span> <span style="color: #668080;">shiftwidth</span>=<span style="color: #000000; font-weight:bold;">4</span>    <span style="color: #C5A22D;">&quot; numbers of spaces of (auto)indent
set scrolloff=1     &quot;</span> keep <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #668080;">lines</span> when scrolling
<span style="color: #804040;">set</span> <span style="color: #668080;">showcmd</span>         <span style="color: #C5A22D;">&quot; display incomplete commands in Last Line
&quot;</span> <span style="color: #804040;">set</span> <span style="color: #668080;">hlsearch</span>      <span style="color: #C5A22D;">&quot; highlight searches
set incsearch       &quot;</span> do incremental searching
<span style="color: #804040;">set</span> <span style="color: #668080;">ignorecase</span>      <span style="color: #C5A22D;">&quot; ignore case when searching
set ruler           &quot;</span> show the <span style="color: #25BB4D;">cursor</span> position all the time
<span style="color: #804040;">set</span> <span style="color: #668080;">novisualbell</span>    <span style="color: #C5A22D;">&quot; turn off visual bell
set nobackup        &quot;</span> do not keep a <span style="color: #668080;">backup</span> file
<span style="color: #804040;">set</span> <span style="color: #668080;">number</span>          <span style="color: #C5A22D;">&quot; show line numbers
set title           &quot;</span> show <span style="color: #668080;">title</span> <span style="color: #804040;">in</span> console <span style="color: #668080;">title</span> bar
<span style="color: #804040;">set</span> <span style="color: #668080;">ttyfast</span>         <span style="color: #C5A22D;">&quot; smoother changes
set modeline        &quot;</span> last <span style="color: #668080;">lines</span> <span style="color: #804040;">in</span> document sets vim <span style="color: #25BB4D;">mode</span>
<span style="color: #804040;">set</span> <span style="color: #668080;">modelines</span>=<span style="color: #000000; font-weight:bold;">3</span>     <span style="color: #C5A22D;">&quot; number lines checked for modelines
set shortmess=atI   &quot;</span> Abbreviate messages
<span style="color: #C5A22D;">&quot;set whichwrap=b,s,h,l,&lt;,&gt;,[,]   &quot;</span> move freely between files
<span style="color: #adadad; font-style: italic;">&quot; informative status line, with filename&amp;format&amp;ValueOfChar&amp;positon&amp;length</span>
<span style="color: #804040;">set</span> <span style="color: #668080;">statusline</span>=<span style="color: #000000;">%&lt;%</span>F<span style="color: #000000;">%</span>m<span style="color: #000000;">%</span>r\ <span style="color: #000000;">&#91;</span><span style="color: #000000;">%</span>Y<span style="color: #000000;">&#93;</span>\ <span style="color: #000000;">&#91;</span>ASCII=\<span style="color: #000000;">%.</span>3b<span style="color: #000000;">&#93;</span>\ <span style="color: #000000;">&#91;</span>HEX=0x\<span style="color: #000000;">%.</span>2B<span style="color: #000000;">&#93;</span><span style="color: #000000;">%</span>=<span style="color: #000000;">&#91;</span>POS=<span style="color: #000000;">%</span>l,<span style="color: #000000;">%</span>v<span style="color: #000000;">&#93;</span>\ <span style="color: #000000;">&#91;</span>LEN=<span style="color: #000000;">%</span>L<span style="color: #000000;">&#93;</span>\ <span style="color: #000000;">%</span>p<span style="color: #000000;">%%</span>
<span style="color: #adadad; font-style: italic;">&quot;set statusline=%F%m%r%h%w\ [FORMAT=%{&amp;ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]</span>
<span style="color: #adadad; font-style: italic;">&quot; --------------------something on C/C++------------------------</span>
<span style="color: #804040;">set</span> <span style="color: #668080;">autoindent</span>     <span style="color: #C5A22D;">&quot; always set autoindenting on
set smartindent        &quot;</span> smart <span style="color: #25BB4D;">indent</span>
<span style="color: #804040;">set</span> <span style="color: #668080;">cindent</span>            <span style="color: #C5A22D;">&quot; cindent
set cino=g0         &quot;</span> <span style="color: #25BB4D;">indent</span> class access specifier such as public, private
<span style="color: #804040;">set</span> <span style="color: #668080;">expandtab</span>      <span style="color: #C5A22D;">&quot; tabs are converted to spaces, use only when required
set wrap         &quot;</span> don<span style="color: #C5A22D;">'t wrap lines
set nosm             &quot; do not show matching braces.
syntax on           &quot; syntax highlighing
&quot;set noautoindent
&quot;set nosmartindent
&quot;set nocindent
&quot;:source $HOME/.vim/abbreviation.vim
&quot; -------------------Configuration for gVim---------------------
if has(&quot;gui_running&quot;)
    &quot; See ~/.gvimrc
    set guifont=Courier<span style="">\ </span>New<span style="">\ </span>12  &quot; use this font
    set lines=30       &quot; height = 50 lines
    set columns=100        &quot; width = 100 columns
    set background=dark   &quot; adapt colors for background
    set guioptions-=m       &quot; remove the menu
    set guioptions-=T       &quot; remove the Toolbar
    set cul                 &quot; set CursorLine
    colorscheme darkblue    &quot; use this color scheme
else
    colorscheme default    &quot; use this color scheme
    &quot;set background=dark        &quot; adapt colors for background
endif
:hi Comment ctermfg=green
:hi StatusLine ctermbg=black
&quot; ----------------------When Vim starts ...---------------------
&quot;:source $HOME/.vim/extern/autocmd.vim
&quot; -----------------Keyboard mappings 閿粦瀹?--------------------
&quot;:source $HOME/.vim/extern/keybind.vim</span></pre></td></tr></table></div>

<p>　　下面是一些键映射，仅供参考。</p>

<div class="wp_codebox"><table><tr id="p23098"><td class="code" id="p2309code8"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot; escape for &lt;ESC&gt;</span>
imap jj <span style="color: #000000;">&lt;</span>esc<span style="color: #000000;">&gt;</span>
<span style="color: #adadad; font-style: italic;">&quot; ' for `</span>
<span style="color: #804040;">map</span> <span style="color: #C5A22D;">' `
&quot; save the file
&quot; map &lt;leader&gt;w :w&lt;cr&gt;
map ,w :w&lt;cr&gt;
&quot; quit
map ,q :q&lt;cr&gt;
&quot; save and quit
map ,z ZZ
&quot; yank from current line to the EOF
map ,yy &quot;+yG
&quot; paste from clipboard
map ,p &quot;+p
&quot; do substitution globally
map ,s :%s/
&quot; do substitution in current line
map zs :s/
&quot; roll up half screen
&quot;map &lt;tab&gt; &lt;C-u&gt;
&quot; roll down half screen
&quot;map &lt;space&gt; &lt;C-d&gt;
&quot; open the Calendar
map &lt;F4&gt; :Calendar&lt;cr&gt;
&quot; open the NERDTree
map &lt;F10&gt; :NERDTree&lt;cr&gt;
&quot; insert a <span style="">\n</span>
map ,&lt;cr&gt; i&lt;cr&gt;&lt;esc&gt;
&quot; Edit .vimrc
map ,,, :tabnew $HOME/.vimrc&lt;cr&gt;
&quot; toggle btw. windows
map &lt;C-H&gt; &lt;C-w&gt;h
map &lt;C-L&gt; &lt;C-w&gt;l
&quot; tabs operations
map tn :tabNext&lt;CR&gt;
map tp :tabprevious&lt;CR&gt;
map tc :tabclose&lt;CR&gt;
map tm :tabmove&lt;CR&gt;
map tf :tabfirst&lt;CR&gt;
map tl :tablast&lt;CR&gt;
&quot;map gf :tabnew &lt;cfile&gt;&lt;cr&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/06/my-vimrc/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>[Vim]交换CapsLock和Esc</title>
		<link>http://www.dutor.net/index.php/2010/05/vim-swap-capslock-esc/</link>
		<comments>http://www.dutor.net/index.php/2010/05/vim-swap-capslock-esc/#comments</comments>
		<pubDate>Sat, 22 May 2010 02:22:29 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[命令]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2296</guid>
		<description><![CDATA[　　Esc是Vim爱好者使用非常频繁的一个按键。但，你不觉得它离你的左手有点远吗？我已经有很长时间没有使用这个键了，取而代之的是组合键Ctrl + [。但，Ctrl + [ 是不是有些麻烦呢？CapsLock，你常用到吗？我几乎不用。相反，CapsLock键就待在Tab键下面，一不留神就会按下，这在Vim下经常会导致一些莫名奇怪的现象。那我们就把它挪走吧！怎么挪？把它和Esc交换啊，但这里不是硬件的交换，你不用把Esc和CapsLock键抠下来交换，而只需要让OS把这两个键的映射对换一下即可。使用命令xmodmap可以完成此操作，xmodmap的具体用法，参考manpage。为了完成CapsLock和Esc的映射交换，你需要建立文件~/.Xmodmap:
<pre>
remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock
</pre>
然后，执行
<pre lang="bash">
xmodmap ~/.Xmodmap # 使映射生效
</pre>]]></description>
			<content:encoded><![CDATA[<p>　　Esc是Vim爱好者使用非常频繁的一个按键。但，你不觉得它离你的左手有点远吗？我已经有很长时间没有使用这个键了，取而代之的是组合键Ctrl + [。但，Ctrl + [ 是不是有些麻烦呢？CapsLock，你常用到吗？我几乎不用。相反，CapsLock键就待在Tab键下面，一不留神就会按下，这在Vim下经常会导致一些莫名奇怪的现象。那我们就把它挪走吧！怎么挪？把它和Esc交换啊，但这里不是硬件的交换，你不用把Esc和CapsLock键抠下来交换，而只需要让OS把这两个键的映射对换一下即可。使用命令xmodmap可以完成此操作，xmodmap的具体用法，参考manpage。为了完成CapsLock和Esc的映射交换，你需要建立文件~/.Xmodmap:</p>
<pre>
remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock
</pre>
<p>然后，执行</p>

<div class="wp_codebox"><table><tr id="p22969"><td class="code" id="p2296code9"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">xmodmap</span> ~<span style="color: #000000; font-weight: bold;">/</span>.Xmodmap <span style="color: #666666; font-style: italic;"># 使映射生效</span></pre></td></tr></table></div>

<p>　　如果你使用ubuntu，在System -> Preferences -> KeyBoard -> Layout -> Options -> Capslock behavior中也可设置交换CapsLock和ESC。<br />
　　最后，提供另一种策略，用Vim的insert模式下的键映射来实现ESC。即在vimrc中做映射imap jj <esc> 。当然你可以选择其它键来映射ESC，但地球人都用jj，你自己掂量着办！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/05/vim-swap-capslock-esc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Vim]代码注释插件The NERD Commenter</title>
		<link>http://www.dutor.net/index.php/2010/05/vim-the-nerd-commenter/</link>
		<comments>http://www.dutor.net/index.php/2010/05/vim-the-nerd-commenter/#comments</comments>
		<pubDate>Wed, 05 May 2010 02:24:38 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2249</guid>
		<description><![CDATA[　　这是一款供Vim使用的插件，看名字可以知道，它和<a href="http://www.dutor.net/index.php/2010/01/vim-calendar-nerdtree/" target="_blank">The NERD Tree</a>同属一个作者。使用这款插件，你可以对多种文件类型的文件进行不同方式地、快速地注释。这对使用Vim来写代码或者修改配置文件的同学来说，无疑是提升效率和快感的一件利器。你可以到<a href="http://www.vim.org/scripts/script.php?script_id=1218" target="_blank">这里来下载</a>这个插件，将压缩包里面的doc/和plugin/文件夹丢到~/.vim/下面就是安装了。为了可以使用其帮助文档，你还需要在Vim中执行:helptags ~/.vim/doc/来注册。
　　简单介绍下NERD Commenter的常用键绑定，以C/C++文件为例，详析的使用方法，请:h NERDCommenter。在Normal或者Visual 模式下：
<ul>
	<li>,ca，在可选的注释方式之间切换，比如C/C++ 的块注释/* */和行注释//</li>
	<li>,cc，注释当前行</li>
	<li>,c<space>，切换注释/非注释状态</li>
	<li>,cs，以"性感"的方式注释</li>
	<li>,cA，在当前行尾添加注释符，并进入Insert模式</li>
	<li>,cu，取消注释</li>
	<li>Normal模式下，几乎所有命令前面都可以指定行数</li>
	<li>Visual模式下执行命令，会对选中的特定区块进行注释/反注释</li>
</ul>
]]></description>
			<content:encoded><![CDATA[<p>　　这是一款供Vim使用的插件，看名字可以知道，它和<a href="http://www.dutor.net/index.php/2010/01/vim-calendar-nerdtree/" target="_blank">The NERD Tree</a>同属一个作者。使用这款插件，你可以对多种文件类型的文件进行不同方式地、快速地注释。这对使用Vim来写代码或者修改配置文件的同学来说，无疑是提升效率和快感的一件利器。你可以到<a href="http://www.vim.org/scripts/script.php?script_id=1218" target="_blank">这里来下载</a>这个插件，将压缩包里面的doc/和plugin/文件夹丢到~/.vim/下面就是安装了。为了可以使用其帮助文档，你还需要在Vim中执行:helptags ~/.vim/doc/来注册。<br />
　　简单介绍下NERD Commenter的常用键绑定，以C/C++文件为例，详析的使用方法，请:h NERDCommenter。在Normal或者Visual 模式下：</p>
<ul>
<li>,ca，在可选的注释方式之间切换，比如C/C++ 的块注释/* */和行注释//</li>
<li>,cc，注释当前行</li>
<li>,c<space>，切换注释/非注释状态</li>
<li>,cs，以&#8221;性感&#8221;的方式注释</li>
<li>,cA，在当前行尾添加注释符，并进入Insert模式</li>
<li>,cu，取消注释</li>
<li>Normal模式下，几乎所有命令前面都可以指定行数</li>
<li>Visual模式下执行命令，会对选中的特定区块进行注释/反注释</li>
</ul>
<p><strong>注：各命令前缀<Leader>是可以自己设置的，通常是逗号&#8217;,'或者&#8217;\&#8217;.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/05/vim-the-nerd-commenter/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>[Vim]恢复文件关闭之前光标的位置</title>
		<link>http://www.dutor.net/index.php/2010/04/vim-recover-cursor/</link>
		<comments>http://www.dutor.net/index.php/2010/04/vim-recover-cursor/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 08:19:48 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2131</guid>
		<description><![CDATA[　　某些情况下，你不得不停下当前文件的编辑工作，退出Vim，处理其他的事情，然后重新打开Vim继续刚才的工作。我总是希望Vim打开某个文件的时候，光标停在上次关闭文件时所停留的位置。Vim的默认配置似乎也是这样的，但直到我添加了自己的~/.vimrc和各种插件、模板文件后，Vim的"记忆"似乎被抹去了。每次打开文件，光标总是在文件的第一个字节处闪烁。于是我只能使用'.或者`.使光标移动到最后修改过的地方，但是，你知道的，我的注意力并不是总在刚刚修改过的地方。通常，光标在哪里，我的瞳孔就朝向哪里。
　　这个问题<em>折磨</em>我好久了，我终于下决心要整治一下。我先把那些插件给禁掉，又把map的很多键也禁了，最后把自定义的.vimrc也清空了，但问题依旧……这让我很是无奈。
　　Google了半天，据说viminfo保存了文件的一些状态信息，包括光标信息。:h viminfo，得知'0保存了Vim上次退出时光标的位置信息。但'0还不是我想要的，因为它保存的是一个"全局"的位置信息。比如，我先打开foo.c，光标移动到非开头处，退出，再打开bar.c，移动到非开头处，退出，再打开foo.c，按下'0，Vim自动打开bar.c并跳到退出时的位置。
]]></description>
			<content:encoded><![CDATA[<p>　　某些情况下，你不得不停下当前文件的编辑工作，退出Vim，处理其他的事情，然后重新打开Vim继续刚才的工作。我总是希望Vim打开某个文件的时候，光标停在上次关闭文件时所停留的位置。Vim的默认配置似乎也是这样的，但直到我添加了自己的~/.vimrc和各种插件、模板文件后，Vim的&#8221;记忆&#8221;似乎被抹去了。每次打开文件，光标总是在文件的第一个字节处闪烁。于是我只能使用&#8217;.或者`.使光标移动到最后修改过的地方，但是，你知道的，我的注意力并不是总在刚刚修改过的地方。通常，光标在哪里，我的瞳孔就朝向哪里。<br />
　　这个问题<em>折磨</em>我好久了，我终于下决心要整治一下。我先把那些插件给禁掉，又把map的很多键也禁了，最后把自定义的.vimrc也清空了，但问题依旧……这让我很是无奈。<br />
　　Google了半天，据说viminfo保存了文件的一些状态信息，包括光标信息。:h viminfo，得知&#8217;0保存了Vim上次退出时光标的位置信息。但&#8217;0还不是我想要的，因为它保存的是一个&#8221;全局&#8221;的位置信息。比如，我先打开foo.c，光标移动到非开头处，退出，再打开bar.c，移动到非开头处，退出，再打开foo.c，按下&#8217;0，Vim自动打开bar.c并跳到退出时的位置。</p>
<p>　　最后我决定开口求救。LinuxToy上的朋友帮我解决了这个问题。只需要vimrc里面加一个稍微复杂一点的autocmd就搞定了：</p>

<div class="wp_codebox"><table><tr id="p213110"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p2131code10"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">if</span> <span style="color: #25BB4D;">has</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;autocmd&quot;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufReadPost</span> <span style="color: #000000;">*</span> <span style="color: #804040;">if</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;'<span style="">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&gt;</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&amp;&amp;</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;'<span style="">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&lt;</span>= <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;$&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">|</span> <span style="color: #804040;">exe</span> <span style="color: #C5A22D;">&quot;normal! g'<span style="">\&quot;</span>&quot;</span> <span style="color: #000000;">|</span> <span style="color: #804040;">endif</span>
<span style="color: #804040;">endif</span></pre></td></tr></table></div>

<p>　　刚才翻看了Vim的全局配置/etc/vim/vimrc，里面有被注释的这么几行：</p>

<div class="wp_codebox"><table><tr id="p213111"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2131code11"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot; Uncomment the following to have Vim jump to the last position when</span>
<span style="color: #adadad; font-style: italic;">&quot; reopening a file</span>
<span style="color: #C5A22D;">&quot;if has(&quot;</span><span style="color: #804040;">autocmd</span><span style="color: #C5A22D;">&quot;)
&quot;</span>  <span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufReadPost</span> <span style="color: #000000;">*</span> <span style="color: #804040;">if</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;'<span style="">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&gt;</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&amp;&amp;</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;'<span style="">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&lt;</span>= <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;$&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">|</span> <span style="color: #804040;">exe</span> <span style="color: #C5A22D;">&quot;normal! g'<span style="">\&quot;</span>&quot;</span> <span style="color: #000000;">|</span> <span style="color: #804040;">endif</span>
<span style="color: #adadad; font-style: italic;">&quot;endif</span></pre></td></tr></table></div>

<p>　　见鬼了，这几行是被注释掉的，可为啥，我刚刚装好的Vim却会自动地定位光标呢？</p>
<h6>更新</h6>
<p>　　解释下上面的autocmd命令。首先，当打开任何文件时，首先判断上次退出该文件时光标所在行，如果不在第一行，那么执行exe命令，即:开头的命令，:normal! g&#8217;&#8221;命令是在normal模式下执行g&#8217;&#8221;，即将光标定位到上次退出文件时所在行。为了使光标准确定位至“某一行的某一列”，需要使用`来跳转至标记&#8221;，而不是&#8217;。最后，代码应该是，</p>

<div class="wp_codebox"><table><tr id="p213112"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2131code12"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot; Uncomment the following to have Vim jump to the last position when</span>
<span style="color: #adadad; font-style: italic;">&quot; reopening a file</span>
<span style="color: #804040;">if</span> <span style="color: #25BB4D;">has</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;autocmd&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufReadPost</span> <span style="color: #000000;">*</span> <span style="color: #804040;">if</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;`<span style="">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&gt;</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&amp;&amp;</span> <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;`<span style="">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&lt;</span>= <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;$&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">|</span> <span style="color: #804040;">exe</span> <span style="color: #C5A22D;">&quot;normal! g`<span style="">\&quot;</span>&quot;</span> <span style="color: #000000;">|</span> <span style="color: #804040;">endif</span>
<span style="color: #C5A22D;">&quot; for simplicity, &quot;</span>  <span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufReadPost</span> <span style="color: #000000;">*</span> <span style="color: #804040;">exe</span> <span style="color: #C5A22D;">&quot;normal! g`<span style="">\&quot;</span>&quot;</span>, <span style="color: #668080;">is</span> Okay<span style="color: #000000;">.</span>
<span style="color: #804040;">endif</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/04/vim-recover-cursor/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>[Vim]Vim入门级技巧集</title>
		<link>http://www.dutor.net/index.php/2010/04/vim-basic/</link>
		<comments>http://www.dutor.net/index.php/2010/04/vim-basic/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 10:47:45 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2124</guid>
		<description><![CDATA[<h4>开场白</h4>
Vim是一个十分强大的文本编辑器，被誉为”编辑器之神”，熟练地使用Vim会使你处理文本、编辑代码的效率提升n个数量级！如果你现在还在使用gedit甚至是”记事本”的话，我奉劝你赶快把它扔到垃圾桶，马上开始你的Vim之旅。这里列出一些我经常使用的基本的Vim命令和技巧，Vim的使用是一个长期的学习、实践、再学习、再实践的过程。Here we go.
<h4>安装Vim/Gvim</h4>
如果你现在没使用过Vim/Gvim，你首先需要安装它们，当前的版本为7.2。Debian/Ubuntu下面，sudo apt-get install vim-gnome即可。其他系统也有相应的包管理程序来直接安装。对于Windows，你需要到<a href="http://www.vim.org/download.php" target="_blank">Vim的官方网站</a>来下载安装。安装时记得选中"设置Vim环境变量"的选项，这样你就可以直接在cmd下使用vim了。
在正式开始之前，最好在终端(cmd)里运行vimtutor，一步步按照提示操作，以对vim的操作有一个初步的了解。
<h4>快速的移动</h4>
<h5>别在总在插入模式里呆着</h5>
除了敲代码，不要总在插入模式里呆着，因为这样的Vim就和诸如gedit等普通的编辑器就没什么区别了。这就是为什么一些新手总是在插入模式的原因了，”好用”或者说”友好”。但是，Vim真正的威力却在于其命令模式，你将会发现，随着你对Vim的了解和熟练，你用插入模式的时间会越来越少。]]></description>
			<content:encoded><![CDATA[<h4>开场白</h4>
<p>Vim是一个十分强大的文本编辑器，被誉为”编辑器之神”，熟练地使用Vim会使你处理文本、编辑代码的效率提升n个数量级！如果你现在还在使用gedit甚至是”记事本”的话，我奉劝你赶快把它扔到垃圾桶，马上开始你的Vim之旅。这里列出一些我经常使用的基本的Vim命令和技巧，Vim的使用是一个长期的学习、实践、再学习、再实践的过程。Here we go.</p>
<h4>安装Vim/Gvim</h4>
<p>如果你现在没使用过Vim/Gvim，你首先需要安装它们，当前的版本为7.2。Debian/Ubuntu下面，sudo apt-get install vim-gnome即可。其他系统也有相应的包管理程序来直接安装。对于Windows，你需要到<a href="http://www.vim.org/download.php" target="_blank">Vim的官方网站</a>来下载安装。安装时记得选中&#8221;设置Vim环境变量&#8221;的选项，这样你就可以直接在cmd下使用vim了。<br />
在正式开始之前，最好在终端(cmd)里运行vimtutor，一步步按照提示操作，以对vim的操作有一个初步的了解。</p>
<h4>快速的移动</h4>
<h5>别在总在插入模式里呆着</h5>
<p>除了敲代码，不要总在插入模式里呆着，因为这样的Vim就和诸如gedit等普通的编辑器就没什么区别了。这就是为什么一些新手总是在插入模式的原因了，”好用”或者说”友好”。但是，Vim真正的威力却在于其命令模式，你将会发现，随着你对Vim的了解和熟练，你用插入模式的时间会越来越少。</p>
<h5>使用h, j, k, l</h5>
<p>为了有效的编辑文件，你首先应该做的就是戒掉那些个方向键 ←↓↑→，代以h, j, k, l，即左、下、上、右。这样的好处是很明显的，你的手不用再不停地在字母键和方向键之间来回挪动了，这会为你节省相当可观的时间，但或许你需要一定的时间来适应这种转变。<br />
在使用中你可能会遇到这样的文件，每一行(这里行以\n, \r标识)的文字都很长，以至于需要用视觉上的多行来显示，这时候使用j或者k会跳过若干行，以至于你不得不使用h或者l来在行内移动。当然，你可以不这么做，方法就是在j, k前面加g即可在视觉行间移动。</p>
<h5>使用motion在当前行内高效地移动</h5>
<p>　　许多其他的编辑器仅仅提供少量的命令来移动光标(左，上，右，下，行首/末等等)。Vim有很多强大的命令来高效地移动，它们被成为motion，motion都通常都有一个开始点(通常就是当前光标处)和一个目标点。下面列出一些有用的motion：</p>
<ul>
<li>fx ：向右移动至字母x在当前行内下一次出现的位置f指forward，x可以是任一个字母。你还可以用;来重复执行刚才的fx操作，这两个命令的结合是极其有用的。</li>
<li>tx ：同fx，区别在于光标会停留到x的右侧。</li>
<li>Fx ：同fx，只是向左移动。</li>
<li>w ：向右移动一个单词，光标停留在下一个单词的首字母，同样地，b向左移动。类似的还有一个命令e也是想右移动一个单词，只是光标会停留在单词的末尾。</li>
<li>0 ：移动到行首，注意：这是零而不是O！</li>
<li>$ ：移动到行末。</li>
<li>^ ：移动到当前行的第一个字符。</li>
<li>( ：移动到下一个句子。</li>
<li>) ：移动到上一个句子。注：这两个命令在编写代码是较少用到，但在编辑普通的文本文章时比较有用。</li>
<li>zz、z.、z-、zt：重画当前屏幕，使当前行显示在屏幕的中间、中间、底部、顶部，具体请:help cmd。</li>
</ul>
<h5>在整个文件域内高效地移动</h5>
<p>　　下面的一些命令可以让你在整个文件范围内移动，从而摆脱掉鼠标滚轮。</p>
<ul>
<li>&lt;C-f&gt; ：向下滚动一屏。</li>
<li>&lt;C-b&gt; ：向上滚动一屏。</li>
<li>G ：即&lt;S-g&gt;，移动到文件末尾。</li>
<li>nG ：移动到第n行。注：几乎所有可重复性操作都可以使用前缀数字执行n次。</li>
<li>gg ：移动到文件开头。</li>
<li>H ：移动到屏幕的最上方。</li>
<li>M ：移动到屏幕正中间。</li>
<li>L ：移动到屏幕最下方。</li>
<li>* ：这个命令比较强大，它记录当前光标处的单词，并移动到该单词下次出现的位置。</li>
<li># ：和*相同，但方向相反。</li>
<li>g* and g#：同上，但匹配包含当前单词的单词，而不是完全匹配。</li>
<li>/pattern ：向下查找模式pattern指定的字符串，pattern可以是一个正则表达式，当然也可以仅仅是一个单词。</li>
<li>?pattern ：同上，但方向相反。</li>
<li>mb ：在当前光标处设定一个书签bookmark，虽然你看不到，但它确实存在。注：此处b可以是任何一个字母或者数字。</li>
<li>`b ：即ESC下面的”反引号”，移动到一个已经设定的书签处b。注：是`而不是&#8217;，不过&#8217;也是可以的，但只能移动到书签b所在的行，你可以根据自己的需要来使用。</li>
<li>`. ：这个更牛叉，可以移动到你最近一次修改过的地方。</li>
</ul>
<h4>高效地输入</h4>
<h5>关键字自动补全</h5>
<p>　　Vim还有关键字自动补全的功能，这意味着：如果你已经定义了一个很长的变量，比如iAmALongLongVariableName，下次就不必在这个名字再完整地敲一遍，而只需要输入iAmA然后按下&lt;C-n&gt;，Vim就会为你自动补全这个变量名，如果前面不止一个类似的变量()那么Vim会弹出一个列表供你选择，在这个列表中你可以用&lt;C-p&gt;和&lt;C-n&gt;上下移动，空格会选择当前高亮的变量名。</p>
<h5>选择适当的进入插入模式的方法</h5>
<p>　　很多新手，总是先移动至指定位置，然后再用i进入到插入模式。这确实能够达到目的，但有时却并不合适。比如你现在在行末，需要在行首插入，如果一顿h或者聪明点的用nh或者nb，始终还是不够高效。下面有几个命令可供使用：</p>
<ul>
<li>i ：在当前光标左侧插入。</li>
<li>I(大小i) ：在行首插入。</li>
<li>a ：在当前光标右侧插入。</li>
<li>A ：在行末插入。</li>
<li>o ：在当前行下面新建一行并进入插入模式。</li>
<li>O ：同o，但在当前行的上面新建一行。</li>
<li>c{motion} ：删除和移动的复合，其中motion是上文中提到过的。比如cfx，会从当前光标处开始删除至字母x(不包括x)并进入插入模式。被删除的字符被保存到剪切板，可以被稍候粘贴到其他地方。</li>
<li>d{motion} ：同上，当并不进入插入模式。</li>
</ul>
<h4>高效地移动文本块</h4>
<h5>可视化选择</h5>
<p>　　不同于Vim的前身vi，Vim允许你高亮(即Visual可视化模式)某个文本块并对它执行某些操作。选择文本块的方式有三种：</p>
<ul>
<li>v 进入可视化模式，此时可以使用前面的移动命令在选取高亮区域。</li>
<li>V 进入行可视化模式，按行选择，即正行地选择。</li>
<li>&lt;C-V&gt; 这个很有特色，它可以允许你在文本的任意地方选出一块矩形区域！当然，前提是那里确实有字符，很少有编辑器有这个功能。</li>
</ul>
<p>　　按上述方法进入可视化模式后，你可以使用前面的移动命令在选取高亮区域，比如vwww会高亮接下来的三个单词，vjj会选择下面的两行，etc.</p>
<h5>剪切和复制</h5>
<ul>
<li>d ：剪切，即删除并放入剪切板。</li>
<li>y ：复制。</li>
<li>c ：同d，但还会进入插入模式。</li>
<li>d{motion} ：和c{motion}类似。</li>
<li>dd ：剪切当前行。</li>
<li>yy ：复制当前行。</li>
<li>cc ：修改当前行。</li>
<li>D ：剪切至行尾。</li>
<li>Y ：同yy。</li>
<li>C ：类似D。</li>
<li>x：剪切光标处字符。</li>
<li>s ：同x，但进入插入模式。</li>
<li>p ：粘贴。</li>
<li>n”+yy ：这个稍显复杂，它从当前行开始向下复制n行，但和nyy不同的是，文本会被复制到系统剪切板，而不是Vim的剪切板，这样你就能在其他程序比如浏览器中进行Ctrl+V。</li>
<li>”+p ：从系统剪切板粘贴。</li>
<li>d&#8217;a, y&#8217;a：剪切和复制从当前到书签a之间各行。</li>
<li>”+y&#8217;a：这个看起来有些复杂，它是前面几个命令的整合，和上一个命令功能相同，只是将当前行至书签a所在行复制到系统剪切板。</li>
<li>”+ynumG：从当前行一直复制到第num行，相比上面的，这个选择性更大一点。</li>
</ul>
<h4>减少重复性操作</h4>
<h5>使用.</h5>
<p>　　好吧，我为它单独开了一个章节，.功能实用使用简单，但使用频率却十分的高。一个.可以重复你刚刚执行过的编辑操作，比如删除、粘贴等。</p>
<h5>使用宏记录</h5>
<p>　　有时候，你会发现你自己在文章的每段或者每行都重复相同的一系列动作。VIM 允许你记录一个宏来完成你的特殊需要。</p>
<ul>
<li>qregister：记录宏到寄存器 register，这里 register 是任意的你的寄存器的名字。比如 qa，将会记录并且把宏存在寄存器 a 里面。</li>
<li>q：结束宏的记录。</li>
<li>@register：使用存在寄存器 register 的宏。比如 @a，将会使用存在寄存器 a 里面的宏。</li>
</ul>
<h4>写代码的时候</h4>
<p>　　VIM 是一个用来写代码的绝好编辑器，因为它有一些特性是专门为程序员而设计的。这里是一些常用的基本命令：</p>
<ul>
<li>]p：和 p 的功能差不多，但是它会自动调整被粘贴的文本的缩进去适应当前代码的位置。试一下！</li>
<li>%：匹配花括号、方括号、括号等。在一个括号的上面，然后按 %，鼠标就会出现在匹配的另外一半括号处。</li>
<li>[{：光标移动至当前块(block)起始处，即上文最近的一个{处。再次[{移动到当前块所在的块起始处。</li>
<li>]}：同上，移动至块末尾。</li>
<li>[/：用于注释块(comment block)中，移动至块起始。</li>
<li>]/：移动至注释块末尾。</li>
<li>»：缩进所有选择的代码</li>
<li>«：和上面类似，但是反缩进</li>
<li>gd：到达光标所在处函数或者变量的定义处。</li>
<li>&lt;C-]&gt;：同上。</li>
<li>&lt;C-o&gt;：返回&lt;C-]&gt;操作前的位置。操作前的位置</li>
</ul>
<h4>键绑定</h4>
<p>　　发挥你想象力的时候到了。如你所见，Vim本身已经提供了大量的命令供你调遣，但不是所有的命令或者命令组合都适合所有的人。为此，Vim同学给了你根据个人习惯绑定命令的自由。vimrc中的一个简单的map命令即可做到，譬如</p>

<div class="wp_codebox"><table><tr id="p212413"><td class="code" id="p2124code13"><pre class="vim" style="font-family:monospace;">“ <span style="color: #668080;">&lt;cr&gt;</span>标示回车<span style="color: #000000;">&#40;</span>Enter<span style="color: #000000;">&#41;</span>
<span style="color: #804040;">map</span> ,w <span style="color: #000000;">:</span>w<span style="color: #000000;">&lt;</span>cr<span style="color: #000000;">&gt;</span></pre></td></tr></table></div>

<p>　　列出常用的一些特殊按键的代号，</p>
<ul>
<li>&lt;cr>, &lt;Cr&gt;, or &lt;CR>：回车；</li>
<li>&lt;Space&gt;：空格；</li>
<li>&lt;Esc&gt;：Esc；</li>
<li>&lt;c-x&gt; or &lt;C-x&gt;：Ctrl + x；</li>
<li>&lt;a-x&gt;：Alt + x；</li>
<li>&lt;m-x&gt;：Meta + x；</li>
<li>&lt;Left&gt;, &lt;Right&gt;, &lt;Up&gt;, &lt;Down&gt;：方向键；</li>
<li>&lt;BS&gt;：Backspace；</li>
<li>&lt;F10&gt;：功能键F10;</li>
<li>&lt;cword&gt;：当前单词(类似a-b_c2)；</li>
<li>&lt;cWORD&gt;：当前单词(不含空白符的字符串)；</li>
<li>&lt;cfile&gt;：当前单词为名的文件；</li>
<li>&lt;Home&gt;：Home，不是所有键盘都有的；</li>
<li>Last but not the least, 所有的字母键都以</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/04/vim-basic/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>推荐两个Vim插件</title>
		<link>http://www.dutor.net/index.php/2010/01/vim-calendar-nerdtree/</link>
		<comments>http://www.dutor.net/index.php/2010/01/vim-calendar-nerdtree/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 17:06:14 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=1977</guid>
		<description><![CDATA[安装方法和其他插件一样，将NERDTree.vim文件放到.vim/puglin/下即可。用:NERDTree命令启动，建议映射成快捷键。该插件常用操作的一些命令如下：
<ol>
	<li>o 打开关闭文件或者目录</li>
	<li>t 在标签页中打开</li>
	<li>T 在后台标签页中打开</li>
	<li>! 执行此文件</li>
	<li>p 到上层目录</li>
	<li>P 到根目录</li>
	<li>K 到第一个节点</li>
	<li>J 到最后一个节点</li>
	<li>u 打开上层目录</li>
	<li>m 显示文件系统菜单（添加、删除、移动操作）</li>
	<li>? 帮助</li>
	<li>q 关闭</li>
</ol>
　　另外一个插件是Calendar，顾名思义，是用来显示一个“日历”，但它的功能不限于此，还可以提供类似日记的功能。喜欢的话，你可以用它来记录一些笔记、备忘什么的。安装即使用方法同其他插件类似，自己摸索吧！截图改天再上。]]></description>
			<content:encoded><![CDATA[<p>已经销声匿迹若干天了，冒个泡，顺便推荐两款非常受欢迎、非常使用的Vim插件：NERTree和Calendar。<br />
NERDTree是一个文件浏览器，方便同时对多个文件进行编辑，详细说明见<a href="http://www.vim.org/scripts/script.php?script_id=1658" target="_blank">官方页面</a>。看图：</p>
<div class="wp-caption aligncenter" style="width: 747px"><img title="Vim NERDTree" src="http://www.dutor.net/files/images/calendar.gif" alt="Vim NERDTree" width="737" height="512" /><p class="wp-caption-text">Vim NERDTree</p></div>
<p>安装方法和其他插件一样，将NERDTree.vim文件放到.vim/puglin/下即可。用:NERDTree命令启动，建议映射成快捷键。该插件常用操作的一些命令如下：</p>
<ol>
<li>o 打开关闭文件或者目录</li>
<li>t 在标签页中打开</li>
<li>T 在后台标签页中打开</li>
<li>! 执行此文件</li>
<li>p 到上层目录</li>
<li>P 到根目录</li>
<li>K 到第一个节点</li>
<li>J 到最后一个节点</li>
<li>u 打开上层目录</li>
<li>m 显示文件系统菜单（添加、删除、移动操作）</li>
<li>? 帮助</li>
<li>q 关闭</li>
</ol>
<p>　　另外一个插件是Calendar，顾名思义，是用来显示一个“日历”，但它的功能不限于此，还可以提供类似日记的功能。喜欢的话，你可以用它来记录一些笔记、备忘什么的。安装即使用方法同其他插件类似，自己摸索吧！截图改天再上。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/01/vim-calendar-nerdtree/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

