ctags vim csrope

来源:互联网 发布:司法拍卖淘宝网 编辑:程序博客网 时间:2024/05/02 07:42

1.vim

1.1 配置文件vim.rc

  • 查看配置信息

    vi --versionCompiled by root@apple.comNormal version without GUI.  Features included (+) or not (-):-arabic +autocmd ...system vimrc file: "$VIM/vimrc"   --系统配置user vimrc file: "$HOME/.vimrc"   --用户配置user exrc file: "$HOME/.exrc"fall-back for $VIM: "/usr/share/vim"
  • 配置文件见文后

1.2 cscope+ctags索引文件

cscope可以和ctags联合使用,就像sourceInsight一样使用,但是不用鼠标。

  • 检查cscope

    ctags --versioncscope --version
  • 生成符号文件

    #!/bin/shfind . -name "*.h" -or -name "*.c"  > cscope.files //要分析的文件cscope -bkq -i cscope.files ctags -R
  • 可以在vimrc中设置nmap快捷键

    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>
  • 常见操作

    把光标放到符号上:
    ctags: CTRL + ] 跳到定义处, CTRL + T 跳回上一处
    在命令模式输入 :cs 可以看到帮助,
    cscope:

    c: Find functions calling this functiond: Find functions called by this functione: Find this egrep patternf: Find this fileg: Find this definitioni: Find files #including this files: Find this C symbolt: Find assignments to

    例如: 使用 CTRL + _ 再按 g 即可查找定义。

1.3 系统头文件

例如:Mac OS的系统头文件在 /usr/include,那么:

ctags -I __THROW --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p --fields=+S  -R -f ~/.vim/systags /usr/include /usr/local/include

-I 忽略后面的字符串,-R 递归,-f 输出文件名,–c-kinds=+p 为原型生成tag,–langmap=c:+.h .h视为c文件而不是c++文件。

生成了:~/.vim/systags TAG文件。
在.vimrc添加:

set tags+=~/.vim/systags

cscope,把系统目录include加进去:
find /usr/include/ . -name ‘.c’ -or -name ‘.h’ > cscope.files

先写到这里。下次补充。

1.3 .vimrc配置文件

下面是Mac OS上的配置:

" Configuration file for vimset modelines=0     " CVE-2007-2438" Normally we use vim-extensions. If you want true vi-compatibility" remove change the following statements" set nocompatible  " Use Vim defaults instead of 100% vi compatibilityset backspace=2     " more powerful backspacing" 语法高亮syntax on" 行号set nu" 高亮当前行set cursorlinehi CursorLine  cterm=NONE   ctermbg=darkred ctermfg=whitehi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white" c语言风格缩进set cindent" 智能缩进set smartindentset showmatchset incsearch" cscope confignmap <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>set cscopequickfix=s-,c-,d-,i-,t-,e-cs add cscope.outset nocpfiletype plugin on " mniCppComplete let OmniCpp_NamespaceSearch = 1 let OmniCpp_GlobalScopeSearch = 1 let OmniCpp_ShowAccess = 1 let OmniCpp_MayCompleteDot = 1 let OmniCpp_MayCompleteArrow = 1 let OmniCpp_MayCompleteScope = 1 let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"] set shiftwidth=4set ruler" set tabstop=4set titleset hlsearchset smarttab"set fdm=indentfiletype onset autoindentset autochdirset tags=tags;set filetype=pythonau BufNewFile,BufRead *.py,*.pyw setf pythonset autoindent " same level indent"set autoindent " next level indentset shiftwidth=4set softtabstop=4set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s"set ts=4set expandtabset nofoldenable" taglist 配置let Tlist_Ctags_Cmd='/usr/local/Cellar/ctags/5.8_1/bin/ctags'let Tlist_Show_One_File=1let Tlist_Exit_OnlyWindow=1let Tlist_Use_Right_Window=1" Don't write backup file if vim is being called by "crontab -e"au BufWrite /private/tmp/crontab.* set nowritebackup nobackup" Don't write backup file if vim is being called by "chpass"au BufWrite /private/etc/pw.* set nowritebackup nobackup
0 0
原创粉丝点击