请教高手,vim+ctags如何查找一个tag的所有引用,而不是定义。

就呆在云上 2010-07-20 09:40:57
请教高手,vim+ctags如何查找一个tag的所有引用,而不是定义。
比如我定义了一个函数,abc()
我要查找整个工程里面都有些谁引用了我的abc函数,怎么弄?
...全文
1961 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
remygo 2013-03-05
  • 打赏
  • 举报
回复
:cs add cscope.out时,用绝对路径。:cs add /xxx/xxx/xxx/cscope.out
leemeng0x61 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mymtom 的回复:]
引用楼主 ztz0223 的回复:
请教高手,vim+ctags如何查找一个tag的所有引用,而不是定义。
比如我定义了一个函数,abc()
我要查找整个工程里面都有些谁引用了我的abc函数,怎么弄?

加装cscope

cscope commands:
add : Add a new database (Usage: add file|dir [pre……
[/Quote]


cs f t xxxxx
mymtom 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用楼主 ztz0223 的回复:]
请教高手,vim+ctags如何查找一个tag的所有引用,而不是定义。
比如我定义了一个函数,abc()
我要查找整个工程里面都有些谁引用了我的abc函数,怎么弄?
[/Quote]
加装cscope

cscope commands:
add : Add a new database (Usage: add file|dir [pre-path] [flags])
find : Query for a pattern (Usage: find c|d|e|f|g|i|s|t name)
c: Find functions calling this function
d: Find functions called by this function
e: Find this egrep pattern
f: Find this file
g: Find this definition
i: Find files #including this file
s: Find this C symbol
t: Find assignments to
help : Show this message (Usage: help)
kill : Kill a connection (Usage: kill #)
reset: Reinit all connections (Usage: reset)
show : Show connections (Usage: show)
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
先谢谢各位
Coder_Granger 2010-07-20
  • 打赏
  • 举报
回复
cscope会把cscope.out所在目录当作当前目录,所以find时使用相对路径没有问题.

只要所有命令都在源码目录下执行就可以了,cscope.out生成后不要移动到别的地方.

cd /azuo/freebsd4.4
find ....
cscope ....
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
我觉得在find操作时候应该用绝对路径:

find /azuo/freebsd4.4 -name "*.h" -o -name "*.c" -o -name ”*.cc” > cscope.files

用.这个相对路径好像不能达到全路径。
Coder_Granger 2010-07-20
  • 打赏
  • 举报
回复
if filereadable("/aaa/bbb/ccc/cscope.out")
cs add /aaa/bbb/ccc/cscope.out
endif

if filereadable("/aaa/bbb/ddd/cscope.out")
cs add /aaa/bbb/ddd/cscope.out
endif

if filereadable("/aaa/bbb/eee/cscope.out")
cs add /aaa/bbb/eee/cscope.out
endif
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 coder_granger 的回复:]
if filereadable("cscope.out")

这里也写绝对路径了吗?
[/Quote]

没有,那如果我有很多个工程的cscope文件怎么办呢?

写很多个:
if filereadable("cscope1.out")
cs add cscope1.out
"这里可以写绝对路径
endif

if filereadable("cscope2.out")
cs add cscope2.out
"这里可以写绝对路径
endif

还是怎么的呢?
如果能解决我就太谢谢你了,明天就給你加分到100分。
Brilliancer 2010-07-20
  • 打赏
  • 举报
回复
此贴收藏~~learn more
Coder_Granger 2010-07-20
  • 打赏
  • 举报
回复
if filereadable("cscope.out")

这里也写绝对路径了吗?
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 coder_granger 的回复:]
引用 10 楼 ztz0223 的回复:
哈哈
我知道怎么玩了,呵呵
直接用ctrl \ 再加一个c哈哈。

谢谢楼上的各位,我上面说的路径问题能解决否?

我在out文件的路径下面vim net/if.c可以用cscope
我cd net再vim if.c就不行了,如何解决哈?


写绝对路径就可以了
[/Quote]

我就是写的绝对路径哈,奇怪的问题。
Coder_Granger 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 ztz0223 的回复:]
哈哈
我知道怎么玩了,呵呵
直接用ctrl \ 再加一个c哈哈。

谢谢楼上的各位,我上面说的路径问题能解决否?

我在out文件的路径下面vim net/if.c可以用cscope
我cd net再vim if.c就不行了,如何解决哈?
[/Quote]

写绝对路径就可以了
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
顶一个
希望有人帮助我
同时感谢帮助过我的persons
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复

哈哈
我知道怎么玩了,呵呵
直接用ctrl \ 再加一个c哈哈。

谢谢楼上的各位,我上面说的路径问题能解决否?

我在out文件的路径下面vim net/if.c可以用cscope
我cd net再vim if.c就不行了,如何解决哈?
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
if has("cscope")
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>i :cs find i <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
if filereadable("cscope.out")
cs add cscope.out
"这里可以写绝对路径
endif
endif

谢谢楼上的哥们

