Module Review: Advanced Editing

[!NOTE] This module solidifies your mastery of Vim’s advanced editing capabilities. By mastering Visual Mode for targeted selections, Registers for multi-clipboard management, and Macros for automated repetition, you transition from basic text manipulation to true editor efficiency.

Solidify your understanding of these powerful tools to become a more efficient editor.

1. Key Takeaways

  • Visual Modes: Use v for characters, V for lines, and Ctrl-v for rectangular blocks.
  • Block Editing: Ctrl-v allows you to insert (I) or append (A) text on multiple lines simultaneously.
  • Registers: Vim has many clipboards. "" is the default. "0 holds your last yank (copy). "1-"9 hold your last deletes. "a-"z are for you.
  • Macros: Record (q{reg}) a sequence of commands to automate repetitive tasks. Replay with @{reg}.
  • Automation: Use relative motions (w, f, $) in macros to make them robust against varying line lengths.

2. Interactive Flashcards

Test your memory of the commands learned in this module.

Loading...
(Click card or press Space to flip)
1 / 5

3. Workflow Demo & Practice

To truly master advanced editing, you must learn to chain commands together. Let’s look at a common scenario: formatting a list of unquoted, comma-separated variables into a formatted JSON-like structure.

Scenario: Wrapping variables with quotes and adding a colon

Before:

userId,
userEmail,
createdAt,

Goal:

"userId":
"userEmail":
"createdAt":

The Macro Approach (qaq):

  1. Move to the first line, first character: gg0
  2. Start recording into register ‘a’: qa
  3. Insert a quote at the beginning: i"<Esc>
  4. Move to the end of the word (ignoring the comma): e
  5. Append a quote and colon, replacing the comma: a":<Esc>x
  6. Move down to the next line: j
  7. Stop recording: q

Replay: Execute 2@a to replay the macro on the remaining two lines.

Practice Area: Use the editable text area below to plan out your keystrokes for complex edits before trying them in Vim.

4. Cheat Sheet

Visual Mode

Command Action
v Character-wise selection.
V Line-wise selection.
Ctrl-v Block-wise selection.
gv Re-select previous selection.
o Move to other end of selection.
~ Toggle case.
I (Block) Insert on multiple lines.
A (Block) Append to multiple lines.

Registers

Command Action
"" Unnamed register (default).
"0 Yank register (copy history).
"1-"9 Delete history.
"a-"z Named registers.
"+ / "* System clipboard.
"_ Black hole register.
:reg Show registers.
Ctrl-r {reg} Paste in Insert mode.

Macros

Command Action
q{reg} Start recording to register.
q Stop recording.
@{reg} Replay macro.
@@ Replay last macro.
:norm @{reg} Run macro on selected lines.

5. Next Steps

Now that you can manipulate text like a wizard, it’s time to master your environment. Proceed to Workspace Management to learn about Splits, Tabs, and Buffer management.

Vim Glossary