<转>vim基本配置

1. 终端运行:vim ~/.vimrc
2. 编辑文件.vimrc, 拷贝以下内容, 按Ecs, 并输入 :wq 保存退出:
  1. "这个文件双引号 (") 是批注  
  2. set hlsearch "高亮度反白  
  3. set backspace=2 "可随时用退格键删除  
  4. set autoindent "自动缩排  
  5. set ruler "可显示最后一行的状态  
  6. set showmode "左下角那一行的状态  
  7. set nu "可以在第一行的最前面显示行号  
  8. set bg=dark "显示不同的底色色调  
  9. syntax on "进行语法检验, 颜色显示  
  10.   
  11. set ts=4 "ts是tabstop的缩写, 设Tab宽4个空格  
  12. set expandtab  
  13. %retab!      "加!是用于处理非空白字符之后的TAB, 即所有的TAB;若不加, 则只处理行首的TAB  
  14.   
  15. " Encoding related  
  16. set encoding=UTF-8  
  17. set langmenu=zh_CN.UTF-8  
  18. language message zh_CN.UTF-8  
  19. set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1  
  20. set fileencoding=utf-8  
  21.   
  22. "支持{}、[]、()、""、''自动补全  
  23. inoremap ( <c-r>=OpenPair('(')<CR>  
  24. inoremap ) <c-r>=ClosePair(')')<CR>  
  25. inoremap { <c-r>=OpenPair('{')<CR>  
  26. inoremap } <c-r>=ClosePair('}')<CR>  
  27. inoremap [ <c-r>=OpenPair('[')<CR>  
  28. inoremap ] <c-r>=ClosePair(']')<CR>  
  29.   
  30. " just for xml document, but need not for now.  
  31. "inoremap < <c-r>=OpenPair('<')<CR>  
  32. "inoremap > <c-r>=ClosePair('>')<CR>  
  33.   
  34. function! OpenPair(char)  
  35.     let PAIRs = {  
  36.                 \ '{' : '}',  
  37.                 \ '[' : ']',  
  38.                 \ '(' : ')',  
  39.                 \ '<' : '>'  
  40.                 \}  
  41.     if line('$')>2000  
  42.         let line = getline('.')  
  43.    
  44.         let txt = strpart(line, col('.')-1)  
  45.     else  
  46.         let lines = getline(1,line('$'))  
  47.         let line=""  
  48.         for str in lines  
  49.             let line = line . str . "\n"  
  50.         endfor  
  51.    
  52.         let blines = getline(line('.')-1, line("$"))  
  53.         let txt = strpart(getline("."), col('.')-1)  
  54.         for str in blines  
  55.             let txt = txt . str . "\n"  
  56.         endfor  
  57.     endif  
  58.     let oL = len(split(line, a:char, 1))-1  
  59.     let cL = len(split(line, PAIRs[a:char], 1))-1  
  60.    
  61.     let ol = len(split(txt, a:char, 1))-1  
  62.     let cl = len(split(txt, PAIRs[a:char], 1))-1  
  63.    
  64.     if oL>=cL || (oL<cL && ol>=cl)  
  65.         return a:char . PAIRs[a:char] . "\<Left>"  
  66.     else  
  67.         return a:char  
  68.     endif  
  69. endfunction  
  70. function! ClosePair(char)  
  71.     if getline('.')[col('.')-1] == a:char  
  72.         return "\<Right>"  
  73.     else  
  74.         return a:char  
  75.     endif  
  76. endf  
  77.    
  78. inoremap ' <c-r>=CompleteQuote("'")<CR>  
  79. inoremap " <c-r>=CompleteQuote('"')<CR>  
  80. function! CompleteQuote(quote)  
  81.     let ql = len(split(getline('.'), a:quote, 1))-1  
  82.     let slen = len(split(strpart(getline("."), 0, col(".")-1), a:quote, 1))-1  
  83.     let elen = len(split(strpart(getline("."), col(".")-1), a:quote, 1))-1  
  84.     let isBefreQuote = getline('.')[col('.') - 1] == a:quote  
  85.    
  86.     if '"'==a:quote && "vim"==&ft && 0==match(strpart(getline('.'), 0, col('.')-1), "^[\t ]*$")  
  87.         " for vim comment.  
  88.         return a:quote  
  89.     elseif "'"==a:quote && 0==match(getline('.')[col('.')-2], "[a-zA-Z0-9]")  
  90.         " for Name's Blog.  
  91.         return a:quote  
  92.     elseif (ql%2)==1  
  93.         " a:quote length is odd.  
  94.         return a:quote  
  95.     elseif ((slen%2)==1 && (elen%2)==1 && !isBefreQuote) || ((slen%2)==0 && (elen%2)==0)  
  96.         return a:quote . a:quote . "\<Left>"  
  97.     elseif isBefreQuote  
  98.         return "\<Right>"  
  99.     else  
  100.         return a:quote . a:quote . "\<Left>"  
  101.     endif  
  102. endfunction  
3. OK, Enjoy it!!!
(温馨提示:.vimrc是vim的配置文件, 路径位于/home/用户名/下, 属于隐藏文件, 按Ctrl + h可以显示隐藏文件。)

posted on 2015-10-05 13:59  hahahahahai12  阅读(203)  评论(0)    收藏  举报

导航