Switching between panes is a pain on my Mac keyboard. There is only one CTRL key and it's on the same side as the W key. I want to map a new keystroke to make this super efficient, preferably without using the CTRL key at all.

I'm wondering what other folks out there doing to switch between panes to make it as painless as possible. Thanks.

  • I really like this for cycling through panes: map <Tab><Tab> <C-W>w
    – StevieD
    Feb 12 '17 at 1:56

FWIW, on linux I'm using xmodmap and xcape to use the Enter key as the control modifier key when it's hold, and Enter when it's pressed.

I do something similar with the capslock key: control when it's hold, and escape when it's pressed.

I don't know Mac well enough to tell you if you could do something similar, but if you did, you would have 2 symmetric control keys, one on the left, the other on the right of the keyboard.

When you have 2 control keys easily accessible for your left and right little fingers, many key sequences involving the control modifier key become easier to type, imho.

In a file sourced by xmodmap (I think it could be ~/.Xmodmap), I have this code:

keycode 36 = Hyper_L
remove mod4 = Hyper_L
add control = Hyper_L
keycode 255 = Return
keycode 66 = Control_L
clear lock
add control = Control_L

These commands make the Enter and capslock key produce the Control_L keysym, when the keys are hold.

In a script executed after the machine has started, I have these commands:

xcape -e 'Control_L=Escape'
xcape -e 'Hyper_L=Return'

It restores the keysym Return on the Enter key, and the keysym Escape on the capslock key, when the keys are pressed briefly (< 500ms).

If you don't want to use external tools, you could remap the prefix C-w, which is used to perform various actions on Vim windows, to gw.

This idea is from justinmk. By default, gw is a normal operator to format a text-object, or a region of text covered by a motion. For example, you can format the current paragraph hitting gwip.
Even though you would lose this operator, you could still use gq instead, which seems a more powerful alternative.

gq also allows to format text, but, contrary to gw, you can control its behavior with the options 'formatexpr' and 'formatprg'.

The idea behind using gw as a prefix for managing your windows, is to take g, which Vim uses by default as a common prefix to build various commands / operators / motions (you can see most of them with :echo map(taglist('^g.$'), 'v:val.name')), and add w with the mnemonics window.

If you wanted to test this solution for a while, you could try this mapping:

nnoremap gw <C-w>

From then, to switch from a window to another, instead of hitting C-w w, you would hit gww.
To open the file under the cursor inside a horizontal split window, instead of hitting C-w f, you would hit gwf. And so on...

  • Very interesting. I will definitely come back to this and try these tips out.
    – StevieD
    Feb 12 '17 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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