vim查看头文件和库

来源:互联网 发布:彩票免费计划软件 编辑:程序博客网 时间:2024/06/05 18:33

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 <函数名或宏等>,这时如果有多个选项的话就会出现一个列表让你选择你需要的那个。

一个好用的工具可以让你的工作效率大大提高,这里只是介绍了一点点,希望大家补充,纠正错误。

转自:http://www.eefocus.com/ayayayaya/blog/09-07/173780_e863b.html

0 0
原创粉丝点击