vim ctags cscope使用记录

ctags:

~/.vimrc内容如下:

"Highlight all search pattern matches
set hls
"Map F12 to create ctags index in current directory
map <F12> :!ctags -R <CR><CR>
"A shotcut to execute the grep command
map mg :!grep <C-R><C-W> . -r <CR>
"change the comment color
hi Comment ctermfg=6

解释如下:

  • set hls,看代码时,使用‘/’或者‘#’搜索指定的关键字时,高亮得到的所有结果
  • map <F12> :!ctags -R <CR><CR> ,重映射F12键,这样可以一键在当前目录下创建ctags的索引
  • map mg :!grep <C-R><C-W> . -r <CR>,一个执行grep命令的快捷方式。编写、查看代码时,敲击’mg’两个字母,即可直接grep光标所在位置的单词
  • hi Comment ctermfg=6,看代码时,默认的注释颜色为深蓝色,看着太吃力了,改为浅蓝色,就好看多了

cscope:

~/.vimrc内容如下:

if has("cscope") && filereadable("/usr/bin/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
endif

nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i <C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>

解释如下:

  • s:查找C代码符号
  • g:查找本定义
  • d:查找本函数调用的函数
  • c:查找调用本函数的函数
  • t:查找本字符串
  • e:查找本egrep模式
  • f:查找本文件
  • i:查找包含本文件的文件

Note:

make cscope

含义解释:
<C-R>=是什么意思?赋值语句?<C-R>是插入某个寄存器值的意思,=是表达式寄存器的意思。所以这句话是在命令行插入expand("<cword>")的值,也就是当前光标下的单词。
其实在<C-R>后再输入<C-W>就是当前光标下单词的意思,<C-R><C-W>与<C-R>=expand("<cword>")应该是等效的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值