2.2 β Word-Based Movement
2.2 β Word-Based Movement#
Moving character by character is precise but slow. Word-based movement lets you jump through text much faster while maintaining precision.
Words vs WORDs#
Vim has two definitions of a βwordβ:
word (lowercase)#
A sequence of letters, digits, and underscores, OR a sequence of other non-blank characters.
Examples of separate words:
hello β 1 word
hello_world β 1 word
hello-world β 3 words (hello, -, world)
hello.world β 3 words (hello, ., world)
$variable β 2 words ($, variable)
WORD (uppercase)#
A sequence of non-blank characters separated by whitespace.
Examples of separate WORDs:
hello β 1 WORD
hello_world β 1 WORD
hello-world β 1 WORD
hello.world β 1 WORD
$variable β 1 WORD
Think of it this way: words respect punctuation; WORDs only care about spaces.
Word Movement Commands#
Forward Movement#
| Command | Action |
|---|---|
w | Move to start of next word |
W | Move to start of next WORD |
e | Move to end of current/next word |
E | Move to end of current/next WORD |
Backward Movement#
| Command | Action |
|---|---|
b | Move to start of current/previous word |
B | Move to start of current/previous WORD |
ge | Move to end of previous word |
gE | Move to end of previous WORD |
Visualizing the Difference#
Consider this line:
user.firstName = "John";
Using w (word):
user.firstName = "John";
^ ^ ^ ^ ^
w w w w w
Stops at: user, firstName, =, "John", ;
Using W (WORD):
user.firstName = "John";
^ ^ ^
W W W
Stops at: user.firstName, =, "John";
Using Counts#
All word motions accept counts:
| Command | Action |
|---|---|
3w | Move forward 3 words |
2b | Move back 2 words |
4W | Move forward 4 WORDs |
2e | Move to end of 2nd word ahead |
Word Motions with Operators#
Word motions combine powerfully with operators:
Deleting Words#
| Command | Action |
|---|---|
dw | Delete from cursor to start of next word |
de | Delete from cursor to end of word |
db | Delete from cursor to start of word |
diw | Delete entire word (cursor anywhere in word) |
daw | Delete word plus surrounding space |
Changing Words#
| Command | Action |
|---|---|
cw | Change from cursor to end of word |
ce | Change from cursor to end of word (same as cw) |
ciw | Change entire word |
caw | Change word plus surrounding space |
cW | Change from cursor to end of WORD |
Yanking Words#
| Command | Action |
|---|---|
yw | Yank from cursor to start of next word |
yiw | Yank entire word |
yaw | Yank word plus surrounding space |
The iw vs aw Distinction#
When using text objects (covered in Chapter 4), thereβs an important difference:
iwβ Inner word: Just the word itselfawβ A word: The word plus one side of surrounding whitespace
Example: In hello world goodbye
β cursor
hello world goodbye
^^^^^ iw selects "world"
^^^^^^ aw selects "world " (including trailing space)
This matters when deleting:
diwon βworldβ leaveshello goodbye(double space)dawon βworldβ leaveshello goodbye(clean)
Practical Examples#
Example 1: Navigating Code#
const calculateTotal = (items, taxRate) => {
From the start of the line:
wβcalculateTotalwβ=wβ(wβitemsWfrom start βcalculateTotalWβ=Wβ(items,
Example 2: Editing a Variable Name#
You want to change oldName to newName:
const oldName = "value";
^cursor
ciwthen typenewName- OR
cwthen typenewName(if cursor at start of word)
Example 3: Deleting a Method Call#
object.oldMethod().result
^cursor on 'o' of oldMethod
dWdeletesoldMethod().result(from cursor to space)diwdeletesoldMethoddf)deletesoldMethod()(usingffrom next lesson)
When to Use word vs WORD#
Use w, e, b (word) when:#
- Working with individual identifiers
- Editing within punctuated text
- You need fine-grained control
Use W, E, B (WORD) when:#
- Navigating quickly through code
- Skipping over punctuation-heavy sections
- Moving through URLs, paths, or compound expressions
Practice Exercises#
Exercise 1: Basic Word Navigation#
- Open a file with prose text
- Press
wrepeatedly to move forward word by word - Press
brepeatedly to move backward - Press
eto move to word ends
Exercise 2: word vs WORD#
- Create a line:
user.name = getData().value; - Go to start of line with
0 - Press
wrepeatedly, note where it stops - Go back with
0 - Press
Wrepeatedly, compare the stops
Exercise 3: Counts with Words#
- Open any text file
- Press
5wto move forward 5 words - Press
3bto move back 3 words - Press
2eto move to 2nd word end ahead
Exercise 4: Deleting Words#
- Create line:
delete this word here - Position on βthisβ
- Press
dwβ what happens? - Undo with
u - Press
diwβ compare - Undo with
u - Press
dawβ compare
Exercise 5: Changing Words#
- Create line:
oldValue = calculate(oldInput) - Navigate to
oldValue - Press
ciw, typenewValue, pressEsc - Navigate to
oldInput - Press
ciw, typenewInput, pressEsc
Common Mistakes#
Using dw When You Mean diw#
dw deletes from cursor to next word, which may leave partial words if cursor isnβt at word start.
Fix: Use diw to delete the entire word regardless of cursor position.
Forgetting ge#
Many Vim users know w, e, b but forget ge (end of previous word).
Use case: Youβre at the start of a word and want to go to the end of the previous word.
Over-using Character Movement#
If youβre pressing l many times to get to a word, you should use w, e, or b instead.
Summary#
| Motion | word (lowercase) | WORD (uppercase) |
|---|---|---|
| Forward to start | w | W |
| Forward to end | e | E |
| Backward to start | b | B |
| Backward to end | ge | gE |
| With Operators | Command |
|---|---|
| Delete word | dw, diw, daw |
| Change word | cw, ciw, caw |
| Yank word | yw, yiw, yaw |
Word-based navigation is a major upgrade from character movement. Master it, and youβll move through text significantly faster.