using ctags and cscope in vim
2017-07-05 23:16
429 查看
ctags
1.安装ctags
sudo apt-get install ctags
也可以源码安装或直接下载可执行的bin文件。
2.生成tags数据文件
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
也可以先生成一个文件列表,再根据文件列表生成tags数据文件。这样可以排除不想要的一些源码文件。
ctags --c++-kinds=+p --fields=+iaS --extra=+q
对于linux kernerl源码,有个更简单的方法。
make tags ARCH=arm64
3.加载tags文件
如果tags文件在当前目录下,当打开vim的时候可自动加载。如果不在当前目录下,可在vim中用如下方法加载tags文件。
:set tags=~/xxx/tags
使用tags
ctrl-]跳转到光标所在标识符定义处。
ctrl-w ]分割窗口并跳转到光标所在标识符定义处。
ctrl-t跳回去。
:tag xxx跳转到xxx定义处。
:stag xxx分割窗口并跳转到xxx定义处。
:tags显示跳转历史。
:tag跳转到跳转历史的最后一条。
: tnext下一个。
: tprev上一个。
:tfirst第一个tag。
:tlast最后一个tag。
:tag xxx_<Tab>自动补全。
:tag /xxxx搜索而不是完全匹配。
其它用法:
:help tag
cscope
vim默认支持cscopehttp://cscope.sourceforge.net
1.安装cscope
sudo apt-get install cscope
2.生成cscope数据库文件
cscope -Rbq -f xxx.out
也可根据文件列表生成cscope数据库文件。这样可以排除源码目录中某些不想要的源码文件。
cscope -bqk -i cs.files
对于linux kernel,应该指定“k”选项:
cscope -Rbqk -f xxx.out
另外,对于linux kernel,有更简单的方法:
make cscope ARCH=arm64
在vim中使用cscope
加载cscope数据库文件::cs add ~/xxx/cscope.out
如果cscope数据库文件在当前目录,是可以自动加载的。
:cs help
:cs find c/d/e/f/g/i/s/t
:help cs
cscope的快捷键
有一个插件,将cs命令映射成快捷键。http://cscope.sourceforge.net/cscope_maps.vim
下载这个插件,放到~/.vim/plugin/目录下,可以使用快捷键。
ctrl-\ c
ctrl-\ d
......
附A:生成文件列表的一种方法
find . \ -path "./arch/*" ! -path "./arch/arm64/*" -prune -o \ -path "./Documentation*" -prune -o \ -path "./scripts*" -prune -o \ -name "*.[chxsS]" -print > cs.files
附B:vim之于程序的其他常用方法
[I查找全局标识符定义。这个命令不依赖ctags,而是在当前文件和include的文件中搜索。
[<Tab>查找全局标识符定义并直接跳转到第一个匹配的。
3[<Tab>跳转到第3个匹配的。
[i只列出第一个匹配的。
]I只列出当前光标之后的匹配项。
]i只列出当前光标之后的第一个匹配项。
[D只查找以”#define”定义的宏。
[d只列出第一个匹配。
]D只列出当前光标之后的匹配。
]d只列出当前光标之后的第一个匹配。
gD与
[I类似,但只搜索当前文件,不搜索include的文件。
gd只在当前函数中查找。
[#跳转到#if或#ifdef。
]#跳转到#else或#endif。
[[跳转到代码块开头。
][跳转到代码块结尾。
[{跳转到代码块开头,但越过平级的代码块。
]}跳转到代码快几位,但越过平级的代码块。
[]上一个函数的结尾。
]]下一个函数的开始。
[m上一个成员函数的开头。
]m下一个成员函数的开头。
[/注释的开头。
]/注释的结尾。
相关文章推荐
- [Ubuntu] Easy PHP Debugging in Ubuntu (using Xdebug and Vim)
- Model View Controller (MVC) Using C#, Delegates and Events in .NET
- Understanding and Using Assemblies and Namespaces in .NET
- Build Google IG like Ajax Start Page in 7 days using ASP.NET Ajax and .NET 3.0
- Creating custom headers and footers in Application level events using global.asax
- Build Google IG like Ajax Start Page in 7 days using ASP.NET Ajax and .NET 3.0(转)
- Using NMock and DynamicMocks in Test Driven Development
- Build Google IG like Ajax Start Page in 7 days using ASP.NET Ajax and .NET 3.0
- Display MS Excel Sheets and Charts in ASPX Pages using C#[favorite]
- How to read and save Images in a Sql Server Database using ADO.NET and C#
- Using WebLogic Server Clusters , Failover and Replication in a Cluster
- Using and Programming Generics in J2SE 5.0
- [收藏]Using Mozilla in testing and debugging web sites
- Using the Web Services and COM+ Event System in the .Net Application.
- How-To : Using EJB 3.0 and Java Persistence API with Spring in OC4J
- Add COM and ActiveX Support in .NET Compact Framework Using Odyssey Software CFCOM
- using JS to control two select(html),the data can be loaded from database and XML,and show in the select
- find element in both array and vector using one myfind function
- vim + ctags + taglist + cscope + cppcomplete + global 使用初探zz
- URL重写Using Sessions and Session Persistence in Web Applications