Debian 下的 vim 的默认配置是出了名的差,所以就需要多设置几句 set expandtab set shiftwidth=4 set tabstop=4 set softtabstop=4 set nobackup set cindent set autoindent set showcmd set helplang=Cn set nofoldenable set noswapfile set number set mouse=nv set hlsearch set incsearch set viminfo+=h
colorscheme evening hi Normal ctermfg=grey ctermbg=black hi Visual ctermfg=green ctermbg=black hi Search term=reverse cterm=standout ctermfg=green ctermbg=yellow hi IncSearch term=reverse cterm=standout ctermfg=green ctermbg=yellow hi PmenuSel ctermbg=Green ctermfg=Yellow
if has('autocmd') " Remove ALL autocommands for the current group au!
" Mark .asm files MASM-type assembly au BufNewFile,BufReadPre *.asm let b:asmsyntax='masm' endif
if has('gui_running') let do_syntax_sel_menu=1 endif
if has('gui_running') && $LANG !~ '\.' set encoding=utf-8 endif
set nocompatible source $VIMRUNTIME/vimrc_example.vim
set autoindent set nobackup set showmatch set formatoptions+=mM set fileencodings=ucs-bom,utf-8,gbk set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P if has('mouse') set mouse=a endif if has('multi_byte') && v:version > 601 if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)' set ambiwidth=double endif endif
" Key mappings to ease browsing long lines noremap gj noremap gk noremap gj noremap gk inoremap gj inoremap gk
" Key mappings for quick arithmetic inside Vim nnoremap ma yypV:!calcu '"'k$ vnoremap ma yopV:!calcu '"'k$ nnoremap mr yyV:!calcu '"'$ vnoremap mr ygvmaomb:r !calcu '"'"ay$dd`bv`a"ap
" Key mapping to stop the search highlight nmap :nohlsearch imap :nohlsearch
" Key mapping for the taglist.vim plugin nmap :Tlist imap :Tlist
" Key mappings for the quickfix commands nmap :cn nmap :cp
" Non-GUI setting if !has('gui_running') " Do not increase the windows width in the taglist.vim plugin if has('eval') let Tlist_Inc_Winwidth=0 endif
" Set text-mode menu if has('wildmenu') set wildmenu set cpoptions-=< set wildcharm= nmap :emenu imap :emenu endif endif
if has('autocmd') function! SetFileEncodings(encodings) let b:my_fileencodings_bak=&fileencodings let &fileencodings=a:encodings endfunction
function! RestoreFileEncodings() let &fileencodings=b:my_fileencodings_bak unlet b:my_fileencodings_bak endfunction
function! ConvertHtmlEncoding(encoding) if a:encoding ==? 'gb2312' return 'gbk' " GB2312 imprecisely means GBK in HTML elseif a:encoding ==? 'iso-8859-1' return 'latin1' " The canonical encoding name in Vim elseif a:encoding ==? 'utf8' return 'utf-8' " Other encoding aliases should follow here else return a:encoding endif endfunction
function! DetectHtmlEncoding() if &filetype != 'html' return endif normal m` normal gg if search('\c') != 0 let reg_bak=@" normal y$ let charset=matchstr(@", 'text/html; charset=\zs[-A-Za-z0-9_]\+') let charset=ConvertHtmlEncoding(charset) normal `` let @"=reg_bak if &fileencodings == '' let auto_encodings=',' . &encoding . ',' else let auto_encodings=',' . &fileencodings . ',' endif if charset !=? &fileencoding && \(auto_encodings =~ ',' . &fileencoding . ',' || &fileencoding == '') silent! exec 'e ++enc=' . charset endif else normal `` endif endfunction
function! RemoveTrailingSpace() if $VIM_HATE_SPACE_ERRORS != '0' && \(&filetype == 'c' || &filetype == 'cpp' || &filetype == 'vim') normal m` silent! :%s/\s\+$//e normal `` endif endfunction
" Highlight space errors in C/C++ source files (Vim tip #935) if $VIM_HATE_SPACE_ERRORS != '0' let c_space_errors=1 endif
" Use Canadian spelling convention in engspchk (Vim script #195) let spchkdialect='can'
" Show syntax highlighting attributes of character under cursor (Vim " script #383) map a :call SyntaxAttr()
" Automatically find scripts in the autoload directory au FuncUndefined * exec 'runtime autoload/' . expand('') . '.vim'
" File type related autosetting au FileType c,cpp setlocal cinoptions=:0,g0,(0,w1 shiftwidth=4 tabstop=4 au FileType diff setlocal shiftwidth=4 tabstop=4 au FileType html setlocal autoindent indentexpr= au FileType changelog setlocal textwidth=76
" Text file encoding autodetection au BufReadPre *.gb call SetFileEncodings('gbk') au BufReadPre *.big5 call SetFileEncodings('big5') au BufReadPre *.nfo call SetFileEncodings('cp437') au BufReadPost *.gb,*.big5,*.nfo call RestoreFileEncodings() au BufWinEnter *.txt call CheckFileEncoding()
" Detect charset encoding in an HTML file au BufReadPost *.htm* nested call DetectHtmlEncoding()
" Recognize standard C++ headers au BufEnter /usr/include/c++/* setf cpp au BufEnter /usr/include/g++-3/* setf cpp
" Setting for files following the GNU coding standard au BufEnter /usr/* call GnuIndent()