我的vim 自动实例括号函数

不废话,直接上代码:

 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

 

转载于:https://www.cnblogs.com/sixbeauty/p/4285654.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值