如何让vim能自动匹配引号?
我想要让
vim
能够匹配引号?
就像匹配括号一样,能用
%
找到匹配的另一个引号,光标在一个引号的时候,这个引号和它匹配的另一个引号变高亮,请问要怎么设置?
koveas.
10 years, 6 months ago
Answers
Sherry
answered 10 years, 6 months ago
将下面内容加入.vimrc文件中即可
:inoremap ( ()i
:inoremap ) =ClosePair(')')
:inoremap { {}i
:inoremap } =ClosePair('}')
:inoremap [ []i
:inoremap ] =ClosePair(']')
:inoremap i
:inoremap > =ClosePair('>')
:inoremap " ""i
:inoremap ' ''i
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\"
else
return a:char
endif
endf
如果有问题,试一下下面的:
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
Kokami
answered 10 years, 2 months ago