linux---vim---ctag

来源:互联网 发布:品友互动 知乎 编辑:程序博客网 时间:2024/05/22 03:31
 

【前言】

    ctags是vim的一个非常有用的插件,可以大大提高程序编码(C、C++)的效率,比如快速调整到函数、变量定义处等等常用

功能,更详细的功能,自行百度。

 
【目的】

    在RHEL 5上面安装配置vim插件ctags


【前提条件】

    vim已经安装


【安装ctags】

    1、首先确定自己是否已经安装了ctag:

[root@ericsson:~]#which
ctags/usr/bin/ctags
    如果结果如上,证明已经安装了该插件,则跳过下面步骤。

    如果找不到,极有可能ctags还没安装,安装步骤如下:

    1、下载ctags:http://ctags.sourceforge.net

    2、上传到linux,解压,假设目录为:/tmp/ctags

    3、确保/tmp/ctags/configure文件有执行权限,执行该文件:/tmp/ctags/configure

    4、执行命令:make;make install

    如果顺利,上面4个步骤可以成功安装ctags

 

【配置ctags】

    假设你要编译的源代码目录位置为:/worksapce/weather

    执行下面操作,生成tags标签文件:

[root@ericsson:/workspace/weather]#pwd
/workspace/weather
[root@ericsson:/workspace/weather]#ls
dispacth.cpp  dispacth.h  main.cpp
[root@ericsson:/workspace/weather]#ctags -R *
[root@ericsson:/workspace/weather]#ls
dispacth.cpp  dispacth.h  main.cpp  tags
   

    vim的配置文件有下面三个:

        system vimrc file: "/etc/vimrc"
        user vimrc file: "$HOME/.vimrc"
        user exrc file: "$HOME/.exrc"

    我本机配置vim是针对全局的,所以修改/etc/vimrc文件,在文件最后添加下面内容:

set tags=/workspace/weather/tags

 

       如果有多个tags文件则用逗号隔开(tags文件名可以相同),设置完tags变量之后,使用如下:

 

[root@ericsson:/workspace/weather]#ls
a.out  dispacth.cpp  dispacth.h  main.cpp  tags
[root@ericsson:/workspace/weather]#vi -t ttcs 
    ttcs是函数名,被定义在main.cpp,如果ctags安装配置正确,则会自动跳到该函数定义处,如果有多个函数,则会出现一个列表。如果

出现:“E257: cstag: tag not found ”,建议重新到代码目录,运行:ctags -R *

原创粉丝点击