介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

Vim、Emacs配置和使用
回复
头像
adam8157
帖子: 2794
注册时间: 2009-03-05 16:31
联系:

介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#1

帖子 adam8157 » 2010-04-24 22:15

翻遍了google上关于cscope的介绍, 也没找到这个设置技巧, 都是要求在项目根目录生成, 项目根目录打开vim...我懒啊....

麻烦, 于是自己憋着想写一个, 写了一半, 试了下去官网搜索, 竟然有!!

autoload_cscope.vim

http://www.vim.org/scripts/script.php?script_id=157

就像ctags设定set tags=tags; 在项目根目录生成总的tags, 任意子目录下即可自动加载...

用了这个插件, 项目根目录生成cscope.out, 随便钻到哪个项目子目录下, 自动正常加载, 正常搜索...

Tips:

代码: 全选

alias更方便
alias cr='ctags -R --fields=+lS && cscope -Rbq'
这个全局变量设置下, 禁止这个插件自带的mapping
let g:autocscope_menus=0
config:

代码: 全选

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Cscope
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Use both cscope and ctag
set cscopetag

" Show msg when cscope db added
set cscopeverbose

" Use tags for definition search first
set cscopetagorder=1

" Use quickfix window to show cscope results
set cscopequickfix=s-,c-,d-,i-,t-,e-

" Cscope mappings
nnoremap <C-w>\ :scs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nnoremap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nnoremap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
problem:
我启用了cscope的quickfix, 但是它的反应和tags不一样, 不是开个quickfix窗口让你选, 而是直接跳到第一个, 虽然你可以自己打开quickfix窗口...绑定和手动都是这样...
头像
速腾1994
论坛版主
帖子: 17379
注册时间: 2008-11-01 20:43
系统: Arch+gnome

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#2

帖子 速腾1994 » 2010-04-24 22:17

绑定!
头像
Fermat618
帖子: 728
注册时间: 2008-12-28 16:01

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#3

帖子 Fermat618 » 2012-03-20 1:49

原来还有这个插件,我自己写了几行内嵌的python做好了。
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
头像
adam8157
帖子: 2794
注册时间: 2009-03-05 16:31
联系:

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#4

帖子 adam8157 » 2012-03-20 10:35

Fermat618 写了:原来还有这个插件,我自己写了几行内嵌的python做好了。
分享看看, 可以不
头像
Fermat618
帖子: 728
注册时间: 2008-12-28 16:01

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#5

帖子 Fermat618 » 2012-03-20 14:22

adam8157 写了:
Fermat618 写了:原来还有这个插件,我自己写了几行内嵌的python做好了。
分享看看, 可以不

代码: 全选

        py3 <<EOF
import os, os.path
from itertools import takewhile
def iterate(fun, x):
    yield x
    for element in iterate(fun, fun(x)):
        yield element
for path in takewhile(lambda x: x!=os.path.dirname(x), iterate(os.path.dirname, os.getcwd())):
    cscopefile = os.path.join(path, 'cscope.out')
    if os.access(cscopefile, os.R_OK): # file readable
        vim.command('cscope add ' + cscopefile +' '+ path)
        break
EOF
需要你的vim有python3支持。有python2可能也没啥问题吧。python写起东西来快,我一些vim中的问题,现在也用python来写了。

PS: 修改了一下,避免硬编码某些字符,使得在各个平台下兼容。
上次由 Fermat618 在 2012-03-21 21:04,总共编辑 3 次。
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#6

帖子 lilydjwg » 2012-03-20 16:19

Fermat618 写了:
adam8157 写了:
Fermat618 写了:原来还有这个插件,我自己写了几行内嵌的python做好了。
分享看看, 可以不

代码: 全选

        py3 <<EOF
import os, os.path
from itertools import takewhile
def iterate(fun, x):
    yield x
    for element in iterate(fun, fun(x)):
        yield element
for path in takewhile(lambda x: x!='/', iterate(os.path.dirname, os.getcwd())):
    cscopefile = os.path.join(path, 'cscope.out')
    if os.access(cscopefile, os.R_OK): # file readable
        vim.command('cscope add ' + cscopefile +' '+ path)
        break
