Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigating between VIM windows in an alternative way

I am using CtrlW to navigate between VIM split windows. Does there exist any different ways to do this?

For example, if I have, say, 5 split windows opened and want to navigate to the top left corner window, CtrlW is very uncomfortable as it requires many keystrokes.

like image 445
Adas Avatar asked Jan 28 '12 17:01

Adas


People also ask

How do I toggle between windows in Vim?

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.

What is Wincmd in Vim?

Example: :wincmd j Moves to the window below the current one. This command is useful when a Normal mode cannot be used (for the |CursorHold| autocommand event). Or when a Normal mode command is inconvenient. The count can also be a window number.

What is Ctrl W in Vim?

Ctrl-w = tells Vim to assign an equal number of lines to each viewport. To move between the viewports while working, use Ctrl-w j to move down, and Ctrl-w k to move up.


2 Answers

Why not setup something like these?

nnoremap <C-h> <C-w>h nnoremap <C-j> <C-w>j nnoremap <C-k> <C-w>k nnoremap <C-l> <C-w>l 

Much quicker ...

like image 69
Rook Avatar answered Oct 03 '22 08:10

Rook


You can use <number><c-w>w to switch to a particular window. So 1<c-w>w goes the the first window (top left corner) 11<c-w>w moves to the last window (here I assume you have less than 11 splits).

I also find the following mappings convenient and have them in my .vimrc

nnoremap <tab> <c-w> nnoremap <tab><tab> <c-w><c-w> 

which I use for window stitching (for some reason if I don't define the second mapping if I hit tab twice I get a message "no identifier under the cursor)

Reading the help page for CTRL-W, there is even a more convenient way than 1<c-w>w and 11<c-w>w to go to the first and last window: <c-w>t goes to the top window and <c-w>b goes to the bottom window.

like image 34
skeept Avatar answered Oct 03 '22 06:10

skeept