Step 6 of 6

9. Operators Motions And Text Objects

Motions

A motion is any command that moves the cursor. We’ve learned a lot of these implicitly throughout the course so far. We know that gg takes us to the top of the file — that’s a motion. We know that w lets us jump from word to word — also a motion. We also know that we can use fX to jump to the next X on the line — again, it’s a motion!

Motions can be used in conjunction with operators. When you combine an operator with a motion — like dt; from the first section in this lesson — the operator is applied over the area that the motion covers.

Let’s experiment. Work through the checklist below — each one combines an operator we know with a motion we’ve picked up along the way.

  1. Yank to the top of the file Put the cursor anywhere in the demo text, then type ygg — the y operator over the gg motion.
  2. Delete to the next period Put the cursor at the start of a line in a paragraph, then type df. — the d operator over the f. motion.
  3. Delete a word Put the cursor on any word, then type dw — the d operator over the w motion.
Yank to the top of the file Put the cursor anywhere in the demo text, then type ygg — the y operator over the gg motion.

Next: Delete to the next period

Loading editor…