79

I am using NERDTree on vim and usually open files with i

Is there an easy way to switch between different panes? Currently I use CTRL+W+W to move from one pane to another.

Jason Down
  • 21,731
  • 12
  • 83
  • 117
Omnipresent
  • 29,434
  • 47
  • 142
  • 186
  • 26
    I realize this is answered, but did you know you can use `CTRL+W, [hjkl]` to navigate the panes/frames? That way if you have 4-6 windows open, you don't have to hit `CTRL+W,W` over and over. I like overthink's keybindings, but then again I enjoy consistency across systems, and when I get used to keybindings I have a hard time relearning them. If I started using CTRL-H to go left, I'd probably end up hitting CTRL-H on systems w/o the keybinding, which actually prints the backspace character by default. Hell I used to press CTRL-H to delete things because the backspace didn't work on my machine! – Kasapo Jul 06 '12 at 20:20
  • 7
    `CTRL+W, [hjkl]` to navigate the panes works perfectly! Thank you. – Jason Kim Aug 04 '12 at 00:05
  • 1
    The CTRL+W… mappings are problematic, because CTRL+W closes tabs in browsers and other applications. Sometimes a different window is focused than you thought and then … curses. – Richard Möhn Jul 27 '18 at 04:18

7 Answers7

107

Long ago I found a tip (once on vim.org, now on wikia, apparently) that I've stuck with. Remap ctrl-[hjkl] to navigate splits. It has served me well.

" Use ctrl-[hjkl] to select the active split!
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>
rr-
  • 14,303
  • 6
  • 45
  • 67
overthink
  • 23,985
  • 4
  • 69
  • 69
  • 1
    I've had similar commands in my .vimrc for ages and can't live without them. Mine are variations, like `map j_` and `map h\|` The `_` and `|` additions force the split to its full width or height when I switch. – the Tin Man May 19 '11 at 04:38
  • 1
    I don't know why but when changing to the `h` direction my destination window was being messed up. Since the `:wincmd` only makes difference off the normal mode and the mappings are used exactly in the normal mode, I have replaced `nmap :wincmd h` for `nnoremap h` – freitass May 19 '11 at 14:09
  • 4
    I strongly recommend remapping caps lock to ctrl also. It makes using this answer even easier. – Greg Sexton May 19 '11 at 19:29
  • @RafaelRendonPablo I've used it successfully in various terminals: urxvt, gnome-terminal, maybe others. Is it possible your terminal application is trapping Ctrl? – overthink Dec 17 '12 at 14:56
  • Mm, maybe, I am using `tmux` and it uses `Ctrl + a` as prefix, I'll try disabling `tmux`. Thanks :) – rendon Dec 17 '12 at 21:24
22

I know this is an old question, but I have a perfect way. Using the number of the split.

split_number C-w C-w

The panes are numbered from top-left to bottom-right with the first one getting the number 1.

for example to go to split number 3 do this 3 C-w C-w, press Ctrl-w twice.

Nafaa Boutefer
  • 2,169
  • 19
  • 26
20

I prefer hitting single keys over hitting key-chords. The following maps pane movement to arrow keys:

" Smart way to move between panes
map <up> <C-w><up>
map <down> <C-w><down>
map <left> <C-w><left>
map <right> <C-w><right>
deadghost
  • 5,017
  • 3
  • 34
  • 46
3

Key mappings are definitely the way to go. I use the mappings mentioned by overthink. I also include the following mappings in my vimrc to move the splits themselves.

" Move the splits arround!
nmap <silent> <c-s-k> <C-W>k                                                                                                                       
nmap <silent> <c-s-j> <C-W>j                                                                                                                       
nmap <silent> <c-s-h> <C-W>h                                                                                                                       
nmap <silent> <c-s-l> <C-W>l

This makes it so that if the split opens in the wrong spot (lets say the left side and I want it on the right) I go to that split and hit <C-S-l> and the split moves where I want it to.

Sam Brinck
  • 891
  • 1
  • 7
  • 11
  • I thought that Vim sees as the same ascii code as . So doing the above will override the prior mappings. – Justin May 27 '11 at 17:24
  • I actually use the arrow keys so that could be – Sam Brinck Jun 01 '11 at 16:01
  • This indeed jams up the accepted answer's mapping. See also https://stackoverflow.com/questions/1506764/. You could use something like this instead: "nmap :wincmd K" and equivalent for J, H, L. – Richard Möhn Jul 27 '18 at 04:16
2

In order to be consistent with changing tabs via gt & gT, I'm currently trying out the g mappings for changing splits. I tend to hit the shift key as I go for the Ctrl key so this helps me avoid that mistake until I get better at not doing so.

nnoremap gh <C-W><C-H>
nnoremap gj <C-W><C-J>
nnoremap gk <C-W><C-K>
nnoremap gl <C-W><C-L>
Dmase05
  • 1,059
  • 15
  • 18
1

I have mapped ctrl+w ctrl+w to <tab> (under normal mode as in normal mode tab does not have any use)and that's have made my life easier as now I can switch between panes easily by pressing <tab>.

For switching to a particular pane, I can press <i> + <tab> to switch between panes as split window panes also got their own number which can replace i.

Ex. i = 1,2...n.

TeraByte
  • 71
  • 1
  • 6
-1

Very easy way of achieving it. Type this shortcut twice, and that should work

ctrl+w ctrl+w