In Vim/Vi, how do you move the cursor to the end of the previous word?

VimVi

Vim Problem Overview


In Vim's normal mode:

  • e goes to the end of the next word
  • w goes to the beginning of the next word
  • b goes to the beginning of the previous word

How do you move the cursor to the end of the previous word?

Vim Solutions


Solution 1 - Vim

Unfortunately it's not a single key... but ge is what you're looking for, I think.

Solution 2 - Vim

Try ge:

ge                      Backward to the end of word [count] |inclusive|.

                                                        *gE*
gE                      Backward to the end of WORD [count] |inclusive|.

Solution 3 - Vim

as seen on VIM manual (section 03.1), you can use ge to go to the end of previous word

Solution 4 - Vim

You may also want to do these to go to the space preceding a word (one character after ge: (both are only 2 keys)

  1. FSpace will take you to the space after the previous word
  2. Bh will also do that, in most cases.

The exception is when you are at the beginning of a line, in which case

  1. k$ does something similar, in 3 keypresses

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionClosureCowboyView Question on Stackoverflow
Solution 1 - VimjkerianView Answer on Stackoverflow
Solution 2 - VimStephanView Answer on Stackoverflow
Solution 3 - VimEduardo CostaView Answer on Stackoverflow
Solution 4 - VimNathanView Answer on Stackoverflow