VIM中查看头文件和库函数的方法

 VIM中查看头文件,库函数的方法:

  1、最简单的方法是安装对应库的man手册,直接在终端man xxx(函数)如 man printf 就会看到pringf相关的信息,这种方法简单而且显示的信息很多,前提是你的英文必须过关!这种方法不是这里的重点。

  安装一个最基本的文档sudo apt-get install manpages-dev

  2、这种方法可以让你更了解头文件或内核源码的结构

  (1)首先安装一个工具Ctags:sudo apt-get install Ctags

  让后我们进入/usr/include或你的内核目录进行如下操作:ctags -R *,这会在当前目录下递归的为各个子目录生成一个名为tags标签文件,这个操作在第一次执行后即可。

  现在在我们执行vim -t printf我们会看到我们进入了vim的编辑界面同时也到了printf声明的地方。或直接进入vim编辑界面输入 :tag <函数名或宏等> 按TAB键可以进行模式匹配,继续安TAB匹配下一个。

  可是这样查到的东西可能不是你想要的那一个,怎么解决这个问题呢?

  (2)解决上面问题需要安装一个工具cscope:sudo apt-get install cscope

  上面几个工具单独用功能不是很大,可是结合起来功能就非常强大了。我这里有一个自己用的vim脚本,是拷贝别人的功能不是很多,但是已经够用了。

  在用户目录下新建一个.vimrc文件将下面内容添加到文件中:

 

 

set mouse=a
        let Tlist_Use_Right_Window=1
        let Tlist_File_Fold_Auto_Close=1
        map :TlistToggle
        noremap :make
        noremap :make clean;make
        noremap :Tlist
        noremap :TlistSync
        noremap :!./vitags.sh:cs reset
        noremap :!cvs up
        nnoremap @=((foldclosed(line(''.'')) < 0)       ''zc'' : ''zo'')

if has("multi_byte")
        set encoding=utf-8
        set fileencoding=chinese
        set fileencodings=ucs-bom,utf-8,chinese
        endif
        set wrap
        set hlsearch
        filetype plugin on

colorscheme elflord
        syntax on

set nocp
        filetype plugin on
        filetype indent on

if has("cscope")
        set csprg=/usr/bin/cscope
        set csto=0
        set cst
        set nocsverb
        " add any database in current directory
        if filereadable("cscope.out")
        cs add cscope.out
        " else add database pointed to by environment
        elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
        endif
        set csverb
        set cscopetag
        endif

set nu
        set ts=4
        set sw=4

set ru
        set hls
        set is
        set sm
        set cin
        set cino=:0g0t0(sus

set autoread                              " read open files again when changed outside Vim
        set incsearch                              " use incremental search
        set nowrap                               " do not wrap lines
        set nobackup
        set nowritebackup
        map :!ctags -R --c-kinds=+p --fields=+iaS --extra=+q .
        map :!ctags -R .

  现在再试试vim -t <函数名或宏等>,这时如果有多个选项的话就会出现一个列表让你选择你需要的那个。

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值