虽然网上的vim插件安装的博文相当的多,但是还是自己经过N久摸索出来的比较的有成就感。当然最大的vim资源当然是官网了:http://www.vim.org/download.php,所谓神器也就只有圣者才能很好的驾驭,那么想成为一个圣者就应该认真的研究/doc文件了。

对于插件ctags

1.安装

其实比较的简单因为可以可以从软件包中定位

$sudo apt-get install ctags

接下来当然是输入密码安装了,不过我在想window下的gvim呢,这不是蛋疼么?

好的对于上面的方法我们直接忽略,来看看自己下载的tar归档文件时怎么整的。

首先下载ctas文件:http://ctags.sourceforge.net

$ tar -xzvf ctags-5.6.tar.gz
$ cd ctags-5.6
$ make
# make install   // 需要root权限

啥,不会用tar,你out了,好吧,那我们来生成一个deb文件(就像是window下的.exe文件)

记住alien指令,别以为它叫陌生你就可以对它陌生了。

alien - Convert or install an alien binary package(意思就是转换或安装alien安装包)至于用法就自己看手册吧!!

言归正传,make install 之后我们会发现屏幕反馈了一下信息:

cp ctags /usr/bin/ctags && chmod 755 /usr/bin/ctags

当然还有其他的信息,我们只要这个文件其他的我才不管呢。发现没有ctags有可执行属性那么是不是和$sudo apt-get install ctags后的指令相同呢,right!

但是我该怎么用呢,如果你用的是$sudo apt-get install ctags你就可以用man手册看看用法,我这里就引用几句:

name: ctags - Generate tag files for source code

discription: The  ctags  and etags programs (hereinafter collectively referred to as ctags, except where distinguished) generate an index (or "tag") file
       for a variety of language objects found in file(s).  This tag file allows these items to be quickly and easily located by a text  editor  or other  utility. A  "tag"  signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object).

source list: …By  default, all other files names are ignored. This permits running ctags on all files in either a single directory (e.g. "ctags *"), or on
       all files in an entire source directory tree (e.g. "ctags -R"), since only those files whose names are mapped to languages will be scanned…

这几句说的很明白从ctags是用来给源代码生成tag文件的,那么tag有什么用呢,请看上面指示:index(or “tag”)就是说tag file 是一个索引文件——语言文件中的对象的索引!通过这个索引对象我们就可以快速的定位对象的定义!啥,这不是VS中的工具么。对,现在你不用羡慕VS了。那么是不是这样就可以了呢,你会发现<C-]>一下毛都没有,坑爹啊!不急还没说完呢,请继续往下看。

可以对所有的文件或文件夹执行ctags指令,至于文件夹实际上就是对多个文件(至于哪些文件可以用ctags –list-maps查看一下)进行索引,然后在当前目录下生成一个tags文件,这不就是我们折腾了这么久的东西么!然后呢是不是就可以了呢,是的打开vim之后:set tag={刚才生成的tags文件的目录}一下就可以了,尝试一下,打开tag索引的源文件
,随便找到一下函数<C-]>一下,发生了什么我的光标呢,原来在函数的定义处,哈哈,这么神奇!还有么,?有的,:help ctags看看就行了。当你新定义了一个函数的时候呢发现对这个函数没有用了,是的你必须重新制作一个tags文件,擦是不是很坑爹!不,要看你怎么用了。

再介绍一个简单点的指令gD就是跳转到定义处,啥就这么简单,我刚才还折腾了那么久呢?是的,但是呢它跳转的不是完全的定义处,而是第一次出现的地方(声明或定义)。

码字真累啊!

posted on 2012-04-08 17:04  Junhv.W  阅读(942)  评论(0编辑  收藏  举报