111

I'm using both Vim and MacVim (or well, trying to). I installed the Tagbar plugin but find it impossible to switch to the actual Tagbar window to make my selection.

I've been reading loads about window switching in VIM, found a lot of default keybindings (CMD+`, CTRL+W+ or ), tried setting my own. NONE worked.

I always use VIM for quick file edits and got intrigued by using it as my full-time IDE. After spending a full hour just trying to figure out how to switch a window I'm totally turned off by the idea though. Still, I feel I have to know. How do you switch the window? Am I being totally blind here?

1
  • 10
    Vim is one of those tools where everything makes perfect sense - after you know about it. Before then it may as well be in welsh.
    – Phoshi
    May 7 '11 at 19:13
172

Control+W followed by W to toggle between open windows and,

Control+W followed by H/J/K/L to move to the left/bottom/top/right window accordingly,

Control+W followed by Left/Down/Up/Right arrow to move to the left/bottom/top/right window accordingly.

6
  • 4
    Nope, not doing anything.
    – Naatan
    May 7 '11 at 18:14
  • 7
    Ugh, I was pressing them at the same time. Tried Ctrl+W, THEN (seperately) one of the last keys and it worked. Sigh. Thanks!
    – Naatan
    May 7 '11 at 18:15
  • 7
    Besides the H/J/K/L directional keys you can also hit W again (with or without Control) to switch back and forth between the previously focused window.
    – Caleb
    May 7 '11 at 18:33
  • 9
    The arrow keys can also be used besides h/j/k/l. Jan 4 '14 at 9:28
  • 4
    You can also add prefix the direction with a number if you need to go more than one window; e.g. C-w 2k
    – Walf
    Aug 1 '16 at 6:12
27

Control + W twice does the trick for me on Macbook Pro.

5
  • 3
    It does also work on Linux.
    – tomrozb
    Mar 4 '14 at 12:44
  • This is the only thing that's worked for me on OSX. None of those <C-w><h/j/k/l> or <C-w><C-h/j/k/l> things the internet says does anything. Too bad <C-w><C-w> only cycles through the windows rather than going directly... Sep 8 '16 at 4:59
  • 4
    Control + W sucks when running a terminal in a browser Sep 18 '18 at 13:39
  • Running a terminal in a browser... interesting. Btw. if it sucks, you can remap it to a different keys.
    – user254319
    Sep 11 '19 at 7:40
  • Surprisingly it worked on vim in termux(android terminal emulator.). Sep 7 '20 at 22:17
11

It's possible to remap these to a more convenient keys (i.e. instead of Control+W followed by h/j/k/l)

Add this to your .vimrc

nnoremap <C-H> <C-W>h
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-L> <C-W>l

After that, Control + h/j/k/l will move around the windows

1
  • This is nice. I placed it into my vimrc.
    – Enis Arik
    Jun 28 '21 at 14:40

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.