<?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; ToolKits</title>
	<atom:link href="http://www.dutor.net/index.php/category/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>Netcat</title>
		<link>http://www.dutor.net/index.php/2011/12/netcat/</link>
		<comments>http://www.dutor.net/index.php/2011/12/netcat/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 07:01:49 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[netcat]]></category>
		<category><![CDATA[命令]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2682</guid>
		<description><![CDATA[　　甚至可以可以使用nc建立文件的中转站。比如，从host1无法直连到host3，只能先连到host2再间接连到host3。如果想从host1向host3传输文件，可以在host2上面建立中转。每次直接传输是client/server还是server/client，都可以实现（当然，如果两台机器有防火墙相隔时，就另说了）：
<pre lang="bash" line="1">
dutor@host2 $ nc -l 5198 &#124; nc -l 5191
dutor@host2 $ # 使用 while true; do nc -l 5198 &#124; nc -l 5191; done 可以建立持久的'中转站'
dutor@host1 $ nc host2 5198 < stuff.tgz
dutor@host3 $ nc host2 5191 &#124; tar xzvf -
</pre>
　　nc是一个简单，强大，又可以信手拈来的工具，尽情发挥你的想象力吧。]]></description>
			<content:encoded><![CDATA[<p>　　买了把瑞士军刀，想起了这个玩意儿。<br />
　　netcat, cat的网络版，一个十分小巧但却功能强大的工具，构建于传输层（TCP/UDP）之上。<br />
　　可以作为客户端使用：</p>

<div class="wp_codebox"><table><tr id="p26821"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2682code1"><pre class="bash" style="font-family:monospace;">$ <span style="color: #666666; font-style: italic;"># HTTP</span>
$ <span style="color: #666666; font-style: italic;"># you could also use 'curl ifconfig.me' to view your external IP. see http://ifconfig.me</span>
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;GET /ip HTTP/1.0<span style="color: #000099; font-weight: bold;">\n</span>User-Agent: netcat<span style="color: #000099; font-weight: bold;">\n</span>HOST: ifconfig.me<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span>\
  nc ifconfig.me <span style="color: #000000;">80</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'/^[0-9]/p'</span>
106.187.43.43
$</pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p26822"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p2682code2"><pre class="bash" style="font-family:monospace;">~$ <span style="color: #666666; font-style: italic;"># FTP</span>
~$ nc dutor.net <span style="color: #000000;">21</span>
<span style="color: #000000;">220</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>vsFTPd 2.3.2<span style="color: #7a0874; font-weight: bold;">&#41;</span>
USER dutor
<span style="color: #000000;">331</span> Please specify the password.
PASS <span style="color: #000000; font-weight: bold;">******</span>
<span style="color: #000000;">230</span> Login successful.
^D
$</pre></td></tr></table></div>

<p>　　还可以监听某个端口，作为服务器使用：</p>

<div class="wp_codebox"><table><tr id="p26823"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2682code3"><pre class="bash" style="font-family:monospace;">~$ <span style="color: #7a0874; font-weight: bold;">echo</span> hi, dutor <span style="color: #000000; font-weight: bold;">|</span> nc <span style="color: #660033;">-l</span> dutor.net <span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">&amp;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">11015</span>
~$ nc dutor.net <span style="color: #000000;">8080</span>
hi, dutor
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>+  Done                    <span style="color: #7a0874; font-weight: bold;">echo</span> hi, dutor <span style="color: #000000; font-weight: bold;">|</span> nc <span style="color: #660033;">-l</span> dutor.net <span style="color: #000000;">8080</span>
~$</pre></td></tr></table></div>

<p>　　dutor同学用的最多的，还是使用nc来方便快捷的在各个主机之间传输文件，可以从client到server，也可以从server到client，只要明白，nc只是简单地将其标准输入传输到对端，将从对端接受到的内容输出到标准输出：</p>

<div class="wp_codebox"><table><tr id="p26824"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2682code4"><pre class="bash" style="font-family:monospace;">dutor<span style="color: #000000; font-weight: bold;">@</span>host1 $ <span style="color: #c20cb9; font-weight: bold;">tar</span> czvf stuff.tgz stuff<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> nc <span style="color: #660033;">-l</span> <span style="color: #000000;">8080</span> <span style="color: #000000; font-weight: bold;">&lt;</span> stuff.tgz
dutor<span style="color: #000000; font-weight: bold;">@</span>host2 $ nc host1 <span style="color: #000000;">8080</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf -</pre></td></tr></table></div>

<p>　　甚至可以可以使用nc建立文件的中转站。比如，从host1无法直连到host3，只能先连到host2再间接连到host3。如果想从host1向host3传输文件，可以在host2上面建立中转。每次直接传输是client/server还是server/client，都可以实现（当然，如果两台机器有防火墙相隔时，就另说了）：</p>

<div class="wp_codebox"><table><tr id="p26825"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2682code5"><pre class="bash" style="font-family:monospace;">dutor<span style="color: #000000; font-weight: bold;">@</span>host2 $ nc <span style="color: #660033;">-l</span> <span style="color: #000000;">5198</span> <span style="color: #000000; font-weight: bold;">|</span> nc <span style="color: #660033;">-l</span> <span style="color: #000000;">5191</span>
dutor<span style="color: #000000; font-weight: bold;">@</span>host2 $ <span style="color: #666666; font-style: italic;"># 使用 while true; do nc -l 5198 | nc -l 5191; done 可以建立持久的'中转站'</span>
dutor<span style="color: #000000; font-weight: bold;">@</span>host1 $ nc host2 <span style="color: #000000;">5198</span> <span style="color: #000000; font-weight: bold;">&lt;</span> stuff.tgz
dutor<span style="color: #000000; font-weight: bold;">@</span>host3 $ nc host2 <span style="color: #000000;">5191</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf -</pre></td></tr></table></div>

<p>　　nc是一个简单，强大，又可以信手拈来的工具，尽情发挥你的想象力吧。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/12/netcat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>调试基础：内存转储</title>
		<link>http://www.dutor.net/index.php/2011/10/debugging-essence-core-dump/</link>
		<comments>http://www.dutor.net/index.php/2011/10/debugging-essence-core-dump/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 14:19:12 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[GDB]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2645</guid>
		<description><![CDATA[　　core dump, 通常译作内存转储，core之所以译作内存，而不是核心，纯属“著名”的历史原因，因为早期的内存有一个叫磁芯（magnectic core）的东西。内存转储会在磁盘中产生一个文件，是某个进程在转储时刻的内存映像及寄存器等信息。内存转储通常发生在进程执行了有致命错误的指令时，常见的就是著了名的Segmentation fault，即段错误，而导致段错误的就是C/C++编程中经常发生的内存非法访问。内存转储操作由操作系统内核进行。当然，内存转储还可以是用户主动发起请求，内核执行转储。
　　内存转储对于程序调试是至关重要的。利用内存转储文件（core files）对程序进行调试是一种异步的静态调试，所谓异步是指异常发生与调试不是在同一时刻，所谓静态指的是core files保存的只是转储时刻进程的内存状态。比如，一个长期运行的服务程序，我们不知道哪里有bug，该bug何时被触发，这种情况下，利用异常发生时的转储文件就可以在一定程度上定位出异常发生的原因。另外，对于非致命性错误，比如死锁或者死循环，进程不会自动结束，通常内核也不会主动杀掉这种进程，这时用户就可以请求内核将该进程进行内存转储，以此来查看进程的运行状态（比如各进程的堆栈）。]]></description>
			<content:encoded><![CDATA[<p>　　core dump, 通常译作内存转储，core之所以译作内存，而不是核心，纯属“著名”的历史原因，因为早期的内存有一个叫磁芯（magnectic core）的东西。内存转储会在磁盘中产生一个文件，是某个进程在转储时刻的内存映像及寄存器等信息。内存转储通常发生在进程执行了有致命错误的指令时，常见的就是著了名的Segmentation fault，即段错误，而导致段错误的就是C/C++编程中经常发生的内存非法访问。内存转储操作由操作系统内核进行。当然，内存转储还可以是用户主动发起请求，内核执行转储。<br />
　　内存转储对于程序调试是至关重要的。利用内存转储文件（core files）对程序进行调试是一种异步的静态调试，所谓异步是指异常发生与调试不是在同一时刻，所谓静态指的是core files保存的只是转储时刻进程的内存状态。比如，一个长期运行的服务程序，我们不知道哪里有bug，该bug何时被触发，这种情况下，利用异常发生时的转储文件就可以在一定程度上定位出异常发生的原因。另外，对于非致命性错误，比如死锁或者死循环，进程不会自动结束，通常内核也不会主动杀掉这种进程，这时用户就可以请求内核将该进程进行内存转储，以此来查看进程的运行状态（比如各进程的堆栈）。</p>
<h4>使能/生成内核转储</h4>
<p>　　ulimit -c命令可以查看和控制转储文件允许的生成大小，如果你的程序发生了致命错误却没有被转储，很可能是该值被设为零了。ulimit -c CORESIZE可以将core files所允许的最大值设为CORESIZE，ulimit -c unlimited取消对core files大小的限制，内核为尽量多的转储进程的内存。<br />
　　异常发生时，内核会根据设定大小生成转储文件。手动生成转储文件有两种方法，使用gdb attach到目标进程执行generate-core-file(缩写为gcore)，但由于attach到进程会导致进程在较长时间内挂起，对某些程序（比如网络程序）会造成不必要的影响，这时使用随gdb一起发布的gcore命令就比较合适了，且更加方便。</p>

<div class="wp_codebox"><table><tr id="p26456"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2645code6"><pre class="bash" style="font-family:monospace;">$ pgrep <span style="color: #660033;">-l</span> foobar
<span style="color: #000000;">12345</span>    foobar
$ <span style="color: #c20cb9; font-weight: bold;">gdb</span>
<span style="color: #c20cb9; font-weight: bold;">gdb</span><span style="color: #000000; font-weight: bold;">&gt;</span> attach <span style="color: #000000;">12345</span>
<span style="color: #c20cb9; font-weight: bold;">gdb</span><span style="color: #000000; font-weight: bold;">&gt;</span> gcore</pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p26457"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2645code7"><pre class="bash" style="font-family:monospace;">$ gcore <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">pidof</span> foobar<span style="color: #000000; font-weight: bold;">`</span></pre></td></tr></table></div>

<h4>控制转储文件的路径和格式</h4>
<p>　　很多系统中转储文件的默认文件名就是core，这时很难确定它是由哪个进程生成的，且可能导致同目录下多个转储文件的相互覆盖。这时可以在/etc/sysctl.conf文件中定制core文件的格式，比如，</p>

<div class="wp_codebox"><table><tr id="p26458"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p2645code8"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sysctl.conf
kernel.core_uses_pid = <span style="color: #000000;">1</span>
$ sysctl <span style="color: #660033;">-p</span> <span style="color: #666666; font-style: italic;"># to take effect</span></pre></td></tr></table></div>

<p>　　将kernel.core_uses_pid设为1，core文件就会以core.PID的形式生成。更复杂的格式可以由kernel.core_pattern变量控制。比如，</p>

<div class="wp_codebox"><table><tr id="p26459"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2645code9"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sysctl.conf
kernel.core_pattern = <span style="color: #000000; font-weight: bold;">%</span>e-<span style="color: #000000; font-weight: bold;">%</span>p-<span style="color: #000000; font-weight: bold;">%</span>u-<span style="color: #000000; font-weight: bold;">%</span>t.core
kernel.core_uses_pid = <span style="color: #000000;">0</span>
$ sysctl <span style="color: #660033;">-p</span> <span style="color: #666666; font-style: italic;"># to take effect</span></pre></td></tr></table></div>

<p>　　这时生成的core文件就是EXECUTABLE-PID-UID-TIME.core的形式，将kernel.core_uses_pid设成0是为了将core文件末尾的pid去掉。kernel.core_pattern可以使用的格式字符如下，</p>
<table>
<th>格式符</th>
<th>说明</th>
<tr>
<td>%%</td>
<td>%</td>
</tr>
<tr>
<td>%p</td>
<td>pid</td>
</tr>
<tr>
<td>%u</td>
<td>uid</td>
</tr>
<tr>
<td>%g</td>
<td>gid</td>
</tr>
<tr>
<td>%s</td>
<td>引发core dump的信号编号</td>
</tr>
<tr>
<td>%t</td>
<td>转储时间</td>
</tr>
<tr>
<td>%h</td>
<td>主机名</td>
</tr>
<tr>
<td>%e</td>
<td>可执行文件名</td>
</tr>
<tr>
<td>%c</td>
<td>ulimit -c</td>
</tr>
</table>
<p>此外，kernel.core_pattern还可以加上路径前缀，用以使core文件转储到特定的目录。</p>
<h4>使用gdb调试内存转储文件</h4>
<p>　　使用gdb可以方便的查看转储文件，同时还需要进程的可执行文件（包含进程的虚拟地址空间），若想调试时能够查看源代码，　　编译可执行文件时需要加上-g调试选项，同时还要有源代码可用（注意：编译器的-g选项并没有把源代码包含到可执行文件中）。<br />
使用gdb调试转储文件的命令为</p>

<div class="wp_codebox"><table><tr id="p264510"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2645code10"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">gdb</span> EXECUTABLE <span style="color: #660033;">-c</span> COREFILE</pre></td></tr></table></div>

<p>或者</p>

<div class="wp_codebox"><table><tr id="p264511"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2645code11"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">gdb</span> EXECUTABLE COREFILE</pre></td></tr></table></div>

<p>或者</p>

<div class="wp_codebox"><table><tr id="p264512"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2645code12"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">gdb</span> EXECUTABLE
<span style="color: #c20cb9; font-weight: bold;">gdb</span><span style="color: #000000; font-weight: bold;">&gt;</span> core COREFILES</pre></td></tr></table></div>

<p>　　调试core file的具体方法属于gdb的使用问题，之前有一篇我学习gdb时写的<a href="http://www.dutor.net/index.php/2011/02/gdb-summary/" target="_blank">总结</a>，也画过一张<a href="http://www.dutor.net/files/GDB.png" target="_blank">思维导图</a>，仅供参考。<br />
　　另外，像前面说的，利用转储文件进行调试属于静态调试，gdb的很多命令是“无法使用”的，比如i proc mapping。当然更无法进行单步调试。<br />
　　另外，转储文件为ELF格式文件，可以使用objdump/readelf等工具查看，但相比动态库、可执行文件等其他ELF二进制文件，它包含的信息是有限的。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/10/debugging-essence-core-dump/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<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>15</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="p261113"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2611code13"><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="p261114"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2611code14"><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="p261115"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2611code15"><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="p261116"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2611code16"><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>使用iconv &amp; luit转换文本编码</title>
		<link>http://www.dutor.net/index.php/2011/05/iconv-luit/</link>
		<comments>http://www.dutor.net/index.php/2011/05/iconv-luit/#comments</comments>
		<pubDate>Thu, 05 May 2011 13:21:57 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[iconv]]></category>
		<category><![CDATA[luit]]></category>
		<category><![CDATA[命令]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2581</guid>
		<description><![CDATA[　　相信很多人经常遇到文件乱码，尤其是文本文件。如果你不是用编辑器打开一个二进制文件的话，这应该是一个编码问题，即文件的实际编码和编辑器查看该文件时所使用的编码不一致。这时候，咱们需要把文件的编码进行转化，或者修改使用该文件的程序采用的编码。后一种方法取决于咱们使用的具体的程序，无法一概而论。
　　这里介绍一个工具，iconv，使用它可以将一个输入文件从一种编码转换到另一种编码，同时将转化结果输出。iconv的-f选项指定源编码，-t选项指定目标编码，-o指定输出文件：
<pre lang="bash">
$ iconv -f coding1 -t coding2 file1 -o file2
</pre>
　　若file1省略，则使用标准输入；若-o选项省略，则使用标准输出。
　　例如，我想把所有GBK编码的.cue文件转化为utf8编码：
<pre lang="bash">
$ find . -name "*.cue" -exec iconv -f gbk -t utf8 {} -o {} \;
</pre>]]></description>
			<content:encoded><![CDATA[<p>　　相信很多人经常遇到文件乱码，尤其是文本文件。如果你不是用编辑器打开一个二进制文件的话，这应该是一个编码问题，即文件的实际编码和编辑器查看该文件时所使用的编码不一致。这时候，咱们需要把文件的编码进行转化，或者修改使用该文件的程序采用的编码。后一种方法取决于咱们使用的具体的程序，无法一概而论。<br />
　　这里介绍一个工具，iconv，使用它可以将一个输入文件从一种编码转换到另一种编码，同时将转化结果输出。iconv的-f选项指定源编码，-t选项指定目标编码，-o指定输出文件：</p>

<div class="wp_codebox"><table><tr id="p258117"><td class="code" id="p2581code17"><pre class="bash" style="font-family:monospace;">$ iconv <span style="color: #660033;">-f</span> coding1 <span style="color: #660033;">-t</span> coding2 file1 <span style="color: #660033;">-o</span> file2</pre></td></tr></table></div>

<p>　　若file1省略，则使用标准输入；若-o选项省略，则使用标准输出。<br />
　　例如，我想把所有GBK编码的.cue文件转化为utf8编码：</p>

<div class="wp_codebox"><table><tr id="p258118"><td class="code" id="p2581code18"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.cue&quot;</span> <span style="color: #660033;">-exec</span> iconv <span style="color: #660033;">-f</span> gbk <span style="color: #660033;">-t</span> utf8 <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #660033;">-o</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></td></tr></table></div>

<p>　　关于编码，还有一个比较实用的工具luit：</p>

<div class="wp_codebox"><table><tr id="p258119"><td class="code" id="p2581code19"><pre class="bash" style="font-family:monospace;">$ luit <span style="color: #660033;">-encoding</span> coding COMMAND</pre></td></tr></table></div>

<p>　　luit将COMMAND命令的输出按照coding编码解释，然后转化为本地系统的编码并输出。<br />
　　例如，各个BBS的telnet输出通常是GBK编码的，直接使用telnet连接可能会出现乱码。使用luit即可，</p>

<div class="wp_codebox"><table><tr id="p258120"><td class="code" id="p2581code20"><pre class="bash" style="font-family:monospace;">$ luit <span style="color: #660033;">-encoding</span> gbk telnet bbs.dlut.edu.cn</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/05/iconv-luit/feed/</wfw:commentRss>
		<slash:comments>1</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>我的conky配置</title>
		<link>http://www.dutor.net/index.php/2011/04/conky-conkyrc/</link>
		<comments>http://www.dutor.net/index.php/2011/04/conky-conkyrc/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 09:10:06 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[conky]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2555</guid>
		<description><![CDATA[　　conky是Linux/Unix环境下面的一个用于可视化地显示系统信息的小程序，它可以嵌入到桌面，实时地显示CPU、内存、磁盘、文件系统、网络、电源等的状况，还可以显示一些特定程序的状态，比如moc, audacious, mpd&#038;mpc等音乐播放器，甚至可以调用外部命令并将命令的输出显示出来。下面是我的conky截图，
<img src="http://www.dutor.net/wp-content/uploads/2011/04/conky.png" alt="conky" title="conky" width="200" height="340" class="size-full wp-image-2556" />]]></description>
			<content:encoded><![CDATA[<p>　　conky是Linux/Unix环境下面的一个用于可视化地显示系统信息的小程序，它可以嵌入到桌面，实时地显示CPU、内存、磁盘、文件系统、网络、电源等的状况，还可以显示一些特定程序的状态，比如moc, audacious, mpd&#038;mpc等音乐播放器，甚至可以调用外部命令并将命令的输出显示出来。下面是我的conky截图，<br />
<div id="attachment_2556" class="wp-caption aligncenter" style="width: 339px"><img src="http://www.dutor.net/wp-content/uploads/2011/04/conky.png" alt="conky" title="conky" width="329" height="544" class="size-full wp-image-2556" /><p class="wp-caption-text">conky screenshot</p></div><br />
　　下面简单解释下各部分的信息。<br />
　　最上面一行显示当前时间和日期，调用的是系统命令date，当然也可以使用conky提供的$time变量。<br />
　　第二行显示英文单词及其释义，由一个自定义脚本从一个单词列表中随机读取，里面是我平时积累的生词。<br />
　　接下来是系统信息，当前登录系统的用户、系统运行时间、处理器占用率及CPU温度、系统负载因子(Load Average)，CPU占用及磁盘I/O状况图，系统内存及使用状况，电源状况(状态，电池充电/放电剩余时间).<br />
　　然后分别是CPU和内存占用前三甲进程的相关信息。<br />
　　最后是MPD(Music Player Daemon)的状态。</p>
<p>　　我的conky更新频率为1Hz，生词更新频率0.2Hz. ^_^</p>
<p>　　在设置生词显示过程中，遇到一个小插曲。我的生词表以dot文件的方式放在$HOME下，随机读取生词的Shell脚本randword.sh放在$HOME下的.bin目录中，.bin目录在.bashrc中被附加到$PATH中。另外，conky在.config/openbox/autostart.sh脚本中启动，autostart.sh脚本在openbox启动时被执行。<br />
　　问题出现了，每次登入openbox，conky确实会被启动，但却没有生词被显示，但时间和日期是正确显示的。就是说date命令被执行了，但randword.sh却可能没被执行。经过我的描述，可能你已经发现问题的诱因了，但我却被生生搞了一个小时(>_<).<br />
　　我是这样找到原因的。生词不是没被显示嘛，于是我在bash中杀掉重启conky，生词就显示了。问题就出在$PATH环境变量的设置上面，$PATH在bashrc中设置，而bashrc只在交互性且非登录的bash启动时才被读取(see man bash)。所以，autostart.sh中执行conky命令时，$PATH并不是我们在bashrc设置中所期望的结果，randword.sh脚本也就无法找到，更无法被执行了。<br />
　　找到了原因，解决办法也就有了：以绝对路径调用randword.sh。然而，更好的方法可能是在.bash_profile文件中source一下.bashrc，因为bash_profile在交互性的登录shell或者非交互性带有--login选项的shell启动时被读取，详情请man bash.</p>
<p>　　最后奉上我的.conkyrc, 关于这份配置文件，如果你要使用的话，要注意，我使用的是consolas字体，你的系统可能没有，请在相应位置调整。显示生词，你很可能也没有相关文件和脚本。电源信息，你可能需要调整BAT1为BAT0或者其他。</p>
<pre>
# Use Xft? To let conky display Chinese, use xft!
use_xft yes
# Xft font when Xft is enabled
#xftfont wenquanyi bitmap song:size=10
xftfont Consolas:size=9
# Text alpha when using Xft
xftalpha 0.6
# Print everything to stdout?
# out_to_console no
#mail_spool $MAIL
# Update interval in seconds
update_interval 1.0
# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0
# Create own window instead of using desktop (required in nautilus)
# Set &#8220;no&#8221; to let conky transparent upon desktop.
own_window yes
# If own_window is yes, you may use type normal, desktop or override
own_window_type desktop
# Use pseudo transparency with own_window?
own_window_transparent yes
# If own_window_transparent is set to no, you can set the background colour here
#own_window_colour hotpink
# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes
# Minimum size of text area
minimum_size 100 3
maximum_width 308
# Draw shades?
draw_shades no
# Draw outlines?
draw_outline no
# Draw borders around text
draw_borders no
# Draw borders around graphs
draw_graph_borders no
# Stippled borders?
stippled_borders 8
# border width
border_width 1
# Default colors and also border colors
default_color white
default_shade_color black
default_outline_color black
# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right
#alignment none
# Gap between borders of screen and text
# same thing as passing -x at command line
gap_x 12
gap_y 12
# Subtract file system buffers from used memory?
no_buffers yes
# set to yes if you want all text to be in uppercase
uppercase no
# number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 2
# number of net samples to average
# set to 1 to disable averaging
net_avg_samples 2
# seemingly required for Chinese
override_utf8_locale yes
# Add spaces to keep things from moving about?  This only affects certain objects.
use_spacer none
# Allow each port monitor to track at most this many connections (if 0 or not set, default is 256)
#max_port_monitor_connections 256
# Maximum number of special things, e.g. fonts, offsets, aligns, etc.
#max_specials 512
# Maximum size of buffer for user text, i.e. below TEXT line.
#max_user_text 16384
# Timing interval for music player thread, e.g. mpd, audacious
#music_player_interval (update_interval is default)
# variable is given either in format $variable or in ${variable}. Latter
# allows characters right after the variable and must be used in network
# stuff because of an argument
# stuff after &#8216;TEXT&#8217; will be formatted on screen

TEXT
${color yellow}${exec date +&#8221;%T %a, %b/%d/%Y&#8221;}$color
${color #ee0000}${font wenquanyi bitmap song:size=10}${execi 5 /home/dutor/.bin/randword.sh}$font$color

${color green}System Info$color
   Usr:${color #0077ff} ${user_names}$alignr${color}Uptime:${color #0077ff} $uptime$color
   CPU:${color #0077ff} $cpu% ${acpitemp}°C$alignr${color}Load:${color #0077ff} ${loadavg}
   ${color #000000}${cpugraph 00ff00 aa0000 -t}$color
   $alignc${color}CPU Status
   ${color #000000}${diskiograph 00ff00 aa0000 -t}$color
   $alignc${color}Disk Status
   Memory:${color #0077ff} $memperc% $mem/4GB$color
   Battery:${color #0077ff} ${battery BAT1} ${battery_time BAT1} $color
#Battery Life:${color #cc2222} $apm_battery_time &#8211; $apm_battery_life $color

${color green}CPU Top 3$color
   Process$alignr PID    CPU%   MEM%   MEM
   ${color #0077ff}${top name 1}$alignr${top pid 1} ${top cpu 1} ${top mem 1} ${top mem_res 1}
   ${top name 2}$alignr${top pid 2} ${top cpu 2} ${top mem 2} ${top mem_res 2}
   ${top name 3}$alignr${top pid 3} ${top cpu 3} ${top mem 3} ${top mem_res 3}

${color green}Memory Top 3$color
   Process$alignr PID    CPU%   MEM%   MEM
   ${color #0077ff}${top_mem name 1}$alignr${top_mem pid 1} ${top_mem cpu 1} ${top_mem mem 1} ${top_mem mem_res 1}
   ${top_mem name 2}$alignr${top_mem pid 2} ${top_mem cpu 2} ${top_mem mem 2} ${top_mem mem_res 2}
   ${top_mem name 3}$alignr${top_mem pid 3} ${top_mem cpu 3} ${top_mem mem 3} ${top_mem mem_res 3}

${color green}Music Player Daemon$color
   Status:${color #0077ff} $mpd_status $alignr${color}Volume:${color #0077ff} $mpd_vol$color
   Artist:${color #0077ff} ${font wenquanyi bitmap song:size=10}$mpd_artist$color${font}
   Title:${color #0077ff} ${font wenquanyi bitmap song:size=10}$mpd_title$color${font}
   Process:${color #0077ff} $mpd_bar
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/04/conky-conkyrc/feed/</wfw:commentRss>
		<slash:comments>1</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="p251521"><td class="code" id="p2515code21"><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="p251522"><td class="code" id="p2515code22"><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>GDB调试实例两则</title>
		<link>http://www.dutor.net/index.php/2011/02/gdb-examples/</link>
		<comments>http://www.dutor.net/index.php/2011/02/gdb-examples/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 06:46:49 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[GDB]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2510</guid>
		<description><![CDATA[　　调试内存转储文件。内存转储文件（core dump）是程序发生严重错误时操作系统产生的文件，它包含了程序崩溃时占用的内存页面的拷贝，因此使用core文件在一定程度上可以再现崩溃前夕程序的状态。
　　多种原因下程序会崩溃，从而被系统终止，生成core文件，经常见到的是访存错误（段错误，Segment fault）。另外，系统是否生成core文件以及core文件的最大尺寸还受系统参数的控制。例如ubuntu下面普通用户程序是不允许生成core文件的，这可以使用ulimit命令来修改。不带参数的ulimit -c输出当前core文件的最大允许值，为了能够生成core文件，使用ulimit -c size设置大小，简单地，ulimit -c unlimited将其设为没有限制。
<pre lang="c" line="1">
void foo(const char* s)
{
    char c = *s;
}
int
main()
{
    foo(0);
    return 0;
}
</pre>]]></description>
			<content:encoded><![CDATA[<h4>普通调试</h4>

<div class="wp_codebox"><table><tr id="p251023"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p2510code23"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;unistd.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span>
main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> n <span style="color: #339933;">=</span> <span style="color: #208080;">0x3fc00000</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> n<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<pre>
$ cc main.c -g
main.c: In function ‘main’
main.c:9: warning: format ‘%f’ expects type ‘double’, but argument 2 has type ‘
$ gdb a.out
Reading symbols from /home/dutor/Wdir/Cpp/GDB/a.out...done.
(gdb) l
1	#include <stdio.h>
2	#include <stdlib.h>
3	#include <unistd.h>
4
5	int
6	main()
7	{
8	    int n = 0x3fc00000;
9	    printf("%f\n", n);
10	    return 0;
(gdb)
11	}
(gdb) start
Temporary breakpoint 1 at 0x80483cd: file main.c, line 8.
Starting program: /home/dutor/Wdir/Cpp/GDB/a.out

Temporary breakpoint 1, main () at main.c:8
8	    int n = 0x3fc00000;
(gdb) i program
	Using the running image of child process 7519.
Program stopped at 0x80483cd.
It stopped at a breakpoint that has since been deleted.
(gdb) n
9	    printf("%f\n", n);
(gdb) p/x n
$2 = 0x3fc00000
(gdb) p/f n
$3 = 1.5
(gdb) disassemble
Dump of assembler code for function main:
   0x080483c4 <+0>:	push   %ebp
   0x080483c5 <+1>:	mov    %esp,%ebp
   0x080483c7 <+3>:	and    $0xfffffff0,%esp
   0x080483ca <+6>:	sub    $0x20,%esp
   0x080483cd <+9>:	movl   $0x3fc00000,0x1c(%esp) # 为n赋值
=> 0x080483d5 <+17>:	mov    $0x80484c0,%eax # 格式字符串地址
   0x080483da <+22>:	mov    0x1c(%esp),%edx
   0x080483de <+26>:	mov    %edx,0x4(%esp) # printf参数入栈
   0x080483e2 <+30>:	mov    %eax,(%esp)
   0x080483e5 <+33>:	call   0x80482f4
<printf@plt>
   0x080483ea <+38>:	mov    $0x0,%eax
   0x080483ef <+43>:	leave
   0x080483f0 <+44>:	ret
End of assembler dump.
(gdb) si
0x080483da	9	    printf("%f\n", n);
(gdb) display /i $eip # 每次暂停都打印下一条指令
2: x/i $eip
=> 0x80483da <main+22>:	mov    0x1c(%esp),%edx
(gdb) x/s $eax
0x80484c0:	 "%f\n"
(gdb) si
0x080483de	9	    printf("%f\n", n);
2: x/i $eip
=> 0x80483de <main+26>:	mov    %edx,0x4(%esp)
(gdb)
0x080483e2	9	    printf("%f\n", n);
2: x/i $eip
=> 0x80483e2 <main+30>:	mov    %eax,(%esp)
(gdb)
0x080483e5	9	    printf("%f\n", n);
2: x/i $eip
=> 0x80483e5 <main+33>:	call   0x80482f4
<printf@plt>
(gdb) x/x $esp
0xbfffec30:	0x080484c0
(gdb) x/xw $esp+4
0xbfffec34:	0x3fc00000
(gdb) x/fw $esp+4
0xbfffec34:	1.5
(gdb) c
Continuing.
0.000000

Program exited normally.
(gdb) q
$
</pre>
<p>　　我们发现，传给printf的整数n的正是浮点数1.5的二进制形式（0x3fc00000参考IEEE 754浮点数标准），但为什么输出确实0.000000呢？同样的方法调试下面程序，</p>

<div class="wp_codebox"><table><tr id="p251024"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2510code24"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span>
main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color:#800080;">1.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>　　会发现这次传递给printf的是8字节的0x3fff 8000 0000 0000，是1.5的双精度表示！可见gcc中printf对格式字符串中的f是按双精度对待的（I&#8217;m wondering: how about a single float?）<br />
　　那么下面的程序的输出就应该是1.5了，你不妨试试</p>

<div class="wp_codebox"><table><tr id="p251025"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2510code25"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span>
main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #208080;">0x0</span><span style="color: #339933;">,</span> <span style="color: #208080;">0x3fff8000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>调试内存转储文件</h4>
<p>　　内存转储文件（core dump）是程序发生严重错误时操作系统产生的文件，它包含了程序崩溃时占用的内存页面的拷贝，因此使用core文件在一定程度上可以再现崩溃前夕程序的状态。<br />
　　多种原因下程序会崩溃，从而被系统终止，生成core文件，经常见到的是访存错误（段错误，Segment fault）。另外，系统是否生成core文件以及core文件的最大尺寸还受系统参数的控制。例如ubuntu下面普通用户程序是不允许生成core文件的，这可以使用ulimit命令来修改。不带参数的ulimit -c输出当前core文件的最大允许值，为了能够生成core文件，使用ulimit -c size设置大小，简单地，ulimit -c unlimited将其设为没有限制。</p>

<div class="wp_codebox"><table><tr id="p251026"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p2510code26"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> foo<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> s<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> c <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>s<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">int</span>
main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    foo<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>编译，执行，调试该程序，</p>
<pre>
$ ulimit
unlimited
$ cc main.c -g
$ ./a.out
Segmentation fault (core dumped) # 段错误，生成名为core的core文件
$ gdb a.out core
Reading symbols from /home/dutor/Wdir/Cpp/GDB/a.out...done.
[New Thread 11199]

warning: Can't read pathname for load map: Input/output error.
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault. # 程序终止原因
#0  0x0804839d in foo (s=0x0) at main.c:7 # 崩溃时程序执行到第7行foo函数。
7	    char c = *s;
(gdb) bt
#0  0x0804839d in foo (s=0x0) at main.c:7
#1  0x080483b7 in main () at main.c:12
(gdb) p /x s # 噢，s竟然是0！
$1 = 0x0
(gdb) q
$
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/02/gdb-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GDB使用小结</title>
		<link>http://www.dutor.net/index.php/2011/02/gdb-summary/</link>
		<comments>http://www.dutor.net/index.php/2011/02/gdb-summary/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 06:38:15 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[GDB]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2505</guid>
		<description><![CDATA[　　列位安好。简单总结下GDB调试器的使用。
<h4>准备</h4>
　　默认情况下，gcc/g++编译的可执行文件是不包含调试信息的，GDB是一个源代码级的调试器，使用GDB调试程序需要程序的源代码、符号及其对应的行号等，其中符号和行号可以是单独的文件，亦可以在编译时嵌入到可执行文件中。使用gcc/g++时使用-g选项即可将必要的调试信息包含到可执行文件中，使用-g3选项还可以将源代码中的宏信息也包含进去。
另外，调试过程中需要随时查看源代码，但源代码并没有包含到可执行文件中。通常GDB在当前目录查找源文件，但某些情况下（比如调试系统命令）需要手动指明源代码的查找目录，directory ~向GDB指明到$HOME下查找源文件。

<h4>启动</h4>
　　GDB的启动很灵活，它的各种特性，你可以在Shell下通过选项和参数指定，也可以在GDB启动之后在GDB自己的命令行下使用GDB内置的命令来指定。最常用的是直接使用命令gdb PROGRAM启动，这样gdb自动加载符号表等调试信息。若要向被调试程序传递参数，可以采用gdb --args program ARG1 ARG2的形式，其中--args(或者-args)是必须的，它告诉GDB该选项之后已经没有GDB需要的选项了。另外，还可以直接使用gdb启动，然后使用file program加载调试信息。此时若要设置被调试程序的参数，可以使用set命令的args子命令，如set args ARG1 ARG2. 还有一种传递参数的方法，在下面介绍。]]></description>
			<content:encoded><![CDATA[<p>　　列位安好。简单总结下GDB调试器的使用。</p>
<h4>准备</h4>
<p>　　默认情况下，gcc/g++编译的可执行文件是不包含调试信息的，GDB是一个源代码级的调试器，使用GDB调试程序需要程序的源代码、符号及其对应的行号等，其中符号和行号可以是单独的文件，亦可以在编译时嵌入到可执行文件中。使用gcc/g++时使用-g选项即可将必要的调试信息包含到可执行文件中，使用-g3选项还可以将源代码中的宏信息也包含进去。<br />
另外，调试过程中需要随时查看源代码，但源代码并没有包含到可执行文件中。通常GDB在当前目录查找源文件，但某些情况下（比如调试系统命令）需要手动指明源代码的查找目录，directory ~向GDB指明到$HOME下查找源文件。</p>
<h4>启动</h4>
<p>　　GDB的启动很灵活，它的各种特性，你可以在Shell下通过选项和参数指定，也可以在GDB启动之后在GDB自己的命令行下使用GDB内置的命令来指定。最常用的是直接使用命令gdb PROGRAM启动，这样gdb自动加载符号表等调试信息。若要向被调试程序传递参数，可以采用gdb &#8211;args program ARG1 ARG2的形式，其中&#8211;args(或者-args)是必须的，它告诉GDB该选项之后已经没有GDB需要的选项了。另外，还可以直接使用gdb启动，然后使用file program加载调试信息。此时若要设置被调试程序的参数，可以使用set命令的args子命令，如set args ARG1 ARG2. 还有一种传递参数的方法，在下面介绍。</p>
<h4>断点</h4>
<p>　　调试程序，就是使用调试器（Debugger）通过检测和改变被调试程序（Debuggee）的状态、控制其执行的方式找出被调试程序中的错误和潜在的bug。调试程序，观察程序当前的行为的前提是让程序在“适当的时候”暂停运，那么什么是适当的时候呢？使用GDB时，让程序暂停运行需要使用断点。具体地，断点又可以分为普通断点（breakpoint以下简称断点），观察点（watchpoint），捕捉点（watchpoint）三类。<br />
　　普通断点使用break命令（简写为b）设置。break命令的格式为break [bp-spec] [if CONDITION] [thread THREADNUM]，bp-spec指明断点设置的位置，可以是行号、函数名或者指令地址，如果bp-spec省略，则断点被设置在程序所要执行的下一行代码（或者指令）上。if CONDITION指明当程序到达bp-spec位置时，只有CONDITION条件成立时程序才会暂停。thread THREADNUM用在多线程程序的调试中，断点只被设置在指定的线程号（GDB内部而不是系统使用的标号）为THREADNUM的线程上，如果THREADNUM为all则所有线程都会被设置断点。补充下bp-spec可以是函数名b FUNCTIONNAME(重载函数名需要使用&#8221;包含才能自动补全)，可以是行号b LINENUMBER或者b FILENAME:LINENUMBER，还可以是指令地址b *ADDRESS。另外，break命令还有其它一些变种，比如tbreak设置临时断点，被使用一次就会自动删除，rbreak使用正则表达式来指明函数名。<br />
　　观察点使用watch命令，命令格式与break相同，但它并不是指明断点的位置，而是指明一个表达式，每当该表达式的值改变时，程序便会被暂停。表达式可以是某个变量、由若干变量组成的表达式或者内存地址。<br />
　　捕捉点是另一种断点，它使用某种事件的发生作为触发条件，命令各式为catch EVENT。这些事件主要包括异常的抛出和捕获（catch throw/catch）和某个系统调用（catch fork/open/exec, catch syscall CALLNUM）。<br />
　　查看当前的断点设置情况可以使用breakpoints，也可以使用info breakpoints（或者简写为i b）命令，查看某个断点使用breakpoints bpnum，bpnum为断点号。<br />
　　使用enable/disable bpnum使某个断点生效和失效，delete bpnum删除断点。bpnum还可以是一个范围，以此批量操作断点，比如d 2-6删除断点2到6。<br />
　　使用ignore bpnum COUNT还可以使某个断点被或略COUNT次，即是说断点bpnum的前COUNT次到达都不会被触发，知道COUNT递减至0。另外，在COUNT递减至0之前，该断点上的条件是不会被考虑的。<br />
　　CONDITION bpnum [if condition]，修改bpnum上的触发条件，若if被省略，则bpnum断点上的条件将被删除。</p>
<h4>运行</h4>
<p>　　GDB启动和加载调试信息后，被调试程序并没有运行。使用run/r或者start命令，GDB建立子进程来运行被调试程序。run和start命令稍有不同，即run仅仅加载程序然后运行，而start会在程序的入口函数（main）设置一个临时断点，程序运行到那里就会暂停，临时断点也随即被清除。另外run和start命令后面都可以加上传递给被调试程序的参数，若不加参数则使用GDB启动时传递的参数或者使用set args命令设置的参数。若要清除参数而不退出GDB，使用不带参数的set args即可。<br />
其它运行相关的命令还有</p>
<ul>
<li>continue/c，继续运行。</li>
<li>next/n, 下一行，且不进入函数调用</li>
<li>stop/s, 下一行，但进入函数调用</li>
<li>ni或者si, 下一条指令，ni与si的区别同n与s的区别</li>
<li>finish/fini, 继续运行至当前栈帧/函数刚刚退出</li>
<li>until/u, 继续运行至某一行，在循环中时，u可以实现运行至循环刚刚退出，但这取决于循环的实现。</li>
</ul>
<h4>查看</h4>
<p>　　调试的主要工作，我想就是检查程序的状态吧，内存的状态，程序的流程，指令的安排。GDB有多个命令来查看程序的状态，最常用的是list/l, print/p和x和disassemble。</p>
<ul>
<li>list linenum/function列出第linenum行或者function所在行附近的10行，list *address列出地址address附近的10行。</li>
<li>list列出上一次list命令列出的代码后面的10行</li>
<li>list -，列出上一次list命令列出的代码前的10行</li>
<li>list列出的默认行数可由set listsize size来设置</li>
<li>p /fmt VARIABLE根据fmt指定的格式打印变量VARIABLE的值，常用的fmt有d(decimal), u(unsigned), x(hex), o(octal), c(character), f(float), s(string)</li>
<li>x /nfs ADDRESS是我最喜欢的命令，它显示ADDRESS地址开始的内容，形式由nfs指定。其中n为次数（个数），f是格式，除p命令可以使用的格式外，还可以使用i(instruction)打印指令，s为所打印内容的大小，可以是b(byte), h(half word), w(word, 4bytes), g(8bytes). nfs均可省略，若省略则使用最近一次使用x命令时的值，最初nfs是1dw。</li>
<li>disassemble /[r][m] [ADDRESS]将ADDRESS所在函数进行反汇编，ADDRESS也可以是一个由行号组成的区间。不指定任何选项时disas只简单的列出反汇编指令，指定m(mixed)选项时会对应地列出指令和源代码，指定r(raw)时会打印出指令对应的十六进制编码。</li>
</ul>
<h4>退出</h4>
<p>　　Ctrl-C会终止当前调试的程序（而不是调试器）。q(quit)退出GDB，若退出时被调试程序尚未结束，GDB会提示，请求确认。</p>
<h4>其它</h4>
<h5>help</h5>
<p>　　使用GDB的过程中，如果对某一个命令的用法不清楚，可以随时使用help/h寻求帮助。</p>
<h5>info</h5>
<p>　　info/i命令也是一个十分常用的GDB命令，可以查看许多信息。</p>
<ul>
<li>i program查看被调试程序的运行状态，如进程号、ip（指令指针）、是否运行、停止原因等。</li>
<li>i b [bpnum]查看断点</li>
<li>i f [frame-num]查看当前（或指定）栈帧，i f all还会列出当前栈帧的局部变量</li>
<li>i line LINENUM查看代码行LINENUM，打印其指令地址，此命令后执行x/i可查看该地址处的指令，然后回车即可继续向后查看接下来的指令</li>
<li>i reg查看寄存器状态，i all-reg查看包含浮点堆栈寄存器在内的所有寄存器情况</li>
<li>i args查看当前栈帧的参数</li>
<li>i s追踪栈帧信息，相当于backtrace/bt命令</li>
<li>i threads查看当前进程的线程信息</li>
</ul>
<h5>回到过去</h5>
<p>　　跟踪调试程序的过程中，偶尔会错过一些关键点，不得不重新启动程序。如果错过的这些关键点不容易再现，就更令人懊恼了。GDB提供一种机制可以让你将程序向后调整，重新来过。这种机制叫做checkpoint，你可以在程序运行的关键点处执行checkpoint命令，你将得到一个数字（check-num）来标识这个checkpoint。在以后的某个时刻使用restart check-num将程序回滚到设置该checkpoint的时刻，而此时此刻的“内存状态”恰如彼时彼刻，你可以重新调试这段程序（比如设置不同的变量值来测试不同的情况）。但覆水难收的道理你是懂得，回滚的这段程序之间产生的内存之外的效应是无法恢复的，比如写出到文件的数据收不回来了（但文件的指针偏移是可以恢复的，因为它的值保存在内存），通过网络发出的数据就更要不回来了。<br />
　　使用i checkpoints可以查看checkpoint信息，比如check-num及其所处代码行。<br />
 　　据我揣测，GDB的这种“回到过去”的伎俩并不是逐步撤销之前运行的指令，而是在checkpoint命令执行的时候，把被调试程序fork/clone了。</p>
<h5>多线程</h5>
<p>　　调试多线程程序与普通程序没有太大的区别。</p>
<ul>
<li>i threads查看当前进程包含的线程的信息，包括线程号及其GDB内部标识号，当前处于前端的线程。</li>
<li>thread thread-num切换到线程thread-num</li>
<li>set scheduler-locking [on|off|step]，这是一个比较重要的选项，它控制这当前调试线程与其它线程的执行关系。设置为on时，其它线程不会抢占当前线程。设置为off（默认）时，当前线程执行时随时可能被其它线程抢占。设置为step时，在执行step命令时不会被抢占，但使用next跳过函数调用时可以/可能会被抢占，即调度器会被执行。</li>
</ul>
<h5>技巧</h5>
<p>　　回车。在GDB命令行下，简单的回车会执行上一个命令。而且GDB命令中可以使用回车重复执行的都是有记忆的，如果使用回车，该命令就会根据上一次的执行适当地调整参数重复执行。比如使用l func列出函数func附近的10行代码，接着回车就会打印接下来的10行。使用x/16xw ADDRESS以16进制形式查看ADDRESS处的16个字，接着回车就会以同样的格式打印接下来的16个字。如果你已经set $i=0了，那么通过p a[$i++]然后一直回车就可以依次打印数组a的元素了。x/i $eip打印下一条指令，接着回车就会打印下下一条指令，以此类推。但，有的指令是无法使用回车来重复执行的，比如run/start，总之，通常，你觉得不能/不适合重复执行的命令就无法重复执行。<br />
　　命令简写，有的命令名称较长甚至很长，但GDB允许用户只使用足以区别其它命令的前几个字符来执行命令，当然你也可以使用TAB自动补全。另外一些极为常用的命令有专门的简写形式，通常只有一个字母，例如break/b, list/l, info/i, continue/c, next/n, step/s, nexti/ni, stepi/si, frame/f, print/p等等等等。<br />
　　在GDB中可以自定义变量（仅供GDB内部使用），很多时候可以方便查看一些表达式的值。有的时候使用变量似乎是必须的，比如x *($esp)是不合法的，因为GDB不允许对寄存器变量进行解引用（dereference, but why?）。这时，设置变量set $p=*($esp)，然后x $p就可以了。</p>
<p>　　这只是一个小小的不完全的总结，如果你从未使用过GDB，推荐使用RMS的《Debugging with GDB》学习，还有一本小书《GDB Pocket Reference》，不妨做你的调试菜谱，如果你喜欢GDB的话。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2011/02/gdb-summary/feed/</wfw:commentRss>
		<slash:comments>3</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>利用xclip访问X剪切板</title>
		<link>http://www.dutor.net/index.php/2010/10/toolkits-xclip-x-clipboard/</link>
		<comments>http://www.dutor.net/index.php/2010/10/toolkits-xclip-x-clipboard/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 16:11:58 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[xclip]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2458</guid>
		<description><![CDATA[　　想必您经常使用复制粘贴功能吧，如果你在桌面环境下工作的话。那么您对Ctrl + C与Ctrl + V一定很熟悉了，您可能还经常使用中指按下鼠标的中键来快捷的粘贴。在X中，此两种粘贴方式是有区别的。Ctrl + V之前要有选中和相应的Ctrl + C，而中键之前只需要选中即可，前者使用的是剪切板（Clipboard），后者使用的是选中（Primary Selection）。关于两者细微的区别<a href="http://www.jwz.org/doc/x-cut-and-paste.html" target="_blank">见这里</a>。
　　下面要介绍的是一个能够在命令行访问剪切板（或者Selection，下面以“剪切板”概而论之）的工具。你可能知道，所谓剪切板以及复制粘贴这些功能都是X提供的，而不是Linux内核本身。因此，在命令终端访问剪切板就显得不那么简单，不那么显而易见了。
<pre lang="bash" line="1">
#! /bin/bash
content=`xclip -o`
echo $content >> ～/.wordump.txt
exit 0
</pre>]]></description>
			<content:encoded><![CDATA[<p>　　想必您经常使用复制粘贴功能吧，如果你在桌面环境下工作的话。那么您对Ctrl + C与Ctrl + V一定很熟悉了，您可能还经常使用中指按下鼠标的中键来快捷的粘贴。在X中，此两种粘贴方式是有区别的。Ctrl + V之前要有选中和相应的Ctrl + C，而中键之前只需要选中即可，前者使用的是剪切板（Clipboard），后者使用的是选中（Primary Selection）。关于两者细微的区别<a href="http://www.jwz.org/doc/x-cut-and-paste.html" target="_blank">见这里</a>。<br />
　　下面要介绍的是一个能够在命令行访问剪切板（或者Selection，下面以“剪切板”概而论之）的工具。你可能知道，所谓剪切板以及复制粘贴这些功能都是X提供的，而不是Linux内核本身。因此，在命令终端访问剪切板就显得不那么简单，不那么显而易见了。<br />
　　而xclip这个程序提供了这样的功能。它既能够从标准输入或者文件中读取内容放入剪切板，也能够将剪切板的内容输出到标准输出。例如下面命令将dutor放入剪切板，</p>

<div class="wp_codebox"><table><tr id="p245827"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2458code27"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dutor&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> xclip</pre></td></tr></table></div>

<p>　　此时你就可以使用鼠标中键将dutor粘贴到需要的地方了。但不能使用Ctrl + V，原因见上面的链接。为了能够使用Ctrl + V，应该为xclip的selection选项指定参数为clipboard（默认为primary），</p>

<div class="wp_codebox"><table><tr id="p245828"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2458code28"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dutor&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> xclip <span style="color: #660033;">-selection</span> clipboard</pre></td></tr></table></div>

<p>　　鉴于本人经常遇到一些不认识的单词，想要积累但记性又差，于是就想把这些偶遇的单词保存下来，待到积累到一定量后集中记忆和复记（好记性还不如烂笔头呢！）。于是，有了下面这个极为简单的脚本，</p>

<div class="wp_codebox"><table><tr id="p245829"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p2458code29"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #007800;">content</span>=<span style="color: #000000; font-weight: bold;">`</span>xclip -o<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$content</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ～<span style="color: #000000; font-weight: bold;">/</span>.wordump.txt
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></td></tr></table></div>

<p>　　利用<a href="http://www.dutor.net/index.php/2010/10/toolkits-xbindkeys/" target="_blank">上一篇介绍的xbindkeys</a>，我就可以很方便地倾倒我的生词啦！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/10/toolkits-xclip-x-clipboard/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>使用xbindkeys进行全局键绑定</title>
		<link>http://www.dutor.net/index.php/2010/10/toolkits-xbindkeys/</link>
		<comments>http://www.dutor.net/index.php/2010/10/toolkits-xbindkeys/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 15:18:31 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[xbindkeys]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2454</guid>
		<description><![CDATA[　　<a href="http://www.nongnu.org/xbindkeys/xbindkeys.html" target="_blank">xbindkeys</a>是一个可以全局按键绑定的程序，使用它，你可以方便用自定义的快捷键序列，来启动常用的程序。而且，xbindkeys独立与桌面环境，无论是gnome, KDE还是xfce，都可以使用同一个xbindkeys配置。、
　　xbindkeys最新版本是v1.8.3，而ubuntu10.04的源中还是v1.8.2，较旧的版本在修改配置文件后“立即生效”上有bug，最新版本已经修复。
　　安装好xbindkeys后，使用下面命令生成默认的配置文件，
<pre lang="bash" line="1">
$ xbindkeys --default > ~/.xbindkeysrc
</pre>
　　生成的配置文件的格式大致是这样的：]]></description>
			<content:encoded><![CDATA[<p>　　<a href="http://www.nongnu.org/xbindkeys/xbindkeys.html" target="_blank">xbindkeys</a>是一个可以全局按键绑定的程序，使用它，你可以方便用自定义的快捷键序列，来启动常用的程序。而且，xbindkeys独立与桌面环境，无论是gnome, KDE还是xfce，都可以使用同一个xbindkeys配置。、<br />
　　xbindkeys最新版本是v1.8.3，而ubuntu10.04的源中还是v1.8.2，较旧的版本在修改配置文件后“立即生效”上有bug，最新版本已经修复。<br />
　　安装好xbindkeys后，使用下面命令生成默认的配置文件，</p>

<div class="wp_codebox"><table><tr id="p245430"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2454code30"><pre class="bash" style="font-family:monospace;">$ xbindkeys <span style="color: #660033;">--default</span> <span style="color: #000000; font-weight: bold;">&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.xbindkeysrc</pre></td></tr></table></div>

<p>　　生成的配置文件的格式大致是这样的：</p>
<pre>
## Ctrl + F1
"urxvt"
 m:0x14 + c:67

## Control + F2 chrome
"google-chrome"
m:0x14 + c:68
</pre>
<p>　　#开始的为注释行，引号中是要执行的命令，那串诡异的字符就是对应的按键序列。<br />
　　为了定制xbindkeys的配置文件，运行以下命令，</p>

<div class="wp_codebox"><table><tr id="p245431"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2454code31"><pre class="bash" style="font-family:monospace;">$ xbindkeys <span style="color: #660033;">-k</span> <span style="color: #666666; font-style: italic;"># 单键</span>
$ xbindkeys <span style="color: #660033;">-mk</span> <span style="color: #666666; font-style: italic;"># 组合键</span></pre></td></tr></table></div>

<p>运行上面的命令后按下想要设定的按键，将生成的字符序列拷贝到~/.xbindkeysrc中即可。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/10/toolkits-xbindkeys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gow &#8211; 轻量级的Cygwin</title>
		<link>http://www.dutor.net/index.php/2010/08/gow-cygwin/</link>
		<comments>http://www.dutor.net/index.php/2010/08/gow-cygwin/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 12:38:56 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[命令]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2382</guid>
		<description><![CDATA[　　现在再推荐一个类似的工具集<a href="http://wiki.github.com/bmatzelle/gow/" target="_blank">Gow</a>(GNU On Windows). 这是一个轻量级的Cygwin“替代品”，集成了<a href="http://wiki.github.com/bmatzelle/gow/executables_list" target="_blank">130个Linux命令</a>，可以由Windows Installer方便地安装，自动设定环境变量。同时，自动为Windows Explorer的右键菜单添加一个“open in cmd prompt”的菜单项。里面有特色的工具主要有：
<ul>
	<li>脚本解释器：bash, zsh ；</li>
	<li>归档、压缩工具：tar, gzip, bzip2等；</li>
	<li>putty工具集： putty, psftp, pscp, plink等；</li>
	<li>下载工具：cURL, wget；</li>
	<li>编辑器：Vim；</li>
	<li>文本搜索/查看工具：grep, cat, less, head, tail等；</li>
	<li>文件（系统）相关工具：mv, cp, ls, rm, pwd等；</li>
</ul>
　　另外，你可能注意到，Gow中并没有gcc(GNU Compiler Collections)，所以，如果你需要这些工具，你可能还需要安装上面的cygnus。需要注意的是，这两个工具集的命令有交集，所以同时安装这两个工具集时要注意PATH中搜索路径的顺序，我更倾向于把Gow的bin放在前面。
　　最后，如果你系统中已经装有Vim（通常为较高的版本），最好把Gow中提供的Vim（貌似是6.3）删除。]]></description>
			<content:encoded><![CDATA[<p>　　Windows命令行太弱，工具太少，Linux Users难免会水土不服。<br />
　　一般的应用，Cygwin有点过于臃肿了，网络状况较差时候安装更是费劲。<br />
　　以前介绍过一个<a href="http://www.claremontmckenna.edu/math/ALee/g++/g++.html" target="_blank">工具集Cygnus</a>，包含不少Linux命令的Win32实现，应用重点在gcc(GNU Compiler Collections).<br />
　　<br />
　　现在再推荐一个类似的工具集<a href="http://wiki.github.com/bmatzelle/gow/" target="_blank">Gow</a>(GNU On Windows). 这是一个轻量级的Cygwin“替代品”，集成了<a href="http://wiki.github.com/bmatzelle/gow/executables_list" target="_blank">130个Linux命令</a>，可以由Windows Installer方便地安装，自动设定环境变量。同时，自动为Windows Explorer的右键菜单添加一个“open in cmd prompt”的菜单项。里面有特色的工具主要有：</p>
<ul>
<li>脚本解释器：bash, zsh ；</li>
<li>归档、压缩工具：tar, gzip, bzip2等；</li>
<li>putty工具集： putty, psftp, pscp, plink等；</li>
<li>下载工具：cURL, wget；</li>
<li>编辑器：Vim；</li>
<li>文本搜索/查看工具：grep, cat, less, head, tail等；</li>
<li>文件（系统）相关工具：mv, cp, ls, rm, pwd等；</li>
</ul>
<p>　　另外，你可能注意到，Gow中并没有gcc(GNU Compiler Collections)，所以，如果你需要这些工具，你可能还需要安装上面的cygnus。需要注意的是，这两个工具集的命令有交集，所以同时安装这两个工具集时要注意PATH中搜索路径的顺序，我更倾向于把Gow的bin放在前面。<br />
　　最后，如果你系统中已经装有Vim（通常为较高的版本），最好把Gow中提供的Vim（貌似是6.3）删除。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/08/gow-cygwin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress图片验证码插件</title>
		<link>http://www.dutor.net/index.php/2010/08/wordpress-plugin-image-verify/</link>
		<comments>http://www.dutor.net/index.php/2010/08/wordpress-plugin-image-verify/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 16:24:32 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2376</guid>
		<description><![CDATA[　　这款插件叫Mumbless，思路来源于我以前使用的插件block-spam-by-math。刚刚写好，可能还不太完善，但以最近一周的使用来看，还未出现自动的垃圾留言，或许因为小众吧。如果你需要，可以点击此处下载<a href="http://www.dutor.net/files/Mumbless.zip">Mumbless.zip</a>。安装方法同其它插件。
　　为了更有效地利用这款小插件，这里提供些建议：
<ul>
	<li>Mumless.php文件中Mumbless类中的add_check_form函数中的keywords数组包含了候选的验证码，你可以根据自己的喜好增删改；</li>

	<li>验证码输入框可能会影响原有表单的tabindex顺序，你可以根据需要调整；</li>

	<li>验证码图片的大小、样式在keyimg.php文件中定义，必要时你也可以对某些参数进行修改。</li>

</ul>

　　希望这个插件能为你节省些许删除垃圾评论的时间。]]></description>
			<content:encoded><![CDATA[<p>　　写了一个WordPress的插件，可以在文章评论、登录表单中加入验证功能，验证码以图片形式呈现。验证码本来是为阻止那些垃圾评论程序（Spambot）而设定的，但却给读者带来了不必要的麻烦。为了娱乐我的读者，这里的验证码主要是一些随机显示的标C/C++关键字、Linux/Unix命令、系统调用、配置文件名等，通常，您一眼就能看出验证码是什么，但Spambot可就费劲了。<br />
　　这款插件叫Mumbless，思路来源于我以前使用的插件block-spam-by-math。刚刚写好，可能还不太完善，但以最近一周的使用来看，还未出现自动的垃圾留言，或许因为小众吧。如果你需要，可以点击此处下载<a href="http://www.dutor.net/files/Mumbless.zip">Mumbless.zip</a>。安装方法同其它插件。<br />
　　为了更有效地利用这款小插件，这里提供些建议：</p>
<ul>
<li>Mumless.php文件中Mumbless类中的add_check_form函数中的keywords数组包含了候选的验证码，你可以根据自己的喜好增删改；</li>
<li>验证码输入框可能会影响原有表单的tabindex顺序，你可以根据需要调整；</li>
<li>验证码图片的大小、样式在keyimg.php文件中定义，必要时你也可以对某些参数进行修改。</li>
</ul>
<p>　　希望这个插件能为你节省些许删除垃圾评论的时间。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/08/wordpress-plugin-image-verify/feed/</wfw:commentRss>
		<slash:comments>2</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="p230932"><td class="code" id="p2309code32"><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="p230933"><td class="code" id="p2309code33"><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="p229634"><td class="code" id="p2296code34"><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>[命令技巧]screen</title>
		<link>http://www.dutor.net/index.php/2010/05/cmd-screen/</link>
		<comments>http://www.dutor.net/index.php/2010/05/cmd-screen/#comments</comments>
		<pubDate>Sat, 22 May 2010 00:37:39 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[命令]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2290</guid>
		<description><![CDATA[　　如果Linux用的比较多的话，你一定遇到过下面的场景。在终端启动了一个任务，这个比较耗时（比如cp, make, apt-get, wget），而此时你又需要在终端下做其它工作。你该如何是好？Ctrl + Alt + F1至F5，再开一个终端？gnome-terminator里面再开一个Tab？再启动一个rxvt？再做一次ssh连接？噢，当然，你还可以Ctrl + C，把那个耗时的进程杀掉。但这都不是一个好的解决之道，相对于使用screen来说。
<h4>screen的工作原理</h4>
　　使用screen，你可以在同一个终端，同一个virtual terminator，同一个ssh中同时进行多个工作。它的大致工作原理是：当前shell中启动screen，此时screen是当前shell的一个子进程，而你现在处于screen的一个会话（session）的一个window中。这个window对应着一个shell进程（比如bash），当你陷入上面的场景时，screen可以让你再开一个（或多个）window，这个window又会对应一个新的shell进程。当然，这些window都在screen的大力监管之下，你可以在这些window之间自由切换。下面两图可能更能说清真象。]]></description>
			<content:encoded><![CDATA[<p>　　如果Linux用的比较多的话，你一定遇到过下面的场景。在终端启动了一个任务，这个比较耗时（比如cp, make, apt-get, wget），而此时你又需要在终端下做其它工作。你该如何是好？Ctrl + Alt + F1至F5，再开一个终端？gnome-terminator里面再开一个Tab？再启动一个rxvt？再做一次ssh连接？噢，当然，你还可以Ctrl + C，把那个耗时的进程杀掉。但这都不是一个好的解决之道，相对于使用screen来说。</p>
<h4>screen的工作原理</h4>
<p>　　使用screen，你可以在同一个终端，同一个virtual terminator，同一个ssh中同时进行多个工作。它的大致工作原理是：当前shell中启动screen，此时screen是当前shell的一个子进程，而你现在处于screen的一个会话（session）的一个window中。这个window对应着一个shell进程（比如bash），当你陷入上面的场景时，screen可以让你再开一个（或多个）window，这个window又会对应一个新的shell进程。当然，这些window都在screen的大力监管之下，你可以在这些window之间自由切换。下面两图可能更能说清真象。</p>
<div class="wp-caption aligncenter" style="width: 223px"><img title="Local terminal" src="http://www.ibm.com/developerworks/cn/aix/library/au-gnu_screen/Figure_5.gif" alt="Local terminal" width="213" height="140" /><p class="wp-caption-text">Local terminal</p></div>
<div class="wp-caption aligncenter" style="width: 223px"><img title="ssh remote" src="http://www.ibm.com/developerworks/cn/aix/library/au-gnu_screen/Figure_4.gif" alt="ssh remote" width="213" height="342" /><p class="wp-caption-text">ssh remote</p></div>
<h4>screen使用方法</h4>
<p>　　多数Linux发行版默认都已经有screen了，在终端下直接启动screen即可。启动screen之后，你可以像往常那样工作，几乎没有任何区别。一旦你需要多个window时，你就需要知道一些快捷键来和screen打交道了。几乎所有的screen命令都是以Ctrl + a开始，以另外一个按键结束的。比如Ctrl a c表示，同时按下Ctrl键和a键，松开后按下c键，此时screen就为你创建了一个新window。多数情况下，Ctrl a Key和Ctrl a Ctrl Key效果是相同的，即你也可以保持按下Ctrl键，接着一次敲击a键和c键来创建新screen。但这对有些命令就不再适用，比如你想向当前window传递Ctrl a本身，就必须是Ctrl a a，而不能是Ctrl a Ctrl a，因为后者用来在当前window和上一个window之间切换。常用的命令见下表，完全的命令列表参见screen的manpage。</p>
<table>
<tbody>
<tr>
<th>C-a ?</th>
<td>显示所有键绑定信息</td>
</tr>
<tr>
<th>C-a w</th>
<td>显示所有window列表</td>
</tr>
<tr>
<th>C-a C-a</th>
<td>切换到之前显示的window</td>
</tr>
<tr>
<th>C-a c</th>
<td>创建一个新的运行shell的window并切换到该window</td>
</tr>
<tr>
<th>C-a n</th>
<td>切换到下一个window</td>
</tr>
<tr>
<th>C-a p</th>
<td>切换到前一个window(与C-a n相对)</td>
</tr>
<tr>
<th>C-a 0..9</th>
<td>切换到window0..9</td>
</tr>
<tr>
<th>C-a a</th>
<td>发送 C-a到当前window</td>
</tr>
<tr>
<th>C-a A</th>
<td>改变当前window的名字</td>
</tr>
<tr>
<th>C-a d</th>
<td>暂时断开screen会话</td>
</tr>
<tr>
<th>C-a k</th>
<td>杀掉当前window</td>
</tr>
<tr>
<th>C-a [</th>
<td>进入拷贝/回滚模式</td>
</tr>
</tbody>
</table>
<p>　　对Ctrl a d稍作解释。你如果有进程组的概念，可以知道，一旦关闭screen所在的shell，或者断开ssh连接，screen进程就会被关闭，当然由screen管理的各个window下的各进程也都会被关闭。Ctrl a d可以将screen与shell断开（detach）,这样即使关闭shell，screen及其子进程也不会被关闭。下次登录shell时，可以用screen -R来恢复先前的screen。</p>
<h4>使用.screenrc</h4>
<p>　　就像很多其它程序一样，screen也有自己的配置文件，用来让用户改变和定制screen的外观和功能。screen的配置文件可以是全局的/etc/screenrc，也可以是自家目录下的.screenrc。我的.screenrc极为简单，只有寥寥3行。你可以参照manpage设置自己的screenrc，进行一些键绑定、选项设置等。</p>
<pre>
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "
startup_message off
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/05/cmd-screen/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WordPress中使用LaTeX</title>
		<link>http://www.dutor.net/index.php/2010/05/wordpress-using-latex/</link>
		<comments>http://www.dutor.net/index.php/2010/05/wordpress-using-latex/#comments</comments>
		<pubDate>Sat, 15 May 2010 08:52:48 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[latex]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2277</guid>
		<description><![CDATA[　　前些天看到<a href="http://www.cnblogs.com/miloyip/archive/2010/04/26/1720877.html" target="_blank">这篇文章</a>，知道有<a href="http://www.codecogs.com/" target="_blank">这么个网站</a>提供了<a href="http://www.codecogs.com/latex/eqneditor.php" target="_blank">这样的服务</a>。除了方便的在线编辑外，这个网站对外还提供生成公式图片的服务，而且图片格式可选，公式清晰、字体饱满。于是我产生了修改LaTeX for Wordpress插件的想法，于是就有了这个插件Using $$\LaTeX$$。使用方法原来zhiqiang的插件，即通过一对$ $之间嵌入LaTeX公式（如$$\LaTeX !$$），通过在公式末尾加!号显示LaTeX语句本身（即$$\LaTeX!!$$）。
　　由于不再使用mimeTeX，而是CodeCogs提供的服务，因此可以使用CodeCogs提供的特有的语法，比如不同的字体风格、不同的分辨率、不同的图片格式、不同背景色等等，其他特色请自己揣摩。另外，Using LaTeX在大约500次访问之后，会自动清空缓冲文件夹。
<img src="http://mathurl.com/33z2yd8.png" alt="" />]]></description>
			<content:encoded><![CDATA[<p>　　你有独立Blog吗？你使用Wordpress吗？你经常需要在文章中插入数学公式吗？如果你的回答是肯定的，那么这篇文章就是写给你的。<br />
　　先前，我一直使用zhiqiang的一款流行的插件<a href="http://zhiqiang.org/blog/plugin/mimetex" target="_blank">LaTeX for WordPress</a>。这款插件使用LaTeX语法，和Wordpress提供的mimeTeX服务，为数学公式生成图片，缓存在博客程序所在主机上。每次访问页面，如果缓冲文件夹中没有所请求的公式图片，就会向远程服务器发出请求，从而生成图片，否则就直接使用缓冲文件夹已经生成的图片。关于这款插件的使用方法见zhiqiang（阅微堂）的<a href="http://zhiqiang.org/blog/plugin/mimetex" target="_blank">这篇文章</a>。</p>
<p>　　但是，这款插件有几个不算是缺点的缺点。mimeTeX生成的公式不是十分美观，当然这和具体的程序和服务器有关。mimeTeX的功能过于精简，LaTeX的诸多特性都得不到支持。编辑公式过程中会出现错误，或者需要再次修改，这样一来，那些被抛弃的图片仍然存在于缓冲文件夹中，需要手动清理。<br />
　　前些天看到<a href="http://www.cnblogs.com/miloyip/archive/2010/04/26/1720877.html" target="_blank">这篇文章</a>，知道有<a href="http://www.codecogs.com/" target="_blank">这么个网站</a>提供了<a href="http://www.codecogs.com/latex/eqneditor.php" target="_blank">这样的服务</a>。除了方便的在线编辑外，这个网站对外还提供生成公式图片的服务，而且图片格式可选，公式清晰、字体饱满。于是我产生了修改LaTeX for WordPress插件的想法，于是就有了这个插件Using <img src="http://www.dutor.net/wp-content/cache/c51d7e23458ca0e7373a8ed6ab56b2b9.png" align="absmiddle" class="tex" alt="\LaTeX" />。使用方法原来zhiqiang的插件，即通过一对$ $之间嵌入LaTeX公式（如$$\LaTeX $$），通过在公式末尾加!号显示LaTeX语句本身（即$$\LaTeX!$$）。<br />
　　由于不再使用mimeTeX，而是CodeCogs提供的服务，因此可以使用CodeCogs提供的特有的语法，比如不同的字体风格、不同的分辨率、不同的图片格式、不同背景色等等，其他特色请自己揣摩。另外，Using LaTeX在大约500次访问之后，会自动清空缓冲文件夹。<br />
　　<a href='http://www.dutor.net/wp-content/uploads/2010/05/Using-LaTeX.zip'>点击此处下载Using LaTeX</a>，安装方法同普通Wordpress插件，需要注意的是本插件会在wp-content下建立cache文件夹，请务必保证cache文件具有读写权限。<br />
　　最后炫一个<br />
<img src="http://mathurl.com/33z2yd8.png" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/05/wordpress-using-latex/feed/</wfw:commentRss>
		<slash:comments>17</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>abcde</title>
		<link>http://www.dutor.net/index.php/2010/05/abcde/</link>
		<comments>http://www.dutor.net/index.php/2010/05/abcde/#comments</comments>
		<pubDate>Tue, 04 May 2010 00:56:23 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[ToolKits]]></category>
		<category><![CDATA[命令]]></category>
		<category><![CDATA[音乐]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=2237</guid>
		<description><![CDATA[　　最近玩儿无损，据说有人曾说无损是种生活，是吗？上帝知道，烧友知道，我知道，你知道吗？
　　今天来了兴致，想把自己的几张Avril的碟子给榨出来。Google了一小下，知道有这么个工具，名字挺有意思，abcde = A Better CD Encoder. 它能从CD中rip出来波形文件（WAV），然后根据选项把波形文件转换成特定格式的音频文件，比如mp3, ogg, flac等等。flac = Free Lossless Audio Codec，就是我要的无损了。
　　UB/Debian下安装abcde很简单，apt-get abcde就<em>OK</em>了。安装时你可能发现这个东西很小，只有不到2M。其实，abcde只是一个脚本，它利用其它的工具来实现特定的功能。比如利用cdparanoia来生成WAV文件，利用lame生成mp3文件，利用flac生成flac文件，利用mkcue生成cue文件……因此，如果相应的工具没有被安装，或者路径不在PATH中，abcde就会有错误提示：
<pre>
[ERROR] abcde: lame is not in your path.
[INFO] Define the full path to the executable if it exists on your system.
</pre>]]></description>
			<content:encoded><![CDATA[<p>　　最近玩儿无损，据说有人曾说无损是种生活，是吗？上帝知道，烧友知道，我知道，你知道吗？<br />
　　今天来了兴致，想把自己的几张Avril的碟子给榨出来。Google了一小下，知道有这么个工具，名字挺有意思，abcde = A Better CD Encoder. 它能从CD中rip出来波形文件（WAV），然后根据选项把波形文件转换成特定格式的音频文件，比如mp3, ogg, flac等等。flac = Free Lossless Audio Codec，就是我要的无损了。<br />
　　UB/Debian下安装abcde很简单，apt-get abcde就<em>OK</em>了。安装时你可能发现这个东西很小，只有不到2M。其实，abcde只是一个脚本，它利用其它的工具来实现特定的功能。比如利用cdparanoia来生成WAV文件，利用lame生成mp3文件，利用flac生成flac文件，利用mkcue生成cue文件……因此，如果相应的工具没有被安装，或者路径不在PATH中，abcde就会有错误提示：</p>
<pre>
[ERROR] abcde: lame is not in your path.
[INFO] Define the full path to the executable if it exists on your system.
</pre>
<p>这时，安装相应的工具即可。<br />
　　你可以在命令行中为abcde指定选项和参数，但更好的方法是使用配置文件。abcde的配置有/etc/abcde.conf或者~/.abcde.conf(可能需要自行创建)，写好了配置文件，你就可以简单地执行abcde进行工作了，当然你仍然可以使用命令行选项来覆盖配置文件中设置的相应选项。abcde有哪些选项，配置文件如何写，请man之，Google之。<a href="http://www.andrews-corner.org/abcde.html" target="_blank">这里有个帖子</a>，里面有多个配置文件，包括MP3/ogg/AAC/FLAC/MPP/SPEEX，还有一个同时生成各种音频格式的配置。这里把生成FLAC文件的配置些出来，若要同时生成.cue文件（几乎是必需的），执行abcde时只需要</p>

<div class="wp_codebox"><table><tr id="p223735"><td class="code" id="p2237code35"><pre class="bash" style="font-family:monospace;">abcde <span style="color: #660033;">-1</span> <span style="color: #660033;">-o</span> default,cue</pre></td></tr></table></div>

<p>当然，mkcue必须已经安装。</p>
<pre>
# -----------------$HOME/.abcde.conf----------------- #
#
# A sample configuration file to convert music cds to
#       FLAC using abcde version 2.3.99.6
#
#       http://andrews-corner.org/abcde.html
# -------------------------------------------------- #

# Specify the encoder to use for FLAC. In this case
# flac is the only choice.
FLACENCODERSYNTAX=flac

# Specify the path to the selected encoder. In most cases the encoder
# should be in your $PATH as I illustrate below, otherwise you will
# need to specify the full path. For example: /usr/bin/flac
FLAC=flac

# Specify your required encoding options here. Multiple options can
# be selected as '--best --another-option' etc.
FLACOPTS='--verify --best' 

# Output type for FLAC.
OUTPUTTYPE="flac"

# The cd ripping program to use. There are a few choices here: cdda2wav,
# dagrab, cddafs (Mac OS X only) and flac.
CDROMREADERSYNTAX=cdparanoia            

# Give the location of the ripping program and pass any extra options:
CDPARANOIA=cdparanoia
CDPARANOIAOPTS="--never-skip=40"

# Give the location of the CD identification program:
CDDISCID=cd-discid            

# Give the base location here for the encoded music files.
OUTPUTDIR="$HOME/music/"               

# The default actions that abcde will take.
ACTIONS=cddb,playlist,read,encode,tag,move,clean

# Decide here how you want the tracks labelled for a standard 'single-artist',
# multi-track encode and also for a multi-track, 'various-artist' encode:
OUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
VAOUTPUTFORMAT='${OUTPUT}/Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'

# Decide here how you want the tracks labelled for a standard 'single-artist',
# single-track encode and also for a single-track 'various-artist' encode.
# (Create a single-track encode with 'abcde -1' from the commandline.)
ONETRACKOUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
VAONETRACKOUTPUTFORMAT='${OUTPUT}/Various-${ALBUMFILE}/${ALBUMFILE}'

# Create playlists for single and various-artist encodes. I would suggest
# commenting these out for single-track encoding.
PLAYLISTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}.m3u'
VAPLAYLISTFORMAT='${OUTPUT}/Various-${ALBUMFILE}/${ALBUMFILE}.m3u'

# Put spaces in the filenames instead of the more correct underscores:
mungefilename ()
{
  echo "$@" | sed s,:,-,g | tr / _ | tr -d \'\"\?\[:cntrl:\]
}

# What extra options?
MAXPROCS=2                              # Run a few encoders simultaneously
PADTRACKS=y                             # Makes tracks 01 02 not 1 2
EXTRAVERBOSE=y                          # Useful for debugging
EJECTCD=y                               # Please eject cd when finished <img src='http://www.dutor.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2010/05/abcde/feed/</wfw:commentRss>
		<slash:comments>0</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="p213136"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p2131code36"><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="p213137"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2131code37"><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="p213138"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2131code38"><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="p212439"><td class="code" id="p2124code39"><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>
	</channel>
</rss>

