81

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.

3
  • 28
    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 6, 2012 at 20:20
  • 8
    CTRL+W, [hjkl] to navigate the panes works perfectly! Thank you.
    – Jason Kim
    Aug 4, 2012 at 0: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. Jul 27, 2018 at 4:18

7 Answers 7

108

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>
5
  • 1
    I've had similar commands in my .vimrc for ages and can't live without them. Mine are variations, like map <C-J> <C-w>j<C-w>_ and map <C-H> <C-w>h<C-w>\| The _ and | additions force the split to its full width or height when I switch. May 19, 2011 at 4: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 <silent> <c-h> :wincmd h<CR> for nnoremap <silent> <c-h> <c-w>h
    – freitass
    May 19, 2011 at 14:09
  • 4
    I strongly recommend remapping caps lock to ctrl also. It makes using this answer even easier. May 19, 2011 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, 2012 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, 2012 at 21:24
27

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.

5
  • 2
    With simple search I found that splits are numbered from top-left to bottom-right. Jun 7, 2018 at 2:47
  • 1
    Great! 3 ctrl-w ctrl-w
    – towry
    May 21, 2019 at 8:21
  • 1
    "With simple search I found that splits are numbered from top-left to bottom-right." Yes, and indexing starts at 1.
    – firebush
    Jan 18, 2022 at 23:52
  • 1
    It is never to late to share nice info like this -- thanks a lot, Nafaa
    – solr
    Sep 12, 2022 at 2:09
  • Any idea how to map this to something shorter like <C-split_number>? E.g., I'd want <C-3> to navigate to the 3rd split
    – molexi
    Feb 18 at 20:17
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>
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.

3
  • I thought that Vim sees <c-k> as the same ascii code as <c-s-k>. So doing the above will override the prior mappings.
    – Justin
    May 27, 2011 at 17:24
  • I actually use the arrow keys so that could be
    – Sam Brinck
    Jun 1, 2011 at 16:01
  • This indeed jams up the accepted answer's mapping. See also stackoverflow.com/questions/1506764. You could use something like this instead: "nmap <silent> <leader><c-k> :wincmd K<CR>" and equivalent for J, H, L. Jul 27, 2018 at 4: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>
2

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

ctrl+w ctrl+w
1
  • In the question: Currently I use CTRL+W+W to move from one pane to another. So...
    – Eric Aya
    May 11, 2021 at 6:55
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.