Monolune

Intuitive Vim Cursor Movements

When lines in vim are too long, they are automatically split over multiple lines. This can be a problem when trying to navigate up and down by using j or k (or even the up and down keyboard arrows) because those commands only move the cursor by the line in the file, and not by the lines you see on the screen. This cursor movement behaviour is not entirely intuitive; moving by lines on the screen is more natural for most people.

Vim cursor movement keys

Vim has commands for moving the cursor by lines on the screen: gj and gk moves the cursor up and down respectively. To make this the default, remap the keys for normal mode and visual mode by adding the following to your .vimrc:

noremap j gj
noremap k gk
noremap <up> gk
noremap <down> gj

" For up and down keyboard buttons when in insert mode.
inoremap <up> <C-O>gk
inoremap <down> <C-O>gj

Remember to reload your existing Vim instances to make use of the remapping.

Share: Submit to reddit Submit to hackernews Submit to facebook

Posted on in Computing. (Modified: ). Tags: Guide, Vim.