125

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?

James Mertz
  • 26,224
  • 41
  • 111
  • 163
Naatan
  • 1,345
  • 2
  • 13
  • 13
  • 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 07 '11 at 19:13

4 Answers4

186

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.

Wuffers
  • 19,020
  • 17
  • 95
  • 126
27

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

ale
  • 3,369
  • 6
  • 40
  • 52
paul bruno
  • 271
  • 3
  • 2
16

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.

tortal
  • 105
  • 5
Nic Wanavit
  • 261
  • 2
  • 4
0

These mappings allow cycling through the windows. Whereas something like <C-W>l stops at the most right window <C-w>w moves the focus to the the first window.

In your .vimrc:

nnoremap <C-h> <C-w>W
nnoremap <C-l> <C-w>w
molexi
  • 101
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 18 '23 at 20:00