3

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 ¿?.

Kamil S.
  • 406
  • 3
  • 10

3 Answers3

4

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.)

ZyX
  • 52,536
  • 7
  • 114
  • 135
  • Oh… So that's it. Oh dear. Oh well, thanks a lot for the clarification! That's pretty much all I needed to know, even if I might have hoped for a different solution. – Kamil S. Jun 08 '11 at 20:04
  • 1
    @caminoix There are discussions about replacing very limited `\x80` vim own escapes with CSI sequences as there are much more problems with current implementation: compared to an absolute value of possible modifier(s)+smth shortcuts like ``, ``, ``, ... vim supports almost none of them, while with CSI all can be supported. When this code will finally be reworked I guess your problem will go away, though it may not happen until vim-7.4 or even vim-8.0. – ZyX Jun 09 '11 at 08:03
3

Avoid recursion with

inoremap ' ''<left>
Fritz G. Mehner
  • 16,550
  • 2
  • 34
  • 41
  • 2
    This isn't the problem. `imap a ab` and `inoremap a ab` both work equally well but neither wants to works with ‘. Clearly, the problem lies in remapping ‘ as `imap a ‘’` works as expected. – Kamil S. Jun 08 '11 at 06:34
0

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.

Prince Goulash
  • 15,295
  • 2
  • 46
  • 47
  • 1
    Thanks for trying but this doesn't work. Recursion is not a problem; `imap a ab` works fine. The problem is remapping the curly quote: ‘ (U+2018). `imap ‘ a` contains no recursion and fails the same way. – Kamil S. Jun 08 '11 at 13:41
  • 1
    @caminoix The fact that `imap something` works fine should not make you write `imap something`. Use `inoremap` unless you can answer the question «Why I can't use `nore` here?», it will save your time as number of mappings that can interfer with each other grows bigger. – ZyX Jun 08 '11 at 15:20
  • Understood. I guess I was too focused on my current problem to appreciate a general, if not quite relevant, advice. – Kamil S. Jun 08 '11 at 19:57