easier way to navigate between vim split panes

VimNavigation

Vim Problem Overview


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.

Vim Solutions


Solution 1 - Vim

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>

Solution 2 - Vim

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>

Solution 3 - Vim

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

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

Solution 4 - Vim

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.

Solution 5 - Vim

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>

Solution 6 - Vim

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

ctrl+w ctrl+w

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOmnipresentView Question on Stackoverflow
Solution 1 - VimoverthinkView Answer on Stackoverflow
Solution 2 - VimdeadghostView Answer on Stackoverflow
Solution 3 - VimNafaa BouteferView Answer on Stackoverflow
Solution 4 - VimSam BrinckView Answer on Stackoverflow
Solution 5 - VimDmase05View Answer on Stackoverflow
Solution 6 - VimAMOL MISHRAView Answer on Stackoverflow