ctag cscope 工程使用心得

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:

"" tag-commands 使用tag命令(help tag查看相关命令)时会使用到tags这个文件, 如: CTRL-]

"""" Tags
set tags=./tags;/home       " Tags can be in ./tags, ../tags, ..., /home/tags.
set showfulltag             " Show more information while completing tags.
if has("win32")
    set path=.
    set tag=tags,
else
    set tag=tags,../tags,../../tags,~/.vim/tags/libc.tags
    " set autochdir
    "set tag=tags,~/.vim/tags/libc.tags,~/.vim/tags/libminigui.tags,
    "set path =.,./include,/usr/include/,/usr/include/linux/,/usr/include/sys,
endif


"" cscope-commands 使用cs命令(help cs查看相关命令)时会使用到cscope.out这个文件, 如:cs find s

" 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


""键盘映射

""找这个标号
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>

""找调用此函数的实现
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>

""找调用此函数的地方
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>

""找到所有包含这个字符串的地方
nmap <C-\>t :cs find t <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-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>

 

第三步,查看目录生成: 

[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一下就好了.)

你可能感兴趣的:(ctags,cscope)