3

This is what I'm trying to achieve:

input

(|)foo

then pressing some key combination to get

output

(foo)|

or

(foo|)

I know this can be done with the autopairs plugin. In the docs they write that the default binding is M-}. I am using Vim/iTerm2/Mac, and I can't seem to figure out how to use the meta key.

In the autopairs plugin they let you remap another feature which is called Fast Wrap and is used to enclose a line with brackets. As you can understand, this is not exactly what I'm looking for, but even with Fast Wrap, which is mapped to M-e, I was not able to remap it or used it as is.

I googled and tried using the sed command in the terminal to see what the option key is outputting, then I tried to remap this output to M-}. Didn't work. Any ideas?

2 Answers 2

4

I don't think there's a need of having another mapping at all.

It's enough to press % once or twice to get on the right "paren". Then x$p and you're done.

2
  • Thanks, brilliant. I wish there was a cheatsheet for vim with all kind of handy stroke combinations like this one.
    – idankor
    Dec 7, 2019 at 9:27
  • 1
    @idankor Well, at least, xp seems to be in every "Vim tips and tricks" out of there. So "inventing" x$p is not a big deal.
    – Matt
    Dec 7, 2019 at 9:35
0

Maybe you can define another mapping for <M-e> mapping in insert mode. imap <M-e> shows that it is mappped to <C-R>=AutoPairsFastWrap()<CR>. So you can define another key map for that, for example:

inoremap <c-e> <C-R>=AutoPairsFastWrap()<CR>
4
  • 1
    Actually I found out that another plugin I have, vim-surround, can get me the line-enclosing functionality. But still my question remains for getting text to move inside a closed pair.
    – idankor
    Dec 7, 2019 at 9:15
  • Does the mapping above work or not?
    – jdhao
    Dec 7, 2019 at 9:18
  • Sorry for my ignorance, but is lower case 'c' the notation for the ctrl key, as the upper case 'C' is?
    – idankor
    Dec 7, 2019 at 9:22
  • 1
    yes, they both they represent ctrl. see :h key-notation inside Vim or Neovim.
    – jdhao
    Dec 7, 2019 at 9:54

Your Answer

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

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