码迷,mamicode.com
首页 > 系统相关 > 详细

我的vim 自动实例括号函数

时间:2015-02-11 12:18:00      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

不废话,直接上代码:

 1 """""""""""""""""""""""""""""""""""""""""""
 2 "自动实例括号
 3 """""""""""""""""""""""""""""""""""""""""""
 4 ""inoremap ( ()<ESC>i
 5 inoremap ( <c-r>=OpenPair((,))<CR>
 6 inoremap ) <c-r>=ClosePair())<CR>
 7 inoremap { {}<ESC>i
 8 inoremap } <c-r>=ClosePair(})<CR>
 9 inoremap [ []<ESC>i
10 inoremap ] <c-r>=ClosePair(])<CR>
11 inoremap " <c-r>=QuoteDelim(‘"‘)<CR>
12 inoremap  <c-r>=QuoteDelim("‘")<CR>
13 
14 function! OpenPair(char1,char2)
15     let line = getline(.)
16     let col = col(.)
17     if col($) == col
18         return a:char1 . a:char2. "\<Left>"
19     else
20         return a:char1 
21     endif
22 endfunction
23 
24 function! ClosePair(char)
25     if getline(.)[col(.) - 1] == a:char
26         return "\<Right>"
27     else
28         return a:char
29     endif
30 endfunction
31 
32 function! QuoteDelim(char)
33     let line = getline(.)
34     let col = col(.)
35     if line[col - 2] == "\\"
36         "Inserting a quoted quotation mark into the string
37         return a:char
38     elseif line[col - 1] == a:char
39         "Escaping out of the string
40         return "\<Right>"
41     else
42         "Starting a string
43         return a:char.a:char."\<Esc>i"
44     endif
45 endf

 

我的vim 自动实例括号函数

标签:

原文地址:http://www.cnblogs.com/sixbeauty/p/4285654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!