256

When you're using vim, you can move forward word by word with w. How do I go backwards?

joslinm
  • 7,845
  • 6
  • 49
  • 72
  • 9
    http://www.viemu.com/vi-vim-cheat-sheet.gif This has a lot of the vim keys in an easy graphical format. I highly recommend printing it and having it next to your computer if you are going to be using vim a lot. – Sam Brinck Feb 09 '12 at 15:39
  • possible duplicate of [How to move one word left in vi editor](http://stackoverflow.com/questions/4488979/how-to-move-one-word-left-in-vi-editor) – Arslan Ali Jul 07 '15 at 12:11
  • 1
    Also see: http://stackoverflow.com/questions/5125270/in-vim-vi-how-do-you-move-the-cursor-to-the-end-of-the-previous-word if interested in going backwards to the end of previous word - using ge and gE – arcseldon Jan 19 '16 at 08:19

4 Answers4

336

Use b to go back a word.

You may also want to check out W and B to advance/go back a WORD (which consists of a sequence of non-blank characters separated with white space, according to :h WORD).

daaawx
  • 3,273
  • 2
  • 17
  • 16
gefei
  • 18,922
  • 9
  • 50
  • 67
  • 60
    For completeness sake `ge` will go backward to the end of a word. `gE` will go backward to the end of a `WORD` – Peter Rincker Feb 09 '12 at 21:24
  • 5
    @Peter Rincker: and `e` and `E` will go forward. – Benoit Feb 10 '12 at 14:28
  • 3
    What's the difference between b and B? Or w and W? Behavior seems the same. – Casey Patton Oct 11 '13 at 19:48
  • 1
    @CaseyPatton: The uppercase versions treat any sequence of non-whitespace as words; lowercase is similar to `\w|\S`. See `:help word` and `:help WORD` for more details. – rninty Dec 12 '13 at 19:40
  • Also worth considering ge and gE for going backwards to the end of the previous word. Also, see http://stackoverflow.com/questions/5125270/in-vim-vi-how-do-you-move-the-cursor-to-the-end-of-the-previous-word – arcseldon Jan 19 '16 at 08:18
  • 1
    `ge` is the correct answer here, not `b` or `W` or `B` – untore Dec 30 '16 at 10:32
106

It helps for me to think of it as:

b to go to beginning of current or previous word

w to go the beginning of next word

e to go to the end of current or next word

ge to go the end of the previous word

Try :h word-motions for more details and how to combine them with operations.

arcseldon
  • 35,523
  • 17
  • 121
  • 125
Steve McKinney
  • 3,183
  • 1
  • 23
  • 26
9

Alternatively, if you use w, b, W, and B to navigate lines by hopping over words, consider the following alternatives which can be faster if used correctly.

f<char>    # jump to next occurrence of <char> to right (inclusive)

or

F<char>    # jump back to next occurrence of <char> to left (inclusive)

If your words are separated by spaces

If your words are separated by <space> you can hop over words by spaces:

f<space>;;;; where ; repeats the previous command, so you hop forward by spaces

F<space>;; to hop backwards by space

If your words are separated by punctuation and not spaces

just replace <char> with punctuation, for example .

The punctuation method is not efficient for scrolling through, but if you know where you want to jump, it can usually get there in a jump or two.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
brother-bilo
  • 490
  • 4
  • 11
8

use "b" to move back - just tested in vi - works fine.

FreudianSlip
  • 2,870
  • 25
  • 24