Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213704
  • 博文数量: 60
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 119
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-07 09:40
个人简介

爱编程、爱生活

文章分类

全部博文(60)

文章存档

2018年(6)

2017年(4)

2015年(50)

分类: C/C++

2015-01-07 18:30:51

原文地址:用cscope和vim读源码; 作者:mingjwan

目标:对于多个子项目,有自己的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;


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