开发者

Auto closing curly quotation marks in Vim

I'd like to set up Vim to auto close the pair of ‘ and ’ (curly quotation marks).

I've tried to configure all the five plugins I could find (two autoclose's开发者_如何学编程, surround, closepairs and delimitmate) but with no success. I don't even seem to be able to remap ‘ at all (with :imap ‘ ‘’<left> or similar).

I use Vim 7.3 on Arch Linux and uim 1.7.0 input method; I insert ‘ and ’ through a shortcut defined in .XCompose. Remapping works just fine for my other compose-key shortcuts, like ¡! or ¿?.


It looks much like a vim bug, in particular, bug with internal vim escape sequences which all start with \x80 (second byte of the character in question is \x80) and encode various things like NULLs, function keys or \x80 byte itself. I guess you can dig into vim source code and find there how this byte is escaped and try to replace last byte of with this escape code or wait until this will be fixed (though I won't expect fix to come soon: here is quote from todo.txt

UTF-8: mapping a multi-byte key where the second byte is 0x80 doesn't appear to work. (Tony Mechelynck, 2007 March 2)

So, you see problem is known for four years and is not yet fixed.)


Avoid recursion with

inoremap ' ''<left>


You can achieve this with a small function:

function! CloseQuotes()
    normal! i'' 
    startinsert
endfunction

and then map it to ' in the following way:

inoremap ' <ESC>:call CloseQuotes()<CR>

The important thing is the exclamation mark in normal!, which prevents the mapping being recursive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