DaleSchool

Verbs and Objects: Operators + Motions

Beginner20min

Learning Objectives

  • Explain how operators (d, c, y) combine with motions
  • Use combinations like dw, d$, and cw
  • Combine numbers with motions
  • Understand Vim's command grammar

Working Code

Imagine this text is open in Vim:

const userName = "Alice";
const userAge = 25;
const userEmail = "alice@example.com";

With the cursor on the N of userName, try these commands:

dw      → delete "ame" (cursor to end of word)
d$      → delete from cursor to end of line
cw      → delete to end of word and enter Insert mode

Vim commands read like English sentences. "Delete (d) a word (w)" — a verb (operator) followed by an object (motion).

Try It Yourself

Let's refactor the variable names in this code:

let result = calculateTotal(price, tax);
let message = "Total: " + result;
console.log(message);
  1. Place the cursor on result and press cw. result is deleted and you enter Insert mode. Type total and press Esc.
  2. On the second line, place the cursor inside "Total: " and press ci" — that changes only what's inside the quotes (you'll learn this in the next lesson).
  3. On the console.log(message); line, press d$ to delete to the end of the line.

"Why?"

Vim is a language

Vim commands form a language with grammar rules. Once you learn the rules, you don't memorize commands — you combine them.

Operators (verbs):

KeyMeaningDescription
ddeleteDelete
cchangeDelete and enter Insert mode
yyankCopy

Motions (objects):

KeyMeaning
wTo start of next word
eTo end of current word
$To end of line
0To start of line
ggTo top of file
GTo end of file

Combination table

Combine operators and motions:

we$0ggG
ddwded$d0dggdG
ccwcec$c0cggcG
yywyey$y0yggyG

Three operators and six motions give you 18 commands.

Numbers make it even more powerful

Prefix the operator or the motion with a number to specify a count:

d2w     → delete 2 words
3dd     → delete 3 lines starting from the current line
y5j     → yank 5 lines downward from the current line

Line-wise shortcuts

Typing an operator twice applies it to the entire current line:

dd      → delete the current line
yy      → yank the current line
cc      → delete the current line and enter Insert mode

The difference between d and c

Both d and c delete text, but c automatically enters Insert mode afterward. Use c when you want to replace text with something else.

dw  → delete word, stay in Normal mode
cw  → delete word, enter Insert mode → ready to type the new word

Deep Dive

Common shortcut commands

Some operator+motion combos have shorthand keys:

ShortcutOriginalMeaning
Dd$Delete to end of line
Cc$Change to end of line
YyyYank the line (note: not y$)
xdlDelete one character
sclChange one character

Refactor variables

Open the code below in Vim and edit it using only operator+motion combinations.

var oldName = "hello";
var oldValue = 42;
console.log(oldName + oldValue);

Goals:

  1. Change every var to const (use cw)
  2. Rename oldName to greeting (use cw)
  3. Delete the last line entirely (use dd)

Hint: Search with /old to jump quickly.

question: "What does d2w do?" options:

question: "What's the difference between cc and dd?" options:

question: "Which command yanks from the cursor to the end of the line?" options: