1

I want to imap the sequence ^^ to ^{}<++> and then place the cursor inside the brackets. (This is handy when editing Latex code and is a nice feature of the vim latex suite which I have recently abandoned)

The straight forward approach doesn't work for me:

:imap ^^ ^{x}<++><esc>Fxs

Any ideas?

2 Answers 2

3
inoremap ^^ ^{}<++><Left><Left><Left><Left><Left>

Is ugly, but it should work.

See :h i_<Left>

7
  • Thanks, it does. But not in GVIM for some reasons. Have you tried it there?
    – Jan
    Commented Aug 16, 2016 at 14:40
  • Works in gVim for me. Have you re-mapped <Left>? Try :imap <Left>.
    – Tumbler41
    Commented Aug 16, 2016 at 14:41
  • I don't get it to work in gvim. Even so when I start it blank via gvim -u NONE.
    – Jan
    Commented Aug 16, 2016 at 14:53
  • How about if you :set nocompatible and then bind it? That seemed to work for me.
    – Tumbler41
    Commented Aug 16, 2016 at 14:59
  • @Jan You should probably use inoremap instead of imap. Not sure if that fixes it, but it might. Commented Aug 16, 2016 at 15:15
1

With lh-brackets (which proposes similar features, and which is compatible with latex-suite when installed -- latex-suite installs a plugin named imaps.vim that has side effects with mappings (*)), It would be:

:Brackets ^{ } -trigger=^^ -visual=0 

The placeholder will be added as well, and the result will be compatible with vim 7.4-patchnumberIdontremember redo feature.

(*) If you are still able to use placeholders (as I see you'll like to have <++> after the closing bracket), and if you are not using lh-brackets, it's likely you have imap.vim still active. This may explain why the mappings proposed in the other answers don't work in your case. Another possible explanation is that ^ is a dead key on some keyboard. Half the time it's the case on my French systems.

3
  • thanks for this -- well analysed. I have imaps.vim installed. I thought that gvim -u None will not load plugins but it actually does. I will try your solution in a second.
    – Jan
    Commented Aug 18, 2016 at 11:29
  • when finally executing the map ^^, I end up with this error message: Error detected while processing function lh#brackets#opener[71]..lh#map#insert_s eq: line 4: E117: Unknown function: lh#dev#reinterpret_escaped_char
    – Jan
    Commented Aug 18, 2016 at 11:50
  • lh-brackets has a few dependencies. Don't forget to install them. At least lh-vim-lib and lh-dev are required. Commented Aug 18, 2016 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.