79

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?

  • 9
    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
119

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.

  • 2
    Nope, not doing anything. – Naatan May 7 '11 at 18:14
  • 5
    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
  • 6
    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. – Eugene Yarmash Jan 4 '14 at 9:28
  • 3
    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
19

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

  • 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... – wren romano Sep 8 '16 at 4:59
  • 2
    Control + W sucks when running a terminal in a browser – Quinn Wilson 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 at 7:40
1

Its possible to remap this to a more convinient keys instead of the annoying Control+W

in .vimrc

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

now control + h/j/k/l will move around the windows

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.