<?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>Tony Bai &#187; Ctags</title>
	<atom:link href="http://tonybai.com/tag/ctags/feed/" rel="self" type="application/rss+xml" />
	<link>https://tonybai.com</link>
	<description>一个程序员的心路历程</description>
	<lastBuildDate>Mon, 08 Jun 2026 23:32:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Hello，Sublime Text 2</title>
		<link>https://tonybai.com/2013/04/01/hello-sublime-text-2/</link>
		<comments>https://tonybai.com/2013/04/01/hello-sublime-text-2/#comments</comments>
		<pubDate>Mon, 01 Apr 2013 06:58:41 +0000</pubDate>
		<dc:creator>bigwhite</dc:creator>
				<category><![CDATA[技术志]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Blogger]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Codecs26]]></category>
		<category><![CDATA[ConvertToUTF8]]></category>
		<category><![CDATA[Ctags]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Opensource]]></category>
		<category><![CDATA[PackageControl]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SublimeText2]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[学习]]></category>
		<category><![CDATA[工作]]></category>
		<category><![CDATA[开源]]></category>
		<category><![CDATA[程序员]]></category>
		<category><![CDATA[编辑器]]></category>

		<guid isPermaLink="false">http://tonybai.com/?p=1238</guid>
		<description><![CDATA[用惯了Vim后，也会有一种尝试新Editor的冲动，这回Sublime Text 2满足了我的这个需求。据说Sublime Text是目前最火的代码编辑器之一，我周围为数不多的几个比较Geek的同事都已经开始使用Sublime Text 2或用了很长时间了，其官方网站首页的Feature Demo也的确非常地炫。 安装Sublime Text 2 我的实验环境Ubuntu 12.04.1 32-bit Desktop版，默认Ubuntu Unity桌面，iBus拼音输入法。 Sublime Text 2的安装极其简单，遵循着download（http://www.sublimetext.com/2） -&#62; unzip -&#62; add path -&#62; start and use的经典路线。我下载的Sublime Text 2是2.0.1版本，启动后一切正常。 安装后目录结构 安装后的Sublime Text 2的目录结构非常简洁： $ ls Icon/ &#160;PackageSetup.py &#160; Pristine Packages/ lib/ &#160; sublime_plugin.py &#160; sublime_text* lib下是自带的Python26环境；Pristine Packages下是各种编程语言的插件包。 在我的环境下Sublime Text 2的用户配置与包环境放在了~/.config/sublime-text-2/下面， $ ls Installed Packages/ &#160;Packages/ [...]]]></description>
			<content:encoded><![CDATA[<p>用惯了<a href="http://tonybai.com/2008/12/30/in-depth-study-vim/">Vim</a>后，也会有一种尝试新Editor的冲动，这回<a href="http://www.sublimetext.com/2">Sublime Text 2</a>满足了我的这个需求。据说Sublime Text是目前最火的代码编辑器之一，我周围为数不多的几个比较Geek的同事都已经开始使用Sublime Text 2或用了很长时间了，其官方网站首页的Feature Demo也的确非常地炫。</p>
<p><strong>安装Sublime Text 2</strong></p>
<p>我的实验环境<a href="http://tonybai.com/2012/12/04/upgrade-ubuntu-to-1204-lts/">Ubuntu 12.04.1</a> 32-bit Desktop版，默认Ubuntu Unity桌面，iBus拼音输入法。</p>
<p>Sublime Text 2的安装极其简单，遵循着download（http://www.sublimetext.com/2） -&gt; unzip -&gt; add path -&gt; start and use的经典路线。我下载的Sublime Text 2是2.0.1版本，启动后一切正常。</p>
<p><strong>安装后目录结构</strong></p>
<p>安装后的Sublime Text 2的目录结构非常简洁：</p>
<p><span style="font-family:courier new,courier,monospace;">$ ls<br />
	Icon/ &nbsp;PackageSetup.py &nbsp; Pristine Packages/<br />
	lib/ &nbsp; sublime_plugin.py &nbsp; sublime_text*</span></p>
<p>lib下是自带的Python26环境；Pristine Packages下是各种编程语言的插件包。</p>
<p>在我的环境下Sublime Text 2的用户配置与包环境放在了~/.config/sublime-text-2/下面，</p>
<p><span style="font-family:courier new,courier,monospace;">$ ls<br />
	Installed Packages/ &nbsp;Packages/ &nbsp;Pristine Packages/ &nbsp;Settings/</span></p>
<p>这里面最重要的目录就是Packages目录了，这里是Sublime Text 2用第三方包扩展自身Feature的包存储路径。</p>
<p><strong>安装package control</strong></p>
<p>package control包之于Sublime Text 2就好比apt工具之于Ubuntu，它是一个方便第三方包安装、卸载和管理的第三方包。在其官网(http://wbond.net/sublime_packages/package_control)上明示了其安装方法：</p>
<p>* 敲入 ctrl + ` 调出命令行窗口<br />
	* 在命令行窗口中输入下面的代码，回车执行。</p>
<p><span style="font-family:courier new,courier,monospace;">import urllib2,os; pf=&#39;Package Control.sublime-package&#39;; ipp=sublime.installed_packages_path(); os. &nbsp; &nbsp; &nbsp; &nbsp;makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2. &nbsp; ProxyHandler())); open(os.path.join(ipp,pf),&#39;wb&#39;).write(urllib2.urlopen(&#39;http://sublime.wbond.net/&#39;+pf.replace(&#39; &#39;,&#39;%20&#39;)).read()); print(&#39;Please restart Sublime Text to finish installation&#39;)</span></p>
<p>* 重启Sublime Text 2。</p>
<p>注意：如果需要代理访问外网的话，需要正确设置<a href="http://tonybai.com/2012/11/21/setup-http-proxy-with-squid/">http_proxy</a>环境变量。</p>
<p>敲入&quot;ctrl + shift + p&quot;可打开命令窗口，输入&quot;Package Control&quot;，你会看到窗口下拉提示中Package Control支持的功能，常用的我们会选择：&ldquo;Package Control: Install Package&rdquo;。</p>
<p><strong>安装中文支持</strong></p>
<p>中国程序员每每在尝试一种国外程序员新开发的编辑器时，都会遇到<a href="http://tonybai.com/2009/09/28/also-talk-about-vim-charset-configuration/">中文字符集编码</a>的问题，这次Sublime Text 2也不例外，它原生就不支持中文显示。还好中国程序员是无比聪明的，开发了<a href="https://github.com/seanliang/ConvertToUTF8">ConvertToUTF8</a>这样的第三方包，让我们可以看到中文并用中文编辑。</p>
<p>最简单的安装ConvertToUTF8的方法就是用Package Control安装，选择Package Control: Install Package后，搜素ConvertToUTF8，找到后，点击即可安装。安装后，你会在~/.config/sublime-text-2/Packages下面看到ConvertToUTF8包目录。</p>
<p>再次启动Sublime Text 2后，打开一个GBK编码的中文文档，居然提示ConvertToUTF8工作不正常。后发现ConvertToUTF8主页上有提示，Python 2.6下的ConvertToUTF8需要一个<a href="https://github.com/seanliang/Codecs26">Codecs26</a>的Package才能正常运行。下载Codecs26后，解压安装到Packages下面，重新启动Sublime Text 2，Sublime Text 2直接dump core。从Packages目录下将Codecs26删除后，Sublime Text 2恢复正常。</p>
<p>又细致读了ConvertToUTF8作者的README文件，发现master branch上的Codecs26是for 64位版本的，我需要下载x32 branch上的包。的确，下载并安装x32 branch上的Codecs26后，Sublime Text 2启动OK，转换中文OK了。</p>
<p>注意：不要与其他支持GBK转换的包（比如GBK Encoding Support）混用，否则ConvertToUTF8无法works。</p>
<p><strong>解决中文输入问题</strong></p>
<p>好不容易能看GBK编码的中文文件了，却发现无法输入中文，无论如何切换输入法和重启输入法，都无法输入中文。网上介绍可通过&quot;Input Helper Package（cd .config/sublime-text-2/Packages; git clone http://github.com/xgenvn/InputHelper.git）&quot;解决问题。问题的确可以解决，不过输入中文时太麻烦了：需要先敲入&quot;ctrl+shift+z&quot;调出中文输入框，再在这个框里输入中文。</p>
<p>网上都说这是iBus输入法与Sublime Text 2的兼容问题，要想解决就要换<a href="http://www.fcitx.org">fcitx</a>。以前用过fcitx感觉默认输入法比较弱，不过现在fcitx有google pinyin了，体验一定会提高不少。通过下面命令一键安装fcitx：</p>
<p><span style="font-family:courier new,courier,monospace;">sudo apt-get install fcitx fcitx-googlepinyin</span></p>
<p>安装后，在&ldquo;语言支持&rdquo;中用fcitx替换掉iBus。在&ldquo;启动应用程序&rdquo;中加入：</p>
<p><span style="font-family:courier new,courier,monospace;">名称: Fcitx<br />
	命令: /usr/bin/fcitx -d<br />
	注释t: Fcitx启动</span></p>
<p>注销再登录后，再打开Sublime Text 2，终于可以输入中文了。</p>
<p><strong>功能</strong></p>
<p>用了一遭儿，Sublime Text 2最吸引我的Feature包括：&ldquo;Goto Anything&rdquo;和&ldquo;Multi-Selection&rdquo;。在一个工程中，通过ctrl + p调出一个输入框，Sublime Text 2首先在文件名级别对你输入的文本进行匹配；待选择好文件后，继续输入@，可看到下拉列表中显示这个文件中所有函数名的名称列表；如果输入的是#，那么下拉列表中将显示该文件中的所有符号。选择某个函数名或符号后，光标将停留在某个符号上，这时我们可以用Multi-Selection这个功能了，如果你要将这个文件中同名符号全选出来，直接Alt+F3即可；如果要选择接下来的N个同名符号，那么敲入N次ctrl + D即可。</p>
<p>不过要想实现<a href="http://tonybai.com/2009/02/23/solve-some-problems-when-using-cscope/">ctags</a>那种在符号上跳转到符号定义或符号调用者的功能，Sublime Text 2还无法原生支持，可考虑安装Sublime Text 2的Ctags插件实现：直接在Packages目录下git clone https://github.com/SublimeText/CTags.git。之后：<br />
	- &ldquo;ctrl +t, ctrl+ r&quot;会重新生成tags文件(前提：系统内安装了ctags程序)<br />
	- &quot;ctrl +t, ctrl + t&quot;会跳到光标所在符号的定义处;<br />
	- &quot;ctrl + t, ctrl + b&quot;会跳回上次的位置;</p>
<p><strong>感受</strong></p>
<p>Sublime Text 2给我的最大感受就是&ldquo;快&rdquo;！你在搜索、切换符号、选择文件列表中文件或符号的同时，整个文件会同步的展现你的屏幕上。</p>
<p style='text-align:left'>&copy; 2013, <a href='https://tonybai.com'>bigwhite</a>. 版权所有. </p>
]]></content:encoded>
			<wfw:commentRss>https://tonybai.com/2013/04/01/hello-sublime-text-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>VIM“重装上阵”</title>
		<link>https://tonybai.com/2008/12/30/in-depth-study-vim/</link>
		<comments>https://tonybai.com/2008/12/30/in-depth-study-vim/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 02:51:09 +0000</pubDate>
		<dc:creator>bigwhite</dc:creator>
				<category><![CDATA[技术志]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Blogger]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Cscope]]></category>
		<category><![CDATA[Ctags]]></category>
		<category><![CDATA[Opensource]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Taglist]]></category>
		<category><![CDATA[Vi]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[博客]]></category>
		<category><![CDATA[开源]]></category>
		<category><![CDATA[程序员]]></category>

		<guid isPermaLink="false">http://tonybai.com/2008/12/30/vim%e2%80%9c%e9%87%8d%e8%a3%85%e4%b8%8a%e9%98%b5%e2%80%9d/</guid>
		<description><![CDATA[国内很多学习Python的人都喜欢看&#34;A Byte of Python&#34;，这是一本由印度小伙儿Swaroop C H写的书，之所以受到大家关注和欢迎，想必其简单而实用的写作风格是其中的重要原因吧，作为入门书很适合。我的Laptop中就有一本中文翻译版，不过书中用的还是Python 2.3.4版本。本月3日(2008-12-3)Python 3.0 Release版祭出，Swaroop C H也在其站点上增加了A Byte of Python for 3.0版。在下载新版&#38;quot...]]></description>
			<content:encoded><![CDATA[<p>国内很多学习<a href="http://www.python.org" target="_blank">Python</a>的人都喜欢看&quot;<a href="http://www.swaroopch.com/notes/Python" target="_blank">A Byte of Python</a>&quot;，这是一本由印度小伙儿<a href="http://www.swaroopch.com/" target="_blank">Swaroop C H</a>写的书，之所以受到大家关注和欢迎，想必其简单而实用的写作风格是其中的重要原因吧，作为入门书很适合。我的Laptop中就有一本中文翻译版，不过书中用的还是Python 2.3.4版本。本月3日(2008-12-3)<a href="http://www.python.org/download/releases/3.0/" target="_blank">Python 3.0 </a>Release版祭出，Swaroop C H也在其站点上增加了A Byte of Python for 3.0版。在下载新版&quot;A Byte of Python&quot;的同时，我又发现了Swaroop C H的另外一部作品&quot;<a href="http://www.swaroopch.com/notes/VIM" target="_blank">A Byte of VIM</a>&quot;。</p>
<p>刚工作的时候，一直用原始的<a href="http://ex-vi.sourceforge.net/" target="_blank">VI</a>(非VIM)在Unix上写代码，之所以选择原始的VI是因为部门里的老同事都使用它，<a href="http://www.VIM.org" target="_blank">VIM</a>用的人不多，刚出校门的我还十分不适应VI的操作(在VIsual Studio上用IDE惯了)，形成VI习惯还是很痛苦的，学习过程似乎没有什么成就感。看着其他一起入司的同事使用VIM的各种&quot;奇技淫巧&quot;分割窗口、折叠代码、自动补齐、通过快捷键在代码文件间跳来跳去，我却仍没有一些想深入学习的感觉(也许当时将精力都投到Java上了吧^_^)。</p>
<p>今年一直在努力通过各种方法(<a href="http://tonybai.com/2008/10/08/work-with-dual-monitors/" target="_blank">双显示器</a>、<a href="http://tonybai.com/2008/10/14/distributed-compiling-make-you-work-more-effectivly/" target="_blank">分布式编译</a>等)提高自己的工作效率，提升工作效率是大势所趋，随着工作责任的增多，工作任务相应的也要多起来，时间还是那些，这就需要你在短时间内高效的完成工作。我们能做的除了做好时间管理、理顺工作流程外，对于个体来说采用更高效的工具以及熟练掌握这些工具就是高效工作的一个突破口了。眼下对于我来说重要的就是让<a href="http://tonybai.com/2008/12/30/in-depth-study-vim" target="_blank">VIM&quot;重装上阵&quot;</a>(工作多年了，还是用使用VI的方法去使用VIM这个强大的工具，有些说不过去了^_^)。</p>
<p>与VI相比，VIM显然更强大，让人惊异于网上的各种VIM的插件和辅助软件，将这些结合在一起后，似乎一个无所不能的IDE就这样诞生了，也许这就是Unix文化的魅力所在吧。Swaroop C H的&quot;A Byte of VIM&quot;，特别是其中的&quot;VIM, Programmer&#039;s Editor&quot;一节中将一个程序员应该常用到的插件和辅助软件都集中在了一起，从头到尾读一遍，你就会能体会到VIM的强大。关于如何使用VIM高效编辑的最好的Guide类文档当属Vim的Founder <a href="http://www.moolenaar.net/" target="_blank">Bram Moolenaar</a>所写的&quot;<a href="http://www.moolenaar.net/habits.pdf" target="_blank">Seven habits of effective text editing</a>&quot;了，目前该文档已经进化到2.0了。Bram在文中的一句话我觉得对学习Vim则是很有指导意义：&quot;Learning every feature of Vim might make you the great award of Vim, but it will not be very effective. And it will be impossible to make everything a habit.&quot; 在VIM纷繁芜杂的功能中找到符合自己的实用功能并形成编辑习惯才是最高效的。</p>
<p>部门服务器上的VIM依旧停留在6.3版本，很多我需要的VIM新功能都不支持。为了不影响大家使用，我还是决定在自己的用户目录下重新编译一个VIM，最新版7.2，这样自己可以按照自己的需求定制。在SunFreeWare网站下载<a href="ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/VIM-7.2.tar.gz" target="_blank">Vim7.2 For SPRAC Solaris 9</a>的源码包，解压后发现VIM的目录组织很清晰整洁，Configure &#038; Make，编译过程很顺利也，甚至连一个Warning都没有，10分钟编译完毕。Make install到自己指定的目录(需要在Configure的时候使用&#8211;prefix参数)，修改path。再一执行Vim，版本已经变成了7.2了。</p>
<p><a href="http://ctags.sourceforge.net/" target="_blank">Ctags</a>一直在使用，不过发现系统里的Ctags版本较低，为了能更好的配合Vim 7.2，我还是下载了一个Ctags 5.7版本源码，重新编译了一个自己用的CTags。在测试项目顶层Ctags -R生成tags文件，测试了一把，一切OK。</p>
<p><a href="http://VIM-taglist.sourceforge.net/" target="_blank">Taglist</a>以前一直没有用过，下载其最新版taglist_45.zip，在本地$VIM_INSTALL_HOME/share/vim/vim72解压，<br />
	&nbsp; inflating: plugin/taglist.vim&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />
	&nbsp; inflating: doc/taglist.txt<br />
	在测试项目里打开一个源文件，命令栏下输入: TlistToggle，Vim打开一个新的窗口，显示你当前Vim Buffer里的宏、<a href="http://tonybai.com/2008/05/02/also-talk-about-typedef/" target="_blank">Typedef</a>、Functions、Variables等。你可以使用&quot;Ctrl+w, Ctrl+w&quot;在两个窗口间切换，对于函数较多较长、size较大的源文件的编辑有很大效率提升，list窗口中的内容也是普通文本，可以用各种搜索功能定位函数或变量，然后回车跳转到主窗口的相应源码。</p>
<p>Ctags和Taglist都功能有限，<a href="http://cscope.sourceforge.net/" target="_blank">CScope</a>才是集大成于一身，Vim内置了8种CScope的查询操作，比如你可以查询到当前光标下的函数被哪些方法调用，这个功能相当实用。由于我们服务器上没有CScope，我下载了源码编译，结果很不顺利，总是报错，无法解决，无奈只能让管理员在主机上用已经做好的安装包安装一个了。然后下载<br />
	<a href="http://cscope.sourceforge.net/cscope_maps.vim" target="_blank">cscope_maps.vim</a>，将之放入.vim/plugin下面，cscope_maps.vim将冗长的cscope命令映射为热键了，便于使用。安装好后打开Vim，使用热键，vim在状态栏中居然提示不支持cs命令。Help了一下CScope，发现Vim默认编译时是不支持CScope的，需要重新Configure，重新Make，这次configure就要加上&#8211;enable-cscope选项了。另外CScope单独执行时会用你默认的编辑器打开相应文件，你可以通过在shell里设置&lsquo;EDITOR&rsquo;环境变量来指定编辑器。</p>
<p>有了CTags、Taglist和CScope，你的Vim将呈现出丰富多彩的界面。窗口多了，别晕了。</p>
<p>Vim新版支持了内置的补全功能，通过Ctrl+N or Ctrl+P可在补全列表中前后选择；内置的补全功能会在当前缓冲区、其它缓冲区，以及当前文件所包含的头文件中查找以光标前关键字开始的单词，也是平时用的最多的补全功能。</p>
<p>Snippets，看到这个单词也许使用TextMate的人最为熟悉不过了，通过敲击几个关键字符+TAB间即可帮助你展开一些最常用的代码，减少输入的重复工作，比如for, while, if以及C++等面向对象语言中的class结构，你只需要输入内容即可。Snippets同样是通过插件<a href="http://VIM.sourceforge.net/scripts/script.php?script_id=1318" target="_blank">snippetsEmu</a>的形式提供到Vim中的。只需要Vim网站下载两个文：snippy_bundles.vba和snippy_plugin.vba，千万不要别扩展名给蒙住了，这两个文件不是Windows上的那个VBA脚本文件，而估计是vimball文件，下载后分别用vim打开，然后执行&quot;source %&quot;即可。VIM会在.vim/下的after和plugin下放入若干文件，用以支持Snippets功能。你可以打开~/.vim/after/ftplugin/c_snippets.vim，看看它对C语言都有哪些Snippets，如果觉得不符合你的习惯可以修改之。随意打开一个C源文件，输入do+TAB，可以看到：<br />
	do<br />
	{<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />
	} while ();<br />
	光标停留在中央，待你输入内容；输入后，点击Tab，光标会跳到下一个中，待输入完内容，再TAB，则最后一个消失，输入完毕。是不是也很强大:)</p>
<p>Vim的Quickfix模式是我以前没用到的，Quickfix这个就好比Visual Studio的&ldquo;输出窗口&rdquo;，build过程出现的错误都会在里面列表显示，你在这个窗口里将光标切换，主窗口就会显示对应的错误位置。前提你要在Vim内执行Make，一般我会使用:cw打开quickfix窗口，用cn和cp在quickfix中的错误行中切换。</p>
<p>其实以上每一个新功能都很复杂，形成习惯需要一个过程，但是一旦形成了习惯，你的效率将会有大幅提高。</p>
<p style='text-align:left'>&copy; 2008, <a href='https://tonybai.com'>bigwhite</a>. 版权所有. </p>
]]></content:encoded>
			<wfw:commentRss>https://tonybai.com/2008/12/30/in-depth-study-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
