vim像sublime一样的括号处理
发表于 : 2013-11-26 19:02
求一段.vimrc
要求如下,在一行中间键入(,则只会出现(
在一行末端键入(,则出现(|)
上面|为光标位置
要求如下,在一行中间键入(,则只会出现(
在一行末端键入(,则出现(|)
上面|为光标位置
代码: 全选
function MayCloseParentheses()
if col('.') == col('$')
return "()\<Left>"
else
return "("
endif
endfunction
inoremap <expr> <silent> ( MayCloseParentheses()
lilydjwg 写了:很简单,我随手就可以给你写一个:代码: 全选
function MayCloseParentheses() if col('.') == col('$') return "()\<Left>" else return "(" endif endfunction inoremap <expr> <silent> ( MayCloseParentheses()
我把manual看了一遍,<silent>这里不懂,为什么要避免回显,本来就不会回显的吧,谢谢lilydjwg 写了:很简单,我随手就可以给你写一个:代码: 全选
function MayCloseParentheses() if col('.') == col('$') return "()\<Left>" else return "(" endif endfunction inoremap <expr> <silent> ( MayCloseParentheses()
习惯性地加上了。不加应该也看不到什么吧。ceclinux 写了:我把manual看了一遍,<silent>这里不懂,为什么要避免回显,本来就不会回显的吧,谢谢lilydjwg 写了:很简单,我随手就可以给你写一个:代码: 全选
function MayCloseParentheses() if col('.') == col('$') return "()\<Left>" else return "(" endif endfunction inoremap <expr> <silent> ( MayCloseParentheses()
代码: 全选
function MayCloseParentheses()
"(当前指针的横坐标)是否等于(当前指针所在行的长度加一),即判断指针是否在当前行的末端
if col('.') == col('$')
"返回(),然后指针向左移一位(移入括号中)
return "()\<Left>"
else
return "("
endif
endfunction
"<expr>为对方法的映射
inoremap <expr> ( MayCloseParentheses()
呃,中间插()我是很少,一般中间插(然后再过一个word然后插)eexpress 写了:没注意看。
只是这要求,真写代码的,几乎用不上。
行中间插()是很正常的事情。
多插了,直接 normal 下 u 就行了。要是中间插了(),发现多插了麻烦就大了。。需要<Esc>lx