7月 252011
 

不解释了,把下面代码贴到.vimrc文件中就行了,然后,重新打开vim,写一个函数试试,我感觉还不错的…

 
  1. :inoremap <S-ENTER> <c-r>=SkipPair()<CR>
  2. :inoremap <S-SPACE> <ESC>la
  3. :inoremap <C-ENTER> <ESC>A;<CR>
  4. :inoremap ( ()<ESC>i
  5. :inoremap ) <c-r>=ClosePair(‘)’)<CR>
  6. :inoremap { <c-r>=ClsoeBrace()<CR>
  7. :inoremap } <c-r>=ClosePair(‘}’)<CR>
  8. :inoremap [ []<ESC>i
  9. :inoremap ] <c-r>=ClosePair(‘]’)<CR>
  10. :inoremap ;; <ESC>A;<CR>
  11. function ClosePair(char)
  12.    if getline(‘.’)[col(‘.’) – 1] == a:char
  13.       return "\<Right>"
  14.    else
  15.       return a:char
  16.    endif
  17. endf
  18. function Semicolon()
  19.    "echo getline(‘.’)[col(‘.’)]
  20.    if getline(‘.’)[col(‘.’)] == ‘)’
  21.       return "<ESC>A;"
  22.    elseif getline(‘.’)[col(‘.’)] == ‘}’
  23.       return "\<ESC>A;"
  24.    elseif getline(‘.’)[col(‘.’)] == ‘]’
  25.       return "\<ESC>A;"
  26.    else
  27.       return ";"
  28.    endif
  29. endf
  30. function SkipPair()
  31.    if getline(‘.’)[col(‘.’) – 1] == ‘)’
  32.       return "\<ESC>o"
  33.    else
  34.       normal j
  35.       let curline = line(‘.’)
  36.       let nxtline = curline
  37.       while curline == nxtline
  38.          if getline(‘.’)[col(‘.’) – 1] == ‘}’
  39.             normal j
  40.             let nxtline = nxtline + 1
  41.             let curline = line(‘.’)
  42.             continue
  43.          else
  44.             return "\<ESC>i"
  45.          endif
  46.          
  47.       endwhile
  48.       return "\<ESC>o"
  49.    endif
  50. endf
  51. function ClsoeBrace()
  52.    if getline(‘.’)[col(‘.’) – 2] == ‘=’
  53.       return "{}\<ESC>i"
  54.    elseif getline(‘.’)[col(‘.’) – 3] == ‘=’
  55.       return "{}\<ESC>i"
  56.    elseif getline(‘.’)[col(‘.’) – 1] == ‘{‘
  57.       return "{}\<ESC>i"
  58.    elseif getline(‘.’)[col(‘.’) – 2] == ‘{‘
  59.       return "{}\<ESC>i"
  60.    elseif getline(‘.’)[col(‘.’) – 2] == ‘,’
  61.       return "{}\<ESC>i"
  62.    elseif getline(‘.’)[col(‘.’) – 3] == ‘,’
  63.       return "{}\<ESC>i"
  64.    else
  65.       return "{\<ENTER>}\<ESC>O"
  66.    endif
  67. endf
 Posted by at 上午 10:45

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据