EOF
需要你的vim有python3支持。有python2可能也没啥问题吧。python写起东西来快,我一些vim中的问题,现在也用python来写了。
我也写过类似的东西。你这样到 Windows 下 for 循环就出不来了。
头像
Fermat618
帖子: 728
注册时间: 2008-12-28 16:01

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#7

帖子 Fermat618 » 2012-03-21 18:57

lilydjwg 写了:
Fermat618 写了:
adam8157 写了:
Fermat618 写了:原来还有这个插件,我自己写了几行内嵌的python做好了。
分享看看, 可以不

代码: 全选

        py3 <<EOF
import os, os.path
from itertools import takewhile
def iterate(fun, x):
    yield x
    for element in iterate(fun, fun(x)):
        yield element
for path in takewhile(lambda x: x!='/', iterate(os.path.dirname, os.getcwd())):
    cscopefile = os.path.join(path, 'cscope.out')
    if os.access(cscopefile, os.R_OK): # file readable
        vim.command('cscope add ' + cscopefile +' '+ path)
        break
EOF
需要你的vim有python3支持。有python2可能也没啥问题吧。python写起东西来快,我一些vim中的问题,现在也用python来写了。
我也写过类似的东西。你这样到 Windows 下 for 循环就出不来了。
又是windows那变态的路径分隔符。让它在windows下死循环去吧。
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
头像
fanhe
帖子: 2357
注册时间: 2007-03-24 23:45

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#8

帖子 fanhe » 2012-03-21 19:37

Fermat618 写了:
lilydjwg 写了:
Fermat618 写了:
adam8157 写了:
Fermat618 写了:原来还有这个插件,我自己写了几行内嵌的python做好了。
分享看看, 可以不

代码: 全选

        py3 <<EOF
import os, os.path
from itertools import takewhile
def iterate(fun, x):
    yield x
    for element in iterate(fun, fun(x)):
        yield element
for path in takewhile(lambda x: x!='/', iterate(os.path.dirname, os.getcwd())):
    cscopefile = os.path.join(path, 'cscope.out')
    if os.access(cscopefile, os.R_OK): # file readable
        vim.command('cscope add ' + cscopefile +' '+ path)
        break
EOF
需要你的vim有python3支持。有python2可能也没啥问题吧。python写起东西来快,我一些vim中的问题,现在也用python来写了。
我也写过类似的东西。你这样到 Windows 下 for 循环就出不来了。
又是windows那变态的路径分隔符。让它在windows下死循环去吧。
你至少应该用 os.sep
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#9

帖子 lilydjwg » 2012-03-21 19:57

fanhe 写了: 你至少应该用 os.sep
不行的,因为还有盘符。
头像
Fermat618
帖子: 728
注册时间: 2008-12-28 16:01

Re: 介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

#10

帖子 Fermat618 » 2012-03-21 20:52

fanhe 写了:
Fermat618 写了:
lilydjwg 写了:
Fermat618 写了:
adam8157 写了:
Fermat618 写了:原来还有这个插件,我自己写了几行内嵌的python做好了。
分享看看, 可以不

代码: 全选

        py3 <<EOF
import os, os.path
from itertools import takewhile
def iterate(fun, x):
    yield x
    for element in iterate(fun, fun(x)):
        yield element
for path in takewhile(lambda x: x!='/', iterate(os.path.dirname, os.getcwd())):
    cscopefile = os.path.join(path, 'cscope.out')
    if os.access(cscopefile, os.R_OK): # file readable
        vim.command('cscope add ' + cscopefile +' '+ path)
        break
EOF
需要你的vim有python3支持。有python2可能也没啥问题吧。python写起东西来快,我一些vim中的问题,现在也用python来写了。
我也写过类似的东西。你这样到 Windows 下 for 循环就出不来了。
又是windows那变态的路径分隔符。让它在windows下死循环去吧。
你至少应该用 os.sep
当初就没想到过这问题。

用 lambda x: x != os.path.dirname(x) 这个可以。
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
回复