保存下自己常用的vimrc,方便取用
" common configuration
set ruler
set nu
set nowrap
set showcmd
set showmode
set hlsearch
set nobackup
" show cursor
set cursorline
"set cursorcolumn
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileformats=unix,dos,mac
set termencoding=utf-8
set formatoptions+=m
set formatoptions+=B
" file type related
filetype on
filetype plugin on
filetype indent on
autocmd FileType python set tabstop=4 shiftwidth=4 expandtab ai
autocmd BufRead,BufNew *.md,*.mkd,*.markdown set filetype=markdown.mkd
autocmd BufNewFile *.sh,*.py exec \":call AutoSetFileHead()\"
function! AutoSetFileHead()
" shell
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
endif
" python
if &filetype == 'python'
call setline(1, "\#!/usr/bin/env python")
call append(1, "\# encoding: utf-8")
endif
normal G
normal o
normal o
endfunc
" auto trim spaces
autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
" cscope configuration
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
if filereadable("cscope.out")
cs add cscope.out
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" shortcut
nnoremap <F6> :set nu! nu?<CR>
nnoremap <F7> :set list! list?<CR>
nnoremap <F8> :set wrap! wrap?<CR>
"set pastetoggle=<F5>
"au InsertLeave * set nopaste
"nnoremap <F6> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR>
" command mode configuration
cnoremap <C-j> <t_kd>
cnoremap <C-k> <t_ku>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>