• Ubuntu16.04安装配置和使用ctags


    Ubuntu16.04安装配置和使用ctags

    by ChrisZZ

    ctags可以用于在vim中的函数定义跳转。在ubuntu16.04下默认提供的ctags是很老很旧的ctags,快要发霉的版本(5.9~svn20110310-11),快扔掉它,安装universal-ctags吧!

    发霉的exuberant-ctags

    来,一起看看,默认的ctags是什么情况。

    查看apt提供了哪些ctags包

    aptitude search ctags
    

    查询结果:

    v   ctags                                                                                                                             -                                                                                                                                            
    v   ctags:i386                                                                                                                        -                                                                                                                                            
    i   exuberant-ctags                                                                                                                   - build tag file indexes of source code definitions                                                                                          
    p   exuberant-ctags:i386                                                                                                              - build tag file indexes of source code definitions                                                                                          
    p   geany-plugin-ctags                                                                                                                - ctags plugin for Geany                                                                                                                     
    p   geany-plugin-ctags:i386                                                                                                           - ctags plugin for Geany                                                                                                                     
    p   libparse-exuberantctags-perl                                                                                                      - exuberant ctags parser for Perl                                                                                                            
    p   libparse-exuberantctags-perl:i386                                                                                                 - exuberant ctags parser for Perl          
    

    其中只有exuberant-ctags是apt可安装ctags版本的正确名字。

    查看exuberant-ctags版本信息

    dpkg -l exuberant-ctags
    

    查询结果:

    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
    ||/ Name                                                           Version                              Architecture                         Description
    +++-==============================================================-====================================-====================================-==================================================================================================================================
    ii  exuberant-ctags                                                1:5.9~svn20110310-11                 amd64                                build tag file indexes of source code definitions
    

    看到其中版本号是5.9~svn20110310-11,已经7年没有更新了。这样的包,发霉7年了,扔了吧:

    sudo apt remove exuberant-ctags -y
    

    安装新鲜的universal-ctags

    universal-ctags是什么?A maintained ctags implementation, https://ctags.io,一个负责的ctags实现,在github上开源并且持续更新和维护。

    不多说,快点安装吧:

    sudo apt install autoconf
    cd /tmp
    git clone https://github.com/universal-ctags/ctags
    cd ctags
    ./autogen.sh
    ./configure --prefix=/opt/software/universal-ctags  # 我的安装路径。你按自己的情况调整。
    make -j8
    sudo make install
    

    把ctags可执行文件更新到系统PATH上?No,我选择创建链接的方式:

    # 如果你装了emacs-snapshot,那么现在的ctags命令实际上链接到了/usr/bin/ctags-snapshot,要先删除链接文件:
    # sudo rm /usr/bin/ctags
    
    # 然后,把新编译安装的universal-ctags链接过来:
    sudo ln -s /opt/software/universal-ctags/bin/ctags /usr/bin/ctags
    

    在vim中配置ctags

    关键配置是:

    set tags=tags;
    set autochdir
    

    放在vim配置文件中。

    可以直接用我的vim配置:

    cd /tmp
    
    git  clone --depth=1  https://github.com/amix/vimrc.git  ~/.vim_runtime
    sh  ~/.vim_runtime/install_awesome_vimrc.sh
    
    git  clone  https://github.com/zchrissirhcz/dotfiles
    cp  dotfiles/my_configs.vim  ~/.vim_runtime/
    

    使用ctags

    cd ~/work/opencv   # 随便进入到一个你的c++工程目录
    ctags -R .  #递归地生成.tags文件
    

    然后在vim中用Ctrl+](跳转到函数定义)和Ctrl+t(跳出定义)。注意,可以多层级嵌套使用,所以这两个操作相当于入栈和弹栈。

    enjoy!

    ===
    update@2019-01-14 11:00:25

    在tensorflow源码中使用ctags,发现很多C++结构体或函数跳转有问题,没法跳转到定义。这种情况是因为tensorflow很多代码不是C/C++写的,而是protobuf,调用protoc编译器后才生成相应的C/C++代码。很坑。

  • 相关阅读:
    paip.提升用户体验上传文件图片命名
    paip.提升安全性软键盘的弱点
    paip.java桌面开发应用与WEB RIA应用
    paip.提升安全性WEB程序安全检测与防范
    paip.PHP zend解密—以SHOPEX4.8.4为例
    PAIP.提升安全性COOKIE绑定IP与城市与运营商
    paip.svn不能提交CLEARUP不起作用解决方法
    paip.提升安全网站登录密码明文传输的登录高危漏洞解决方案
    paip.docfile二进制复合文档
    paip.session的调试in php
  • 原文地址:https://www.cnblogs.com/zjutzz/p/9393397.html
Copyright © 2020-2023  润新知