<转>vim基本配置
1. 终端运行:vim ~/.vimrc
2. 编辑文件.vimrc, 拷贝以下内容, 按Ecs, 并输入 :wq 保存退出:
- "这个文件双引号 (") 是批注
- set hlsearch "高亮度反白
- set backspace=2 "可随时用退格键删除
- set autoindent "自动缩排
- set ruler "可显示最后一行的状态
- set showmode "左下角那一行的状态
- set nu "可以在第一行的最前面显示行号
- set bg=dark "显示不同的底色色调
- syntax on "进行语法检验, 颜色显示
- set ts=4 "ts是tabstop的缩写, 设Tab宽4个空格
- set expandtab
- %retab! "加!是用于处理非空白字符之后的TAB, 即所有的TAB;若不加, 则只处理行首的TAB
- " Encoding related
- set encoding=UTF-8
- set langmenu=zh_CN.UTF-8
- language message zh_CN.UTF-8
- set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
- set fileencoding=utf-8
- "支持{}、[]、()、""、''自动补全
- inoremap ( <c-r>=OpenPair('(')<CR>
- inoremap ) <c-r>=ClosePair(')')<CR>
- inoremap { <c-r>=OpenPair('{')<CR>
- inoremap } <c-r>=ClosePair('}')<CR>
- inoremap [ <c-r>=OpenPair('[')<CR>
- inoremap ] <c-r>=ClosePair(']')<CR>
- " just for xml document, but need not for now.
- "inoremap < <c-r>=OpenPair('<')<CR>
- "inoremap > <c-r>=ClosePair('>')<CR>
- function! OpenPair(char)
- let PAIRs = {
- \ '{' : '}',
- \ '[' : ']',
- \ '(' : ')',
- \ '<' : '>'
- \}
- if line('$')>2000
- let line = getline('.')
- let txt = strpart(line, col('.')-1)
- else
- let lines = getline(1,line('$'))
- let line=""
- for str in lines
- let line = line . str . "\n"
- endfor
- let blines = getline(line('.')-1, line("$"))
- let txt = strpart(getline("."), col('.')-1)
- for str in blines
- let txt = txt . str . "\n"
- endfor
- endif
- let oL = len(split(line, a:char, 1))-1
- let cL = len(split(line, PAIRs[a:char], 1))-1
- let ol = len(split(txt, a:char, 1))-1
- let cl = len(split(txt, PAIRs[a:char], 1))-1
- if oL>=cL || (oL<cL && ol>=cl)
- return a:char . PAIRs[a:char] . "\<Left>"
- else
- return a:char
- endif
- endfunction
- function! ClosePair(char)
- if getline('.')[col('.')-1] == a:char
- return "\<Right>"
- else
- return a:char
- endif
- endf
- inoremap ' <c-r>=CompleteQuote("'")<CR>
- inoremap " <c-r>=CompleteQuote('"')<CR>
- function! CompleteQuote(quote)
- let ql = len(split(getline('.'), a:quote, 1))-1
- let slen = len(split(strpart(getline("."), 0, col(".")-1), a:quote, 1))-1
- let elen = len(split(strpart(getline("."), col(".")-1), a:quote, 1))-1
- let isBefreQuote = getline('.')[col('.') - 1] == a:quote
- if '"'==a:quote && "vim"==&ft && 0==match(strpart(getline('.'), 0, col('.')-1), "^[\t ]*$")
- " for vim comment.
- return a:quote
- elseif "'"==a:quote && 0==match(getline('.')[col('.')-2], "[a-zA-Z0-9]")
- " for Name's Blog.
- return a:quote
- elseif (ql%2)==1
- " a:quote length is odd.
- return a:quote
- elseif ((slen%2)==1 && (elen%2)==1 && !isBefreQuote) || ((slen%2)==0 && (elen%2)==0)
- return a:quote . a:quote . "\<Left>"
- elseif isBefreQuote
- return "\<Right>"
- else
- return a:quote . a:quote . "\<Left>"
- endif
- endfunction
3. OK, Enjoy it!!!
(温馨提示:.vimrc是vim的配置文件, 路径位于/home/用户名/下, 属于隐藏文件, 按Ctrl + h可以显示隐藏文件。)
posted on 2015-10-05 13:59 hahahahahai12 阅读(203) 评论(0) 收藏 举报
浙公网安备 33010602011771号