Linux Vim配置
这里可以下载。
插件
主要的用到的是这些:
- youcompleteme 补全神器
- vundle 插件管理神器 然后可以下 n 多的 bundle,下面都列出了。
- ctrlp 文件定位,可以代替 minibuffer
- taglist
- cscope
- ctags
- winmanager
- The-NERD-Commenter
- DoxygenToolKit
配置
除了常规的插件设置,我写了一个函数function! AutoLoadCTagsAndCScope()
并 bind 到 F12 上,用来生成工程目录下里的 tags 和 cscope 文件,当需要刷新时,点击 F12 就好,当然其实也调用了另外一个脚本.bravo_gen_cscope_ctag_tags.sh
来生成 tags 和 cscope 文件:
#!/bin/sh
if [ -e cscope.out ];then
echo "update cscope files..."
rm -f cscope*
else
echo "create cscope files..."
fi
# get rid of symbol link
#find `pwd` \( \( -iname "*.c" -o -iname "*.cc" -o -iname "*.cpp" -o -iname "*.h" \) -and \( -not -type l \) \) -print > cscope.files
find `pwd` -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.py" > cscope.files
cscope -Rbkq -i cscope.files
if [ -e tags ];then
echo "update tags files..."
rm -f tags
else
echo "create tags files..."
fi
ctags -R `pwd` --fields=+lS --c++-kinds=+p
echo "ctags and cscope files ready"
全体配置如下:
"======================="Basic setting
"=======================
filetype off
syntax on
set nocompatible
set history=100
set number
set ruler
set number
set cindent
set tabstop =4
set shiftwidth =4
set smarttab
set hlsearch
set incsearch
set background=dark
set cursorline
set autoread
set autowriteall
"set cursorcolumn
set hidden
"set confirm
set nobackup
set noswapfile
"better for cut/copy between web and vim
set clipboard =unnamed
"set ui close
if has("gui_running")
set guioptions -=m
set guioptions -=T
endif
set backspace =indent,eol,start
"set guifont=Luxi\ Mono\ 13
set guifont=DejaVu\ Sans\ mono\ 13
set linespace=6
let mapleader =","
let g:mapleader = ","
"set scheme
set t_Co=256
let g:solarized_termcolors=256
let g:solarized_termtrans=1
colorscheme solarized
"=======================
"set vundle
"=======================
"Brief help of vundle
":BundleList ":BundleInstall
":BundleSearch
":BundleClean
":help vundle
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
filetype indent plugin on
"let vundle manage itself,required
Bundle 'gmarik/vundle'
"My bundles here:
Bundle 'altercation/vim-colors-solarized'
Bundle 'taglist.vim'
"Bundle 'cscope.vim'
Bundle 'ctags.vim'
"Bundle 'TinyBufferExplorer'
Bundle 'minibufexpl.vim'
"Bundle 'SelectBuf.vim'
Bundle 'winmanager'
Bundle 'Valloric/YouCompleteMe'
Bundle 'Syntastic'
"Bundle 'SirVer/ultisnips'
Bundle 'honza/vim-snippets'
Bundle 'scrooloose/nerdtree'
"Bundle 'echofunc.vim'
Bundle 'The-NERD-Commenter'
Bundle 'DoxygenToolKit.vim'
Bundle 'desert256.vim'
"Bundle 'instant-markdown.vim'
"Bundle 'isnowfy/python-vim-instant-markdown'
"Bundle 'ctrlpvim/ctrlp.vim'
Bundle 'klen/python-mode'
'
"=======================
"set tags dir
"=======================
set tags=tags
set tags+=./tags
set tags+=/usr/include/tags
set autochdir
silent! set tags
"=======================
"set winmanager
"=======================
"to make it work well with NERDTree
"winmanager.vim has been modified:
" 1. all set buftype = nofile -> set buftpe =
" 2. in CloseWindow , exec 'bd' -> 'bd!'
let g:winManagerWindowLayout='FileExplorer|TagList'
"let g:winManagerWindowLayout='NERDTree|TagList'
let g:saveTagsDisplay=0
"auto exit winmanager
autocmd bufenter * if (winnr("$") == 2 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") |qa | endif
"=======================
"set nerdtree
"=======================
let g:NERDTree_title = 'NERDTree'
function! NERDTree_Start()
exec 'NERDTree'
endfunction
function! NERDTree_IsValid()
return 1
endfunction
"=======================
"set taglist
"=======================
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_Exit_OnlyWindow = 1
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Use_Right_Window = 0
let Tlist_Show_Menu = 0
let Tlist_Display_Tag_Scope = 0
let Tlist_Auto_Update = 1
let Tlist_Enable_Fold_Column = 0
let Tlist_GainFocus_On_ToggleOpen = 1
"=======================
"set minibufexpl
"=======================
let g:miniBufExplMapWindowNavVim =1
let g:miniBufExplMapWindowNavArrows =1
let g:miniBufExplMapCTabSwitchBufs =1
let g:minBufExpModSelTarget =1
let g:miniBufExplorerMoreThanOne =2
"=======================
"set youcompleteme
"=======================
let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'
let g:yum_error_symbol ='>>'
let g:yum_warning_symble ='>*'
"comments and strings can be completed ,too
let g:ycm_complete_in_comments = 1
let g:ycm_complete_in_strings = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
"no need ask load the configuration
let g:ycm_confirm_extra_conf =0
"key word syntax
let g:ycm_seed_identifiers_with_syntax = 1
"use tags from ctags
let g:ycm_collect_identifiers_from_tag_files =1
"close syntastic of ycm
let g:ycm_show_diagnostics_ui =1
"let ycm use ultisnips
let g:ycm_use_ultisnips_completer = 0
"the right python version
let g:ycm_server_python_interpreter='/usr/bin/python'
"auto close preview window
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
"invoke hotkey ALT+c
let g:ycm_key_invoke_completion=',<tab>'
",gs ,gb ,gd hotkey
nnoremap <leader>gb :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <leader>gs :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gd :YcmCompleter GoToDefinition<CR>
"=======================
"set ultisnips
"=======================
let g:UltiSnipsUsePythonVersion = 3
let g:UltiSnipsSnippetDirectories=['snippets','UltiSnips','ultisnips']
let g:UltiSnipsSnippetDirectories= ['~/.vim/bundle/vim-snippets/snippets','~/.vim/bundle/vim-snippets/UltiSnips']
let g:UltiSnipsExpandTrigger = '<s-tab>'
let g:UltiSnipsListSnippets = '<c-s-Tab>'
let g:UltiSnipsJumpForwardTrigger = '<s-tab>'
"let g:UltiSnipsJumpBackForwardTrigger = '<s-tab>'
"let g:UltiSnipsUsePythonVersion = '<tab>'
"solve confliction with ycm
let g:ycm_key_list_select_completion = ['<tab>', '<Down>']
let g:ycm_key_list_previous_completion = ['<c-tab>','<Up>']
let g:SuperTabDefaultCompletionType = '<tab>'
"=======================
"set synstastic
"=======================
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
"let g:syntastic_always_populate_loc_list =1
"let g:syntastic_auto_loc_list =1
"let g:syntastic_check_on_open =1
"let g:syntastic_check_on_wq =1
"=======================
"set cscope
"=======================
"quickfix window
"set cscopequickfix=s-,c-,d-,i-,t-,e-
"nmap \s :cs find s <C-R>=expand("<cword>")<CR><CR>:cw<CR>
"nmap \g :cs find g <C-R>=expand("<cword>")<CR><CR>
"nmap \c :cs find c <C-R>=expand("<cword>")<CR><CR>:cw<CR>
"nmap \t :cs find t <C-R>=expand("<cword>")<CR><CR>:cw<CR>
"nmap \e :cs find e <C-R>=expand("<cword>")<CR><CR>:cw<CR>
"nmap \f :cs find f <C-R>=expand("<cfile>")<CR><CR>:cw<CR>
"nmap \i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:cw<CR>
"nmap \d :cs find d <C-R>=expand("<cword>")<CR><CR>:cw<CR>
"\b quit quickbox
nmap \s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap \g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap \c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap \t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap \e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap \f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap \i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap \d :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap \b :ccl<CR>
function! AutoLoadCTagsAndCScope()
let max = 10
let dir = './'
let i = 0
let break = 0
let cur_dir = getcwd()
echo cur_dir
while isdirectory(dir) && (i < max)
"echo "i = " . i
"echo dir . 'cscope.out'
"echo dir . 'tags'
if filereadable(dir . 'cscope.out') && filereadable(dir . 'tags')
" use self defined shell to update tags and cscopefiles, which must be placed
" at /user/bin directory
" fist time must manally generate the tags and cscope files.like:
" cd project_dir
" bravotags
"echo "1"
"execute "!command pwd"
let dir1 = getcwd()
execute 'cd' . dir
"execute "!command pwd"
execute '!bravotags'
"reset cscope database
execute 'cs reset'
execute 'cd' . dir1
"execute "!command pwd"
let break = 1
endif
if break == 1
"echo dir . 'cscope.out'
"echo dir . 'tags'
if filereadable(dir . 'cscope.out')
"echo "2"
"execute "!command pwd"
execute 'cs add ' . dir . 'cscope.out'
"echo "add cscope success"
let break = 1
endif
if filereadable(dir . 'tags')
"echo "3"
"execute "!command pwd"
execute 'set tags +=' . dir . 'tags'
"echo "add tags success"
let break = 1
endif
"echo "4"
execute 'cd ' . cur_dir
"execute "!command pwd"
break
endif
let dir = dir . '../'
let i = i + 1
endwhile
if break == 0
echo "did not find tags and cscope files"
endif
endfunction
"set csprg=/usr/bin/cscope
"set csto =0
"set cst
"=======================
"set DoxygenToolKit
"=======================
let g:DoxygenToolkit_commentType = "C"
let g:DoxygenToolkit_compactOneLineDoc = "yes"
let g:DoxygenToolkit_compactDoc = "yes"
let g:DoxygenToolkit_briefTag_className = "yes"
let g:DoxygenToolkit_briefTag_funcName = "yes"
let g:DoxygenToolkit_briefTag_structName = "yes"
let g:DoxygenToolkit_briefTag_enumName = "yes"
let g:DoxygenToolkit_briefTag_namespaceName = "yes"
"let g:DoxygenToolkit_briefTag_pre ="@brief "
"let g:DoxygenToolkit_paramTag_pre ="@param "
"let g:DoxygenToolkit_returnTag_pre ="@return null"
"hot key
"=======================
"ctrlp
"=======================
"let g:ctrlp_map = '<leader>p'
let g:ctrlp_cmd = 'CtrlP'
map <leader>f :CtrlPMRU<CR>
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|rvm)$',
\ 'file': '\v\.(exe|so|dll|zip|tar|tar.gz|pyc)$',
\ }
let g:ctrlp_working_path_mode=0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height=15
let g:ctrlp_match_window_reversed=0
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
"=======================
"python mode
"https://github.com/python-mode/python-mode/blob/develop/doc/pymode.txt
"=======================
let g:pymode_python = 'python3'
let g:pymode_quickfix_minheight = 3
let g:pymode_quickfix_maxheight = 6
let g:pymode_options_max_line_length = 79
let g:pymode_folding = 0
"=======================
"self-definition hotkeys
"=======================
"Doxygen
map fg :Dox<CR>
map fh :DoxAuthor<CR>
"cscope
"switch between sub-windows
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-h> <c-w>h
map <c-l> <c-w>l
"adjust windowsize
map wj :resize +2<CR>
map wk :resize -2<CR>
map wh :vertical resize -2<CR>
map wl :vertical resize +2<CR>
"F2 show colum numbers or not
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>
"F3 triggle taglist
nnoremap <F3> :TlistToggle<CR>
"F4 triggle nerdtree
nnoremap <F4> :NERDTreeToggle<CR>
"F5 to show buffer and choose 1
"nnoremap <F5> :buffers<CR>:buffer<Space>
"F8 close hightlight
nnoremap <silent> <F8> :noh<CR>
"F9 toggle the winmanager
"conflict with NERDTree ,I give up !
"nnoremap <silent> <F9> :WMToggle<CR>
"F10 toggle minibufexplorer
nnoremap <silent> <F10> :TMiniBufExplorer<CR>
"F9 update tags and cscope file
nnoremap <silent> <F9> :call AutoLoadCTagsAndCScope()<CR><CR>
"=============================================
"auto update .vimrc when saved the .vimrc file
"=============================================
autocmd! bufwritepost .vimrc source ~/.vimrc