你能帮我解释一下你设置的几个快捷键都是怎么用哈?

还有写out文件的绝对路径是新加一行否:
cs add cscope.out //原来的不变,新加一行否?
cs add /azuo/freebsd4.4/cscope.out
Coder_Granger 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ztz0223 的回复:]

引用 6 楼 coder_granger 的回复:
cscope add xxx不是在console里输入,是在vim里输入 :cs add xxx


我现在是在vim里面输入了,但是如果从cscope.out目录下面开始打开文件那么也可以用cscope
但是我进入子目录再用cscope就不行了。

还有是不是我每次打开文件都要输入cs add xxx?
有没有好的办法?
[/Quote]

每次打开文件都要执行:cs add xxx,
你可以把那个写到配置文件里去,我是这么写的,
顺便把cs find type xxx都绑定到快捷键了.
if has("cscope")
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>i :cs find i <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
if filereadable("cscope.out")
cs add cscope.out
"这里可以写绝对路径
endif
endif
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 coder_granger 的回复:]
cscope add xxx不是在console里输入,是在vim里输入 :cs add xxx
[/Quote]

我现在是在vim里面输入了,但是如果从cscope.out目录下面开始打开文件那么也可以用cscope
但是我进入子目录再用cscope就不行了。

还有是不是我每次打开文件都要输入cs add xxx?
有没有好的办法?
Coder_Granger 2010-07-20
  • 打赏
  • 举报
回复
cscope add xxx不是在console里输入,是在vim里输入 :cs add xxx
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
我现在是打开vim之后然后输入:
: cs add /azuo/freebsd4.4/cscope.out
就可以查找了
现在有一个问题了

如果是我在cscope.out的目录下面用vim 打开net文件夹下面的if.c然后用cs find c xxxx都是可以的,能查找。
vim net/if.c
这样可以。

然后我进入net文件夹再vim 打开if。c就不能用cscope了。
cd net
vim if.c
这样不行。提示
E567: no cscope connections
谁教教我怎么弄哈。
谢谢咯
就呆在云上 2010-07-20
  • 打赏
  • 举报
回复
我的操作如下:

[root@BTazuo ~]# cd /azuo
[root@BTazuo azuo]# cd freebsd4.4/
[root@BTazuo freebsd4.4]# ls -la
total 3592
drwxr-xr-x 32 nobody nobody 4096 Jul 20 21:46 .
drwxrwxrwx 4 root root 4096 Jul 20 21:46 ..
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 compile
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 conf
drwxr-xr-x 3 nobody nobody 4096 Jul 19 23:32 dev
drwxr-xr-x 4 nobody nobody 4096 Jul 19 23:32 hp
drwxr-xr-x 9 nobody nobody 4096 Jul 19 23:32 hp300
drwxr-xr-x 11 nobody nobody 4096 Jul 19 23:32 i386
drwxr-xr-x 3 nobody nobody 4096 Jul 19 23:32 isofs
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 kern
drwxr-xr-x 3 nobody nobody 4096 Jul 19 23:32 libkern
drwxr-xr-x 9 nobody nobody 4096 Jul 19 23:32 luna68k
drwxr-xr-x 3 nobody nobody 4096 Jul 19 23:32 mips
drwxr-xr-x 12 nobody nobody 4096 Jul 19 23:32 miscfs
drwxr-xr-x 2 nobody nobody 4096 Jul 20 21:40 net
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 netccitt
drwxr-xr-x 2 nobody nobody 4096 Jul 20 19:38 netinet
drwxr-xr-x 3 nobody nobody 4096 Jul 19 23:32 netiso
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 netns
drwxr-xr-x 13 nobody nobody 4096 Jul 19 23:32 news3400
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 nfs
drwxr-xr-x 9 nobody nobody 4096 Jul 19 23:32 pmax
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 scripts
drwxr-xr-x 10 nobody nobody 4096 Jul 19 23:32 sparc
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 stand
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 stand.att
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:32 sys
-rw-r--r-- 1 root root 3541569 Jul 20 19:38 tags
drwxr-xr-x 12 nobody nobody 4096 Jul 19 23:32 tahoe
drwxr-xr-x 7 nobody nobody 4096 Jul 19 23:31 tests
drwxr-xr-x 6 nobody nobody 4096 Jul 19 23:31 ufs
drwxr-xr-x 14 nobody nobody 4096 Jul 19 23:31 vax
drwxr-xr-x 2 nobody nobody 4096 Jul 19 23:31 vm
[root@BTazuo freebsd4.4]#

find . -name ”*.h” -o -name ”*.c” -o -name ”*.cc” > cscope.files
cscope -Rbkq -P /azuo/freebsd4.4 -i cscope.files

生成cscope.out后,我在命令行里面输入

[root@BTazuo azuo]# cscope add /azuo/freebsd4.4/cscope.out
然后,我打开vim,在里面输入:
:cs find c sqlx
提示
E567: no cscope connections
是不是我的操作不对哈?
谢谢各位。

23,116

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