Vim Editing
100%

Advanced Text-Fu · Lesson 7

Vim Editing

Learn how Vim combines operators, motions, registers, puts, and undo commands for text editing.

Vim editing commands often combine an operator with a motion or text object. This grammar lets the same actions work at character, word, line, and larger scopes. Press Esc before practicing to return to Normal mode.

Combining an Operator with a Motion

The general form is:

[count] operator [count] motion

Common operators include:

  • d: Delete text.
  • c: Change text, then enter Insert mode.
  • y: Yank, or copy, text.

For example, dw deletes through the w motion, while d$ deletes from the cursor through the end of the line. 2dw applies the delete across two word motions.

In Normal mode, what does d$ do?

Editing Characters and Lines

Some commands are convenient shortcuts:

  • x: Delete the character under the cursor.
  • dd: Delete the current line linewise.
  • 3dd: Delete three lines starting with the current line.
  • cc: Change the current line and enter Insert mode.
  • r{char}: Replace the character under the cursor with {char}.
  • R: Enter Replace mode until Esc is pressed.

Repeating an operator, as in dd, makes it linewise. A count expands the number of lines.

Which Normal-mode command deletes the current line and the next two lines?

Changing Text and Entering Insert Mode

The c operator removes the selected text and enters Insert mode so you can type a replacement:

  • ce: Change through the end of the word.
  • c$: Change through the end of the line.
  • cc: Change the complete current line.
  • ciw: Change the inner word under the cursor.
  • caw: Change a word text object, including surrounding spacing as Vim defines it.

The behavior of cw has a historical special case and often acts like ce. Text objects such as iw can make the intended boundary clearer.

Which Normal-mode command replaces the inner word under the cursor by deleting it and entering Insert mode?

Yanking and Putting Text

Vim calls copying yanking and pasting putting:

  • yw: Yank through a word motion.
  • yy: Yank the current line.
  • p: Put after the cursor for characterwise text or below the current line for linewise text.
  • P: Put before the cursor or above the current line.

Deletes and changes also store text in registers, so a later p may put the most recently deleted text rather than an earlier yank. Named registers let you preserve specific text, but begin by watching what the latest operation stored.

After yy yanks the current line, which command puts that line below the current line?

Undoing, Redoing, and Repeating

In Normal mode:

  • u: Undo the most recent change.
  • Ctrl+R: Redo an undone change.
  • .: Repeat the most recent change at the current location when applicable.
  • J: Join the current line with the next line.

Undo history applies to buffer changes, not merely cursor motions. Save checkpoints and review edits rather than depending on an unlimited or permanent undo history.

Which Normal-mode command redoes a change that was just undone?

To practice operators, motions, and recovery on disposable text, try this hands-on lab:

  1. Edit Text Files in Linux with Vim and Nano - Practice creating files, editing text, saving files, and navigating with both vi/vim and nano. This lab will help you apply concepts like deleting, changing, yanking, and putting text in real scenarios.

Lesson complete

You finished Vim Editing

You can now compose Vim edits and recover from mistakes in Normal mode.

  • Combine operators with motions, text objects, and counts.

  • Delete characters or complete lines at a chosen scope.

  • Change text and enter Insert mode for replacement.

  • Yank and put characterwise or linewise text.

  • Undo, redo, or repeat changes deliberately.

Keep your learning progress

Create a free account to save this lesson and continue learning on any device.

Create a free account
Next Lesson
Back to Advanced Text-Fu