ctag cscope 工程使用心得
[user:test] ls
1111/ 2.txt a.out* good/ goog/ main.cpp Makefile
[user:test] tree
.
├── 1111
│ └── 1.txt
├── 2.txt
├── a.out
├── good
│ ├── print.cpp
│ └── print.h
├── goog
│ └── test.cpp
├── main.cpp
└── Makefile
3 directories, 8 files
第一步,写Makefile:
[user:test] cat Makefile
RM = /bin/rm -rf
FIND = /usr/bin/find
CTAGS = /usr/bin/ctags --c++-kinds=+p --c-kinds=+px-n --fields=+iatfS --extra=+q -I __wur,__THROW,__nonnull+
CSCOPE = /usr/bin/cscope -bkq
tag:
$(RM) tags
$(RM) cscope.*
$(FIND) . -name '*.[ch]' -exec realpath {} + >> cscope.list; \
$(FIND) . -name '*.cpp' -exec realpath {} + >> cscope.list; \
$(CTAGS) -L cscope.list -f tags;
$(CSCOPE) -icscope.list -fcscope.out;
$(RM) cscope.list
[user:test]
第二步,在~/.vimrc中使用自动运行cscope.out:
" auto load cscope.out
if has("cscope")
if has("win32")
set csprg=e:\cygwin\root\bin\mlcscope.exe
endif
set cscopetag " When using :tag, <C-]>, or "vim -t", try cscope:
set cscopetagorder=0 " try ":cscope find g foo" and then ":tselect foo"
set csto=1
set cspc=5
set nocsverb
if filereadable("./cscope.out")
execute 'cscope add ./cscope.out'
elsei filereadable("../cscope.out")
execute 'cscope add ../cscope.out'
elsei filereadable("../../cscope.out")
execute 'cscope add ../../cscope.out'
endif
if filereadable("~/.vim/tags/libc.out")
execute 'cscope add ~/.vim/tags/libc.out'
endif
endif
第三步,查看目录生成:
[user:test] make
/bin/rm -rf tags
/bin/rm -rf cscope.*
/usr/bin/find . -name '*.[ch]' -exec realpath {} + >> cscope.list; \
/usr/bin/find . -name '*.cpp' -exec realpath {} + >> cscope.list; \
/usr/bin/ctags --c++-kinds=+p --c-kinds=+px-n --fields=+iatfS --extra=+q -I __wur,__THROW,__nonnull+ -L cscope.list -f tags;
/usr/bin/cscope -bkq -icscope.list -fcscope.out;
/bin/rm -rf cscope.list
[user:test] ls
1111/ 2.txt a.out* cscope.out cscope.out.in cscope.out.po good/ goog/ main.cpp Makefile
tags
[user:test]
cscope.out 和tags已生成,大功告成,打开vim自动寻找cscope.out和运行.
(具体是什么意思google一下就好了.)