VIM Cursor Motions

Table of Content

The scenarios focus on VIM cursor motions using keyboard.

Baby steps - moving Cursor by HJKL keys

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor left h :help h
2 Move cursor down j :help j
3 Move cursor up k :help k
4 Move cursor right l :help l
5 Move cursor 2 characters down 2j  

If you have trouble to memorize k for motion up and j for motion down, use this trick to remember.

  • To remember j as motion down, think of a street, place or anywhere with a letter J that is south of your location.
  • To remember k as motion up, think of a street, place or anywhere with a letter K that is north of your location.

Moving line up (preserve column position)

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor up. Preserve column position. k  

Moving line up (change column position)

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor up and to first column. - :help -

Moving line down (preserve column position)

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor down. Preserve column position. j  

Moving line down (change column position)

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor down and to first column. + :help -

Moving cursor within a line

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to end of the line $ :help $
2 Move cursor forward to letter t in sit, last non-blank character g\_ :help g_
3 Move cursor backward to beginning of the line 0 :help 0
4 Move cursor backward to letter L in lorem, first non-blank character ^ :help ^

VIM wrap mode affects the cursor with these keys if the line is wrapped.

Moving cursor to first letter

To words forward

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to letter -, the letter between four and five w  
Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to letter f in five 2w  

To WORDS forward

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to letter s in six W  
Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to letter s in seven 2W  

How to determine cursor location for uppercase and lowercase w? Read here. In short, :help ‘iskeyword’ option affects the logic.

To words backward

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor backward to letter f in four b  

To DWORDS backward

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor backward to letter t in three B  
Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor backward to letter t in two 2B  

Moving cursor to last letter

To words forward end of word

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to letter r in four e  

To WORDS forward end of word

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to letter e in five E  
Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to letter x in six 2E  

To words backward end of word

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor backward to letter - between three and four ge  
Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor backward to last letter e in three 2ge  

To WORDS backward end of word

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor backward to letter o in two 2gE  

Moving cursor to a specific character

Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor forward to letter i in five fi :help f
2 Repeat the process above in the same direction ; :help ;
Step VIM Buffer I Intent to… Keys to Press Note
0 Starting point. Cursor in yellow.    
1 Move cursor backward to second letter e in three 2Fe :help F
2 Repeat the process above but in opposite direction , :help ,

t{char} :help t and T{char} :help T has similar effect as f{char} and F{char}, but cursor position placement is difference. I find these keys are useful for deletion.

Moving cursor to sentence

I Intent to… Keys to Press Note
Move cursor next sentence ) :help )
Move cursor previous sentence ( :help (

Moving cursor to paragraph

I Intent to… Keys to Press Note
Move cursor next paragraph { :help {
Move cursor previous paragraph } :help }

Reference