Chinaunix首页 | 论坛 | 博客
  • 博客访问: 168871
  • 博文数量: 50
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 123
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-01 16:03
文章分类

全部博文(50)

文章存档

2016年(3)

2015年(5)

2014年(35)

2013年(7)

我的朋友

分类: LINUX

2013-12-22 01:10:23

vi 使用技巧

1、sudo apt-get install ctags cscope 这个命令安装这两个工具软件.

2、在用户目录下创建 ~/.vimrc  文件,此文件在vi打开文件时候被调用。
        写入如下内容:
       

点击(此处)折叠或打开

  1. set number

  2. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  3. " cscope setting
  4. if has("cscope")
  5.     set csprg=/usr/bin/cscope
  6.     set csto=0
  7.     set cst
  8.     set csverb
  9.     set cspc=3
  10.     "add any database in current dir
  11.     if filereadable("cscope.out")
  12.         cs add cscope.out
  13.     "else search cscope.out elsewhere
  14.     else
  15.        let cscope_file=findfile("cscope.out", ".;")
  16.        let cscope_pre=matchstr(cscope_file, ".*/")
  17.        if !empty(cscope_file) && filereadable(cscope_file)
  18.            exe "cs add" cscope_file cscope_pre
  19.        endif
  20.      endif
  21. endif

  22. nmap <C-a>s :cs find s <C-R>=expand("")<CR><CR>
  23. nmap <C-a>g :cs find g <C-R>=expand("")<CR><CR>
  24. nmap <C-a>c :cs find c <C-R>=expand("")<CR><CR>
  25. nmap <C-a>t :cs find t <C-R>=expand("")<CR><CR>
  26. nmap <C-a>e :cs find e <C-R>=expand("")<CR><CR>
  27. nmap <C-a>f :cs find f <C-R>=expand("")<CR><CR>
  28. nmap <C-a>i :cs find i ^<C-R>=expand("")<CR>$<CR>
  29. nmap <C-a>d :cs find d <C-R>=expand("")<CR><CR>
  30. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

先按 Ctrl+a ,再按 s/g/c/t/e/f/i/d来完成 快捷键功能。

s:查找C语言符号,即查找函数名、宏、枚举值等出现的地方 
g:查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
d:查找本函数调用的函数 
c:查找调用本函数的函数 
t:查找指定的字符串
e:查找egrep模式,相当于egrep功能,但查找速度快多了 
f:查找并打开文件,类似vim的find功能 
i:查找包含本文件的文
当然在底行模式下介键入 help 会弹出 vim的帮助。

3、使用tags查找

ctrl+]:在函数调用的地方跳转到函数定义的地方
ctrl+t:返回上一个查找的地方

4、在工程目录下创建 cs.sh 文件。内容如下:

点击(此处)折叠或打开

  1. #!/bin/sh
  2. find `pwd` -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.java" > cscope.files
  3. cscope -bkq -i cscope.files
  4. ctags -R


阅读(1572) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~