How does one switch between windows on VIM?

87

27

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?

Naatan

Posted 2011-05-07T17:59:23.013

Reputation: 959

9Vim 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 – 2011-05-07T19:13:01.207

Answers

125

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.

Wuffers

Posted 2011-05-07T17:59:23.013

Reputation: 16 645

3You can also add prefix the direction with a number if you need to go more than one window; e.g. C-w 2k – Walf – 2016-08-01T06:12:13.017

3Nope, not doing anything. – Naatan – 2011-05-07T18:14:28.017

6Ugh, I was pressing them at the same time. Tried Ctrl+W, THEN (seperately) one of the last keys and it worked. Sigh. Thanks! – Naatan – 2011-05-07T18:15:42.757

7Besides 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 – 2011-05-07T18:33:10.757

I get "E784: Cannot close last tab page" – Aleksandr Levchuk – 2012-10-30T15:35:53.823

9The arrow keys can also be used besides h/j/k/l. – Eugene Yarmash – 2014-01-04T09:28:07.983

21

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

paul bruno

Posted 2011-05-07T17:59:23.013

Reputation: 211

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 – 2016-09-08T04:59:33.033

2Control + W sucks when running a terminal in a browser – Quinn Wilson – 2018-09-18T13:39:28.610

Running a terminal in a browser... interesting. Btw. if it sucks, you can remap it to a different keys. – user254319 – 2019-09-11T07:40:27.860

3It does also work on Linux. – tomrozb – 2014-03-04T12:44:29.007

4

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

Nic Wanavit

Posted 2011-05-07T17:59:23.013

Reputation: 141