代码
使用方法:直接拷贝代码到文件,命名为.vimrc
代替~/.vimrc
即可
配合cscope
使用起来看内核代码用的很舒服.
syntax on
"""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""
"cscope setting
"""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""
if has("cscope")
set csprg=/usr/local/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
"cs add /Users/chenming/Developing/demo/jasper-2.0.14/cscope.out
let csfilelist = []
let csfilecursor = -1
function CmCscopeFind(type,symbol)
:call add(g:csfilelist,@%)
:call add(g:csfilelist,line("."))
:call add(g:csfilelist,a:symbol)
:let g:csfilecursor = (len(g:csfilelist) / 3) - 1
:exec "cs find " . a:type . " " . a:symbol
endfunction
function CmJumpBackFile()
if g:csfilecursor == -1
else
if g:csfilecursor > 0
let g:csfilecursor -= 1
:call CmJumpFile()
endif
endif
endfunction
function CmJumpForwardFile()
if g:csfilecursor == -1
return
endif
if g:csfilecursor < (( len(g:csfilelist) / 2 ) - 1 )
let g:csfilecursor += 1
:call CmJumpFile()
endif
endfunction
function CmJumpFile()
if len(g:csfilelist) > 1
:exec "vi! +" . g:csfilelist[3 * g:csfilecursor + 1] . " " . g:csfilelist[3 * g:csfilecursor]
else
:echo "no file in csfilelist!"
endif
endfunction
function CmCscopeHelp()
:echo "<C-f>s: Find this C symbol"
:echo "<C-f>g: Find this definition"
:echo "<C-f>a: Find assignments to this symbol"
:echo "<C-f>c: Find functions calling this function"
:echo "<C-f>i: Find files #including this file"
:echo "<C-f>t:Find this text string"
:echo "<C-f>d:Find functions called by this function"
endfunction
function CmShowFileList()
let i = 0
while i < (len(g:csfilelist) / 3)
:echo i . ". " . g:csfilelist[3 * i + 2] . "\t\t[" . g:csfilelist[3 * i] . ":" . g:csfilelist[3 * i + 1] . "]"
let i += 1
endwhile
:let index = input("please enter index:")
if (index < 0 || index > ((len( g:csfilelist) / 3) - 1))
return
endif
let g:csfilecursor = index
:call CmJumpFile()
endfunction
nmap <C-i> <esc>:call CmShowFileList()<cr>
nmap <C-n> <esc>:let @/ = "\\<" . expand("<cword>") . "\\>"<cr>
nmap <C-f> <esc>:call CmCscopeHelp()<cr>
nmap <C-f>w <esc>:call CmJumpBackFile()<cr>
nmap <C-f>b <esc>:call CmJumpForwardFile()<cr>
nmap <C-f>s <esc>:call CmCscopeFind("s",expand("<cword>"))<cr>
nmap <C-f>g <esc>:call CmCscopeFind("g",expand("<cword>"))<cr>
nmap <C-f>a <esc>:call CmCscopeFind("a",expand("<cword>"))<cr>
nmap <C-f>c <esc>:call CmCscopeFind("c",expand("<cword>"))<cr>
nmap <C-f>i <esc>:call CmCscopeFind("i",expand("<cword>"))<cr>
nmap <C-f>t <esc>:call CmCscopeFind("t",expand("<cword>"))<cr>
nmap <C-f>d <esc>:call CmCscopeFind("d",expand("<cword>"))<cr>
部署Taglist
$ mkdir -p $HOME/.vim/pack/downloads/start
$ cd $HOME/.vim/pack/downloads/start
$ git clone https://github.com/yegappan/taglist
使用说明
待补充