Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Editing Files  ›  Lesson

Vim — Editing with Verbs and Motions

Vim 15 minVim commands combine a verb such as d, y or c with a motion such as w or $, doubled for whole lines and repeatable with a count or the dot key.

Vim — Editing with Verbs and Motions

Anyone can open Vim, type some text and quit. What makes it fast is Normal mode, where short key combinations delete, copy and change whole words or lines without touching the mouse. They are easy to remember, because they're built like tiny sentences.

The rule

Verb then motion: d plus a move deletes that far.

A verb says what to do:

Verb Action
d delete (the text is kept so you can paste it)
y yank, which means copy
c change: delete, then drop into Insert mode

A motion says how far to go. These are the movement keys you already know: w (to the next word), $ (to the end of the line), G (to the end of the file).

Put them together:

  • dw deletes to the start of the next word.
  • d$ deletes to the end of the line.
  • cw changes the rest of the current word.
  • yG copies everything from here to the end of the file.

Typing the verb twice acts on the whole line: dd deletes a line and yy copies one. A number in front repeats: 3dd deletes three lines and 2w jumps two words.

The rest of the everyday toolkit:

Key Does
x delete the character under the cursor
p / P paste after / before the cursor
u undo
Ctrl+r redo
. repeat the last change
/word search forward for "word"; n finds the next match, N the previous one

And one command-line trick: :%s/old/new/g replaces every "old" with "new" in the whole file.

The shortcut

Say what you want out loud as "verb, how far", and the keys follow. For example, "delete three lines" is 3dd, "change to end of line" is c$, and "copy this line" is yy.

Asha tidies her notesStep 1 of 5
  1. Find the line

    She types /basil and presses Enter. The cursor jumps to "Pick basil every day every day".

A common slip is pressing u over and over and undoing further than you meant. Ctrl+r redoes one step at a time, so nothing is lost.

Drills

Answer fast — trust the rule.

quick drill

Which keys delete the current line?

quick drill

What does y stand for in Vim?

quick drill

You want to replace the rest of a word with new text. Which command?

quick drill

You just deleted a line with dd. What does pressing . do next?

quick drill

Which command replaces every "tomatos" with "tomatoes" across the whole file?

Remember

  • Verb then motion: d, y or c followed by a move acts that far. Double the verb for a whole line, and put a number in front to repeat.
  • Say it as "verb, how far" and the keys follow.
  • u undoes, Ctrl+r redoes, and . repeats your last change.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainSay it, then type it

Explain how Vim's verb-plus-motion idea works, then give the keys for: delete three lines, change the rest of a word, copy a line and paste it below, and repeat the last change.