122

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, 2011 at 19:13

3 Answers 3

183

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, 2011 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, 2011 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, 2011 at 18:33
  • 9
    The arrow keys can also be used besides h/j/k/l. Jan 4, 2014 at 9:28
  • 5
    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, 2016 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, 2014 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, 2016 at 4:59
  • 4
    Control + W sucks when running a terminal in a browser Sep 18, 2018 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, 2019 at 7:40
  • Surprisingly it worked on vim in termux(android terminal emulator.). Sep 7, 2020 at 22:17
15

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 switch window focus.

3
  • This is nice. I placed it into my vimrc.
    – Enis Arik
    Jun 28, 2021 at 14:40
  • 1
    This is clutch for those running a terminal in a browser (as mentioned in another comment) since Ctrl+W on Windows is "close window". Oof.
    – Excel Help
    Jun 22, 2022 at 12:07
  • ❤️ that one! Thanks! Aug 20, 2022 at 0:07

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.