diff --git a/.vim/plugin/cscope.vim b/.vim/plugin/cscope.vim new file mode 100644 index 0000000..f851a6c --- /dev/null +++ b/.vim/plugin/cscope.vim @@ -0,0 +1,103 @@ +" cscope keymaping plugin +" (a tool to browse through C source files) +" + +" if compiled with --enable-cscope +if has("cscope") + if exists("g:loaded_cscope") || &cp + finish + endif + let g:loaded_cscope = 1.0 + + function! GoToDefinition() + try + execute "cscope find g " . expand("") + catch /:E259:/ + try + execute "tag " . expand("") + catch /:E257:/ + execute "normal! gd" + execute "nohlsearch" + endtry + endtry + endfunction + + " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t' + set cscopetag + " use ctags before cscope + set csto=0 + " add any cscope database in current directory + if filereadable("cscope.out") + cscope add cscope.out + endif + " add the database pointed by environment variable. + " Cscope file added from db should contains full path to file. Otherwise they + " should be added with cscope add PATH_TO_CSCOPE_FILE PATH_TO_SRC_ROOT + if $CSCOPE_DB != "" + if filereadable($CSCOPE_DB) + cscope add $CSCOPE_DB + endif + endif + " show message when any other cscope db added + set cscopeverbose + " open include file with F4 and split with shift+F4 + nmap :cscope find f =expand("") + nmap :scscope find f =expand("") + " find this C symbol with F5 and split with shift+F5 + nmap :cscope find s =expand("") + nmap :scscope find s =expand("") + " go to definition with F6 and split with shift+F6 and use ctags with alt+shift+F6 + "nmap :cscope find g =expand("") + nmap :call GoToDefinition() + nmap :scscope find g =expand("") + nmap :tag =expand("") + " go to calls with F7 and split with shift+F7 + nmap :cscope find c =expand("") + nmap :scscope find c =expand("") + " go to ... with 'ctrl+s letter' and go back with ctrl+t + nmap s :cscope find s =expand("") + nmap g :cscope find g =expand("") + nmap c :cscope find c =expand("") + nmap t :cscope find t =expand("") + nmap e :cscope find e =expand("") + nmap f :cscope find f =expand("") + nmap i :cscope find i ^=expand("")$ + nmap d :cscope find d =expand("") + " split to ... with 'ctrl+space letter' + nmap s :scscope find s =expand("") + nmap g :scscope find g =expand("") + nmap c :scscope find c =expand("") + nmap t :scscope find t =expand("") + nmap e :scscope find e =expand("") + nmap f :scscope find f =expand("") + nmap i :scscope find i ^=expand("")$ + nmap d :scscope find d =expand("") + " vertical split to ... with 'ctrl+space ctrl+space letter' + nmap s :vertical scscope find s =expand("") + nmap g :vertical scscope find g =expand("") + nmap c :vertical scscope find c =expand("") + nmap t :vertical scscope find t =expand("") + nmap e :vertical scscope find e =expand("") + nmap f :vertical scscope find f =expand("") + nmap i :vertical scscope find i ^=expand("")$ + nmap d :vertical scscope find d =expand("") + " s symbol find all references to the token under cursor + " //find this C symbol + " g global find global definition of the token under cursor + " //find this definition + " c calls find all calls to the function name under cursor + " //find function calling this function + " d called find functions that function under cursor calls + " //find function called by this function + " t text find all instances of the text under cursor + " //find this text string + " e egrep egrep search for the word under cursor + " //find this egrep pattern + " f file open the filename under cursor + " //find this file + " i includes find files that include the filename under cursor + " //find files #including this file + + + +endif diff --git a/.vim/plugin/cscope_plus.vim b/.vim/plugin/cscope_plus.vim new file mode 100644 index 0000000..f4190ba --- /dev/null +++ b/.vim/plugin/cscope_plus.vim @@ -0,0 +1,40 @@ +" if compiled with --enable-cscope +if has("cscope") + if exists("g:loaded_cscope_plus") || &cp + finish + endif + let g:loaded_cscope_plus = 1.0 + + " cat Makefile | grep '\-I\/' | tr '[:space:]' '\n' | grep '\-I/' | sort -u | tr '\n' ' ' + " build tags database with shift+F8 or alt+F8 to ignore /usr/include + " --c++-kinds=+p : Adds prototypes in the database for C/C++ files. + " --fields=+iaS : Adds inheritance (i), access (a) and function + " signatures (S) information. + " --extra=+q : Adds context to the tag name. Note: Without this + " option, the script cannot get class members. + + command! CtagsBuild + \ :!echo 'building ctags database...' ; + \ ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p && + \ echo 'adding system headers...' ; + \ find -exec gcc -M '{}' \; 2>&- | tr '[:space:]' '\n' | grep '^/.*' | sort -u | + \ ctags --c-kinds=+px --c++-kinds=+px --fields=+iaS --extra=+q -aL- + command! CtagsKernelBuild + \ :!echo 'building ctags database in kernel mode...' ; + \ ctags --fields=+iaS --extra=+q --totals -R --c++-kinds=+p + command! CscopeBuild + \ :!echo 'building cscope database...' ; + \ cscope -bR + command! CscopeKernelBuild + \ :!echo 'building cscope database in kernel mode...' ; + \ cscope -bkR + + if has("cscope") + map :CtagsBuild:CscopeBuild:cscope reset:cscope add cscope.out + map :CtagsKernelBuild:CscopeKernelBuild:cscope reset:cscope add cscope.out + else + map :CtagsBuild + map :CtagsKernelBuild + endif + +endif diff --git a/.vimrc b/.vimrc index c411793..a3aa3fe 100644 --- a/.vimrc +++ b/.vimrc @@ -6,7 +6,13 @@ " S-F2 Split and open file " F3 autotags Update " S-F3 autotags Add +" F4 open include file +" F5 find C symbol +" F6 go to definition +" F7 go to calls " F8 view tag list +" S-F8 build ctags/cscope databases +" M-F8 build kernel ctags/cscope databases " F9 Open NerdTree " M-F9 Show diff line " S-F9 Highlight diff line @@ -171,6 +177,9 @@ endif map :tabe =expand("%:h") . "/" nmap :split =expand("%:h") . "/" +colorscheme desert +set nocursorline + """""""" " HELP " """"""""