vim Movement Basic Motion


Example

Remarks

  • Every motion can be used after an operator command, so the command operates on the text comprised by the movement's reach.
  • Just like operator commands, motions can include a count, so you can move by 2words, for example.

Arrows

In Vim, normal arrow/cursor keys () work as expected. However, for touch-typers, it's easier to use the hjkl alternative keys. On a typical keyboard, they're located next to each other on the same row, and easily accessible using right hand. The mnemonic technique to remember which is which among them goes like this:

  • h/l — those are located "most to the left/right" among the four letters on the keyboard, so they are equivalent to "going left/right" respectively;
  • j — lowercase "j" has its tail going "down" below typical letters, like a small arrow - so it's equivalent to "going down";
  • k — conversely, lowercase "k" has its "ascender" going "up" above typical letters, like a small pointer - so it's equivalent to "going up".

Basic motions

All commands below should be done in normal mode.

CommandDescription
h or leftgo [count] characters to the left
j or downgo [count] characters below
k or upgo [count] characters above
l or rightgo [count] characters to the right
gggo the first line, or [count]'th line, if given
Hgo to the first line in the visible screen
Mgo to the middle line in the visible screen
Lgo to the last line in the visible screen
Ggo the last line, or [count]'th line, if given
Home or 0go to first character of the line
^go to first non-blank character of the line
+go down one line to first non-blank character
-go up one line to first non-blank character
$ or Endgo to the end of the line (if [count] is given, go [count - 1] lines down)
|go to the [count]'th character or go to the beginning of the line if count not specified
f{char}go to [count]'th occurrence of {char} to the right inclusive
F{char}go to [count]'th occurrence of {char} to the left inclusive
t{char}go to [count]'th occurrence of {char} to the right exclusive
T{char}go to [count]'th occurrence of {char} to the left exclusive
;repeat latest f, t, F or T [count] times
,repeat latest f, t, F or T, in the opposite direction, [count] times
wgo to the beginning of the next word
bgo to the beginning of the previous word
ego to the ending of the next word
gego to the ending of the previous word
%go to matching pairs, e.g (), [], {}, /* */ or #if, #ifdef, #else, #elif, #endif
{ }previous/next paragraph
[{]}beginning/ending of block
'{char}Go to mark (mark with m{char})
<C-B><C-F>previous/next page
<C-O><C-I>Go back or foward in the "jump list" (requires jumplist feature, see :help jumps)

Note: b, e, and w consider a word to be letters, numbers, and underscores by default (this can be configured with the iskeyword setting). Each of these can also be capitalized, causing them to skip over anything that isn't whitespace as well.

Note: Vim recognizes two kinds of movement: operator movement (:help movement) and jumps (:help jumplist). Movements like those executed with g (gg, G, g,) count as jumps, as do changes. Changes get their own jumplist, which is navigable as mentioned above via g, and g; (see :help changelist). Jumps are not treated as motion commands by Vim

When moving up or down across lines, the cursor retains its column as would be expected. If the new line is too short the cursor moves to the end of the new line. If the column is beyond the end of the line, the cursor is displayed at the end of the line. The initial column number is still retained until an action is taken to alter it (such as editing text or explicitly moving column).

If a line's length exceeds the width of the screen, the text is wrapped (under default settings, this behaviour can be configured). To move through lines as displayed on screen, rather than lines within the file, add g in front of the usual command. For example, gj will move the cursor to the position displayed one line below its current position, even if this is in the same line of the file.