Faster Vim window navigation

Vim does two things when you open a file:

  • Copy the file into a buffer running in memory.
  • Open a window in the buffer so you can view and edit the file.

Like Tmux, Vim allows us to split windows and navigate between them. By splitting a window, you are technically duplicating the current buffer.

Here are the commands to split windows vertically and horizontally, respectively:

ctrl+w v or :vsp
ctrl+w s or :sp

The commands for switching between windows are:

ctrl+w h
ctrl+w j
ctrl+w k
ctrl+w l

I like to remap the window switching keys so I can press ctrl+hjkl.

map("n", "<C-h>", "<C-w>h")
map("n", "<C-j>", "<C-w>j")
map("n", "<C-k>", "<C-w>k")
map("n", "<C-l>", "<C-w>l")

It’s perhaps a minor improvement, but worth trying out imho. You can check out my dofiles here if you found this useful.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *