为了补偿前几周对 vim 的不忠,这两天整理了一下 vim 的配置,贴上来备份一下,也算是一篇凑数的文章。
目前正在使用的插件有 neocomplcache(自动补全),bufexplorer(多个 buffer 间切换),code_complete(代码模板),nerdtree(文件浏览的侧边栏),nerdcommenter(注释的好帮手)。另外还有一些好用的插件如 taglist(代码结构浏览,只需装上 ctags 即可,不需生成 tags 文件),echofunc(输入函数左括号时显示函数原型)等。
最后贴一下配置文件,是在 deb 包配置文件的基础上修改的(2013.12.09 更新):
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
syntax on
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
"au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
au BufReadPost * exe "normal! g`\""
endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
if has("autocmd")
filetype plugin indent on
endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set smartcase " Do smart case matching
set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis | wincmd p | diffthis
" --------------------------------------------------------------------------- "
let mapleader = ","
source $VIMRUNTIME/ftplugin/man.vim " using ':Man' to get help, equal to 'K'
" tweaks for default console colorscheme
"hi folded ctermbg=black
"hi comment ctermfg=darkgrey
"hi statusline ctermbg=black ctermfg=darkyellow
"hi statuslinenc ctermbg=darkyellow ctermfg=black
" popup menu color tweaks since 7.3.524
"hi pmenu ctermfg=white
"hi pmenusel ctermfg=white
set t_Co=256
colorscheme molokai
hi todo ctermfg=black ctermbg=yellow
hi visual ctermbg=238
hi statuslinenc ctermfg=238 ctermbg=253
hi statusline ctermfg=244 ctermbg=232
hi pmenusel ctermfg=253 ctermbg=238
" generic settings. some of them are picked up from debian.vim
set nocp " 'nocompatible': Use Vim defaults instead of 100% vi compatibility
set bs=indent,eol,start " more powerful backspacing
set hi=50 " keep 50 lines of command line history
set ru " 'ruler': show the cursor position all the time
set nowb " 'nowriteback'
set nobk " 'nobackup'
set noswf " 'noswapfile'
set nu " 'number': show line number
set nows " 'nowrapscan': searching stops when reaching the end of file
set fdm=syntax " 'foldmethod': fold multi lines by syntax
set fdl=9999 " 'foldlevel': unfold automatically when opening a file
set fencs=utf-8,gbk " :h fileencodings
"set hls " 'hlsearch': highlight search key
set nomodeline " modelines have historically been a source of security/resource vulnerabilities -- disable by default, even when 'nocompatible' is set
set ar " :h autoread
" c indent options
set cino=b1,t0,(0 " 'cinoptions' :h cinoptions-values
set cink+=0=break " 'cinkeys': for cinoptions
set sw=4 " 'shiftwidth': 4 spaces for indent
set sts=4 " 'softtabstop': delete 4 spaces once
set et " 'expandtab': insert spaces instead of tab
set sta " :h smarttab
set cot=longest,menuone " 'completeopt': do not show the preview window when omnicompleting
"autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
"autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" im auto-switch. available in gvim
"au InsertEnter * set noimdisable
"au InsertLeave * set imdisable
" emacs-style key bindings
func! KillLineEnd()
let l:current_col = col('.')
let l:row_end = col('$')
if col('$') == 1
normal dd
else
if l:current_col == l:row_end - 1
normal J
else
normal D
endif
endif
normal a
endfunc
inoremap <C-a> <C-o>^
inoremap <C-b> <left>
inoremap <C-d> <del>
inoremap <C-e> <end>
inoremap <C-f> <right>
inoremap <C-k> <C-o>:call KillLineEnd()<cr>
inoremap <C-n> <down>
inoremap <C-p> <up>
inoremap <C-y> <esc>pa
" buffer shortcuts
nnoremap <C-x>b :b#<cr>
inoremap <C-x>b <C-o>:b#<cr>
nnoremap <C-x><C-b> :BufExplorer<cr>
inoremap <C-x><C-b> <esc>:BufExplorer<cr>
func! KillBuffer()
let l:curr_buf = bufnr("%")
let l:prev_buf = bufnr("#")
if buflisted(l:prev_buf)
buffer #
else
bnext
endif
if bufnr("%") == l:curr_buf
new
endif
exec "bwipe " . l:curr_buf
endfunc
nnoremap <silent> <C-x>k :call KillBuffer()<cr>
" window shortcuts
nnoremap <tab> <C-w>w
nnoremap <C-left> <C-w><
nnoremap <C-right> <C-w>>
nnoremap <C-up> <C-w>+
nnoremap <C-down> <C-w>-
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" cscope settings
if has("cscope")
set cscopeprg=/usr/bin/cscope
set cscopetagorder=0
set cscopetag
let s:currdir = getcwd()
while !filereadable("cscope.out")
if getcwd() == "/"
break
endif
cd ..
endwhile
if filereadable("cscope.out")
cs add cscope.out
else
cd `=s:currdir` " cd %:p:h or :set acd
endif
endif
" ctags settings
set tags=tags; " :h file-searching
" development shortcuts
"nnoremap <F2> :DiffOrig<cr>
"inoremap <F2> <esc>:DiffOrig<cr>
nnoremap <silent> <F3> :NERDTreeToggle<cr>
inoremap <silent> <F3> <esc>:NERDTreeToggle<cr>
"nnoremap <silent> <F4> :TlistToggle<cr>
"inoremap <silent> <F4> <esc>:TlistToggle<cr>
nnoremap <F5> :wa<cr>:!/usr/local/bin/run %<cr>
inoremap <F5> <esc>:wa<cr>:!/usr/local/bin/run %<cr>a
nnoremap <C-F7> :make clean && make<cr><cr><cr>
inoremap <C-F7> <C-o>:make clean && make<cr><cr><cr>
nnoremap <F9> :!ctags -R --c++-kinds=+dx --fields=+aiS --extra=+q<cr>:set tags=/usr/include/tags,tags;<cr>:!cscope -Rbkq<cr>:cs reset<cr>
" `stty -ixon' to disable ctrl-s and ctrl-q in bash
nnoremap <C-s> :w<cr>
inoremap <C-s> <C-o>:w<cr>
nnoremap <C-q> :q<cr>
inoremap <C-q> <esc>:q<cr>
nnoremap <space> o<esc>0D
inoremap <C-\> <left><cr><up><end><cr>
" <cr> action according to whether there is a popup menu
inoremap <expr> <cr> pumvisible()?"\<C-y>":"\<cr>"
" user-defined keyword highlighting
"autocmd filetype c,cpp,h syn keyword MyType atomic_t | hi link MyType type
" autoload plugins according to filetype
"autocmd vimEnter *.c,*.cpp,*.h :NERDTree | :wincmd l
if filereadable(".project.vim")
source .project.vim
endif
let php_folding = 2
" --------------------- bufexplorer settings ----------------- "
let g:bufExplorerFindActive = 0
" ---------------------- nerdtree settings ------------------- "
let NERDTreeIgnore = ['\.o$', '^cscope', 'tags']
" ------------------- neocomplcache settings ----------------- "
let g:neocomplcache_enable_at_startup = 1
let g:neocomplcache_enable_auto_select = 1
let g:neocomplcache_fuzzy_completion_start_length = 2
let g:neocomplcache_enable_fuzzy_completion = 1
if !exists('g:neocomplcache_omni_patterns')
let g:neocomplcache_omni_patterns = {}
endif
let g:neocomplcache_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
let g:neocomplcache_omni_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_omni_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
" ---------------------------------------------------------
" ms-windows settings
"autocmd vimEnter * simalt ~x " maximize when launched
"set guicursor=a:block-blinkoff0
"set guifont=Dejavu\ Sans\ Mono:h12
"set guioptions-=T " toolbar
"set guioptions-=m " menubar
"set guioptions-=l " same as 'r'
"set guioptions-=L " same as 'R'
"set guioptions-=r " right-hand scrollbar always
"set guioptions-=R " right-hand scrollbar is presented when is a vsplit window
"set guioptions-=b " bottom scrollbar
选项就不一一介绍了,具体的说明 :help 一下就行了。
……我发现我一直都在裸用vim,几乎不用插件不绑定热键,nerdtree还是昨天才开始用的……原因是因为左边没有个边栏的话,代码每行开头太偏了。
我以前也是这样的……尝试了emacs之后发现插件真的很爽,你用firefox应该比我更有体会……
……从一个侧面反映出我还没有折腾到一定境界……竟然没有对插件的需求。。。。另外火狐我几乎也是裸用的……只有代理和evernote的两个插件……汗……我倒是想找个时候看看写vim script的教程……
顶欧哥!