BPm
BPm

Reputation: 2994

map alt+shift+] in vim

I want to map Alt+Shift+] and Alt+Shift+[ to gt and gT (so it works like on Mac)

How do I do it because it doesn't seem to work if I simply do this:

map <A-S-]> gt

Somehow ] needs to be escaped or something

Upvotes: 10

Views: 8878

Answers (2)

JaredPar
JaredPar

Reputation: 754595

There is nothing wrong with your definition there. Vim will correctly map that combination but it doesn't do it in quite the way you expect. What that mapping essentially says is

When Shift + Alt is hit in addition to ]

On a standard keyboard the ] character when combined with Shift will produce }. This means that Vim won't ever see the ] in combination with Shift but instead sees just }. You can leverage this though to get the behavior you're looking for. Try the following mappings instead (assuming standard QWERTY keyboard)

:map <A-}> gt
:map <A-{> gT

Upvotes: 21

steveha
steveha

Reputation: 76695

When you want to remap keys in vim, it is often a good idea to go to insert mode, hit Ctrl+V, and then type the key you want to remap. In this case, I get an Escape character (Ctrl+[) followed by }.

I do like using the <A-}> notation, but you could have solved the problem by editing your .vimrc file, entering the map text, then hitting Ctrl+V and hitting Alt+Shift+] and then adding gt. You would end up with a line like

map ^[} gt

(but with an actual Escape character rather than a ^ and a [ as I had to type here) and it would work.

P.S. When I tried this, Alt+Shift+[ worked fine, but Alt+Shift+] seems to be already in use in my copy of vim. I'm not sure exactly what it does but remapping it isn't working for me. When I type

:map <A-}>

it prints No mapping found.

Upvotes: 17

Related Questions