Chinaunix首页 | 论坛 | 博客
  • 博客访问: 272704
  • 博文数量: 124
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 21
  • 用 户 组: 普通用户
  • 注册时间: 2016-08-20 14:44
文章分类

全部博文(124)

文章存档

2020年(1)

2018年(2)

2016年(2)

2015年(6)

2014年(10)

2013年(23)

2012年(7)

2011年(18)

2010年(15)

2009年(8)

2007年(8)

2006年(23)

2005年(1)

我的朋友

分类: C/C++

2013-12-09 21:35:26

目标:对于多个子项目,有自己的cscope.out文件,当在父目录中打开im时,自动加载所有子工程的cscope;
为了便于单独管理cscope的配置文件,单独建立了cscope目录,设置~/cscope,下面在根据项目名字建立子目录;

1. cscope.out的文件的建立;
     在子目录中 运行 find /src_dir -name "*.cpp" -o -name "*.c" -o -name "*.h" > cscope.files; (由于src和cscope文件不在一个目录,所以find时写绝对路径;
     运行cscope -Rbkq 产生cscope.out 文件

2. 编写.vimrc文件
    为了编辑其他文件时不加载cscope文件,所以.vimrc分为两个部分
  1. ~/.vimrc 文件,供vim自动加载;
  2. ~/cscope/.vimrc文件,供加载cscope文件;

  3. 点击(此处)折叠或打开

    1. function Checkcscope()
    2.    let cscope="/home/test/code/cscope"
    3.    let pwd=getcwd()
    4.    let iscscope=stridx(pwd,cscope)
    5.    if iscscope==0
    6.         :execute "source". cscope. "/.vimrc"
    7.    endif
    8. endfunction
    9. :call Checkcscope()

    点击(此处)折叠或打开

    1. let files=findfile("cscope.out",".,*",-1)
    2. for f in files
    3.    :execute "cs add ". f
    4. endfor
    5. nmap <C-@>s :cs find s <C-R>=expand("")<CR><CR>
    6. nmap <C-@>g :cs find g <C-R>=expand("")<CR><CR>
    7. nmap <C-@>c :cs find c <C-R>=expand("")<CR><CR>
    8. nmap <C-@>t :cs find t <C-R>=expand("")<CR><CR>
    9. nmap <C-@>e :cs find e <C-R>=expand("")<CR><CR>
    10. nmap <C-@>f :cs find f <C-R>=expand("")<CR><CR>
    11. nmap <C-@>i :cs find i ^<C-R>=expand("")<CR>$<CR>
    12. nmap <C-@>d :cs find d <C-R>=expand("")<CR><CR>
    代码关键: findfile的第二个参数用“.,*"表示在当前目录和子目录中搜索文件;path是用逗号隔开的,这有点不一样;
    对于cs的调用,使用execute来拼接后运行的。因为cs 命令后直接跟文件名,而不支持变量。所以要先拼接出命令,然后在execute;


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

mingjwan2014-04-12 22:26:40

C-T 可以回退,这是 im的一个通用快捷键!

knull2014-01-04 15:39:06

cscope+vim,根据网上的资料,配置好了之后,用了近2个月(当时出差,工作,带自己的电脑,所以用的VIM)。
用的感觉是:可以用,但是,真的不如souceinsight(可能是因为用惯了)。
但是,如果vim还是有优势的:就是可以纯粹的键盘操作,而不需要鼠标(似乎以前的*nix牛人都这样的。。。)

leadsec1112013-12-10 15:21:34

文明上网,理性发言...