动态加载cscope.out,我的脚本哪里写错了,请帮忙看下
来自: Alan 2012-09-03 11:06:40
vimer初成长有问题请教大家,谢谢了先。
在项目的任一级的子目录中动态加载cscope.out
即 cs add [path/to/cscope.out]
发现vim中有一个 findfile命令,我在vim中实验,在项目的一个子目录中
:echo findfile("cscope.out", ".;") //从当前目录往上找,直到找到 cscope.out
这个命令能到找到cscope.out的路径。所以呢 我在vimrc中加入了如下脚本
set cscopequickfix=s-,c-,d-,i-,t-,e-
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
"add any database in current dir
if filereadable("cscope.out")
cs add cscope.out
"else search cscope.out elsewhere
else
let cscope_file=findfile("cscope.out", ".;")
if !empty(cscope_file) && filereadable(cscope_file)
exe "cs add" . cscope_file
endif
endif
set csverb
endif
但是每次进入一个项目的子目录下 cs show,都显示没有cscope.out connection。也许是我的脚本写的有问题吧。
请大家帮忙看看,给点意见
谢谢!
Alan 2012-09-03 13:23:02
ok,我找到方法了,一会我就传上来。
回应 赞
加州旅客 (:%s/party/freedom/g) 2012-09-03 13:35:21
vimrc只在刚启动的时候执行一遍,你这样写当然是不行的。
把代码放到一个函数里面,然后
:autocmd bufenter * call 函数名()
回应 赞
Alan 2012-09-04 21:48:24
vimrc只在刚启动的时候执行一遍,你这样写当然是不行的。 把代码放到一个函数里面,然后 :auto ... 加州旅客
谢谢回复,
但是,你也许没看清我的帖子~~
回应 赞
Alan 2012-09-04 21:50:04
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set csverb
set cspc=3
"add any database in current dir
if filereadable("cscope.out")
cs add cscope.out
"else search cscope.out elsewhere
else
let cscope_file=findfile("cscope.out", ".;")
let cscope_pre=matchstr(cscope_file, ".*/")
if !empty(cscope_file) && filereadable(cscope_file)
exe "cs add" cscope_file cscope_pre
endif
endif
endif
vimrc中加上上面的脚本,就ok了
回应 赞
是谁在练太极 (花若盛开,清风自来。) 2012-09-06 18:12:19
新脚本可以,不过有个提示,按enter才能进,怎么去掉这个提示?
回应 赞
Alan 2012-09-19 09:21:15
新脚本可以,不过有个提示,按enter才能进,怎么去掉这个提示? 是谁在练太极
我突然想到了,你在
exe "cs add" cscope_file cscope_pre 这句话后面加一个 <CR> 试试,我没有试过啊。
回应 赞
是谁在练太极 (花若盛开,清风自来。) 2012-09-22 15:25:34
我突然想到了,你在 exe "cs add" cscope_file cscope_pre 这句话后面加一个 <CR> 试试, ... Alan
貌似不行,加上silent参数就可以了,不错的功能
回应 赞
是谁在练太极 (花若盛开,清风自来。) 2012-09-22 15:47:10
我突然想到了,你在 exe "cs add" cscope_file cscope_pre 这句话后面加一个 <CR> 试试, ... Alan
对了,突然想到同样逻辑也可以把filenametags(找文件用给力工具)加进去
回应 赞
Mraz 2012-09-25 10:47:38
@是谁在练太极
还有一个办法,可以将
"set cst
set csverb
set cspc=3 "
中的csverb改为nocsverb。
回应 赞
Mraz 2012-09-25 10:49:30
对了,突然想到同样逻辑也可以把filenametags(找文件用给力工具)加进去 是谁在练太极
我也正在尝试中,有結果了吱一声~~~