====插件下载
网上自行下载taglist_46.zip和winmanager.zip,并解压缩到~/.vim下
解压后的~/.vim目录文件情况如下:
/home/hwcrm/.vim/
/home/hwcrm/.vim/plugin
/home/hwcrm/.vim/plugin/winfileexplorer.vim
/home/hwcrm/.vim/plugin/wintagexplorer.vim
/home/hwcrm/.vim/plugin/taglist.vim
/home/hwcrm/.vim/plugin/winmanager.vim
/home/hwcrm/.vim/doc
/home/hwcrm/.vim/doc/winmanager.txt
/home/hwcrm/.vim/doc/taglist.txt
====常用快捷键(vim的自行补习)
F8 #打开taglist、winmanager窗口
Ctrl+w*2 #切换taglist、winmanager和vim编辑窗口
Enter #在taglist窗口中可以调到对应的变量或函数,在winmanager窗口可以调到对应的文件
Ctrl+p #自动补全代码
Ctrl+] #跳转到函数/变量声明或实现的地方
Ctrl+t #返回到跳转前的地方
====非常用快捷键(均是Cscope快捷键,使用前都必须使光标定位在某个函数/变量上)
先按Ctrl+Shift+- 再按s “查找指定标识符的使用位置
先按Ctrl+Shift+- 再按g “查找指定标识符的定义位置
先按Ctrl+Shift+- 再按c “查找该函数被调用的位置
先按Ctrl+Shift+- 再按t “查找指定的文本字符串
先按Ctrl+Shift+- 再按e “查找指定的正规表达式
先按Ctrl+Shift+- 再按f “查找指定的文件
先按Ctrl+Shift+- 再按i “查找该文件在哪些地方被包含
先按Ctrl+Shift+- 再按d “查找该函数调用了哪些函数
====生效的前提条件,在代码的根目录执行如下指令
ctags -R –file-scope=yes –langmap=c:+.h –languages=c,c++ –links=yes –c-kinds=+p –c++-kinds=+p –fields=+iaS –extra=+q
find `pwd` -name "*.[ch]" -o -name "*.cpp" > cscope.files
cscope -Rbq
====.vimrc内容
"set term=vt100
set ts=4
set sw=4
"set fileencoding=utf-8
"set fileencoding=cp936
"set fileencodings=cp936
"set encoding=cp936
"set encoding=UTF-8
set autoindent
set showcmd
set nocompatible
set smartindent
set showmatch
set t_Co=8
set t_Sf=p1%dm
set t_Sb=p1%dm
map <C-J> :set filetype=cpp<CR>
set hls
set incsearch
set ruler
set path=.,/usr/include,include,inc,../include,../inc
set path+=/usr/local/SRBC2.0/include
set tags+=tags;
set backspace=indent,start,eol whichwrap+=<,>,[,]
if has("fname_case")
au BufNewFile,BufRead *.cxx,*.c++,*.C,*.H,*.hh,*.hxx,*.hpp,*.moc,*.tcc,*.inl,*.pc setf cpp
else
au BufNewFile,BufRead *.cxx,*.c++,*.hh,*.hxx,*.hpp,*.moc,*.tcc,*.inl,*.pc setf cpp
endif
noremap <space> :call ToggleFold()<CR>
fun! ToggleFold()
if foldlevel('.') == 0
normal! l
else
if foldclosed('.') < 0
. foldclose!
else
. foldopen!
endif
endif
" Clear status line
echo
endfun
"set wrap
syntax on
highlight Comment ctermfg=cyan
highlight Macro ctermfg=gray
highlight Include ctermfg=magenta
function FoldBrace()
if getline(v:lnum+1)[0] == '{'
return 1
endif
if getline(v:lnum) =~ '{'
return 1
endif
if getline(v:lnum)[0] =~ '}'
return '<1'
endif
return -1
endfunction
if has("autocmd")
autocmd FileType text setlocal textwidth=78
autocmd FileType text set nocindent
autocmd FileType html set formatoptions+=tl
autocmd FileType css set smartindent
autocmd FileType html,css set noexpandtab tabstop=2
autocmd FileType c,cpp,slang,esqlc set cindent
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
autocmd BufEnter * :lcd %:p:h
autocmd BufReadPost *.c,*.ec,*.cpp,*.hpp,*.ecpp,*.pc,*.ppc set foldexpr=FoldBrace()
autocmd BufReadPost *.c,*.ec,*.cpp,*.hpp,*.ecpp,*.pc,*.ppc set foldmethod=expr
autocmd BufReadPost *.c,*.ec,*.cpp,*.hpp,*.ecpp,*.pc,*.ppc set foldenable
endif " has("autocmd")
highlight Comment ctermfg=cyan
map <C-K> gt
map <C-H> gT
map <Tab> gt
set delcombine
map Q gq
vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
colorscheme desert
"set binary
"set noeol
set pastetoggle=<F5>
"ctags config
set autochdir
set tags=tags;
"当文件保存,自动生成ctag相关索引文件
function! UpdateCtags()
let curdir=getcwd()
while !filereadable("./tags")
cd ..
if getcwd() == "/"
break
endif
endwhile
if filewritable("./tags")
!ctags -R --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q
TlistUpdate
endif
execute ":cd " . curdir
endfunction
autocmd BufWritePost *.c,*.h,*.cpp call UpdateCtags()
"taglist config
"nnoremap <silent> <F8> :TlistToggle<CR><CR>
" :Tlist 调用TagList
let Tlist_Show_One_File=1 " 只显示当前文件的tags
let Tlist_Exit_OnlyWindow=1 " 如果Taglist窗口是最后一个窗口则退出Vim
let Tlist_Use_Left_Window=1 " 在右侧窗口中显示
let Tlist_File_Fold_Auto_Close=1 " 自动折叠
"let Tlist_Auto_Open=1 "自动打开taglist
" 设置winmanager
" 在进入vim时自动打开winmanager
"let g:AutoOpenWinManager = 0
" 设置界面分割
let g:winManagerWindowLayout = "FileExplorer|TagList"
"定义打开关闭winmanager快捷键为F8
nmap <silent> <F8> :WMToggle<cr>
autocmd bufenter * if (winnr("$") == 2 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | qa | endif
"cscope config
set cscopequickfix=s-,c-,d-,i-,t-,e-
if has("cscope")
set csprg=/usr/local/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
let curdir=getcwd()
while !filereadable("./cscope.out")
cd ..
if getcwd() == "/"
break
endif
endwhile
if filewritable("./cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
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>
"当文件保存,自动生成cscope相关索引文件
function! UpdateCscope()
let curdir=getcwd()
while !filereadable("./cscope.out")
cd ..
if getcwd() == "/"
break
endif
endwhile
if filewritable("./cscope.out")
!find `pwd` -name "*.[ch]" -o -name "*.cpp" > cscope.files
!cscope -Rbq
endif
execute ":cd " . curdir
endfunction
autocmd BufWritePost *.c,*.h,*.cpp call UpdateCscope()