Know Your VIM - Basic Cursor Movement

Last updated on  Sep 29, 2024  in  Vim  by  Amo Chen  ‐ 2 min read

Up, Down, Left, and Right

Remembering how to move up, down, left, and right in VIM doesn’t require any secret tricks. The reason h, j, k, l are used for left, down, up, and right is because on the developer’s keyboard at the time, hjkl also represented those directions.

Left, Down, Up, Right h j k l

Historical Note: ADM-3A Keyboard

Jumping Between Words

  • Jump to the start of the next word

mode: visual

key: w or SHIFT+RIGHT

Mnemonic: word

This is an apple.
>---->-->-->
w    w    2w
  • Jump to the start of the previous word

mode: visual

key: b or SHIFT+LEFT

Mnemonic: backward

This is an apple.
<----<--<--<
2b      b  b
  • Jump to the end of the next word

mode: visual

key: e

Mnemonic: end

This is an apple.
--->----->
   e     2e
  • Jump to the end of the previous word

mode: visual

key: ge

Mnemonic: go back to the end of word

This is an apple.
   <-----<------
 2ge     e
  • Jump to a specific letter on the right

mode: visual

key: f

Mnemonic: fly

This is an apple.
----->-->-------
   2fi  fa
  • Jump to a specific word on the left

mode: visual

key: F

Mnemonic: Opposite of lowercase f is uppercase F

Jump to Matching Bracket

mode: visual

key: %

Mnemonic: None for this one XD

function func() { return true; };
                <-------------->
                       %

This command works for {, [, (, which are often used in coding block symbols.

To add support for HTML angle brackets, use the following VIM setting:

:set mps+=<:>

mps stands for matchpairs.

Jump to Line Start or End

  • Line start

mode: visual

key: ^ or 0

Mnemonic: Start symbol ^ in regular expression

This is an apple.
^
  • Line end

mode: visual

key: $

Mnemonic: End symbol $ in regular expression

This is an apple.
                $

Jump Back to the Previous Position

If we jump from one position to an end (or somewhere else), we can press Ctrl + o to jump back to the previous position.