1.x β Chapter 1 summary and quiz
1.x β Chapter 1 Summary and Quiz#
Letβs review the four main Vim modes and test your understanding.
Chapter Summary#
Lesson 1.1: Normal Mode β The Command Center#
Normal mode is Vimβs default mode where keystrokes execute commands.
Key concepts:
- You spend most of your time here
- Commands follow the grammar:
[count][operator][motion] - The
.command repeats your last change
Essential commands:
| Category | Commands |
|---|---|
| Movement | h, j, k, l, w, b, 0, $ |
| Deletion | x, dd, d{motion} |
| Change | c{motion}, cc |
| Yank/Paste | yy, y{motion}, p, P |
| Undo/Redo | u, Ctrl-r |
Lesson 1.2: Insert Mode β Entering Text#
Insert mode is where you type text.
Ways to enter Insert mode:
| Command | Position |
|---|---|
i / a | Before / after cursor |
I / A | Start / end of line |
o / O | New line below / above |
s / S | Substitute character / line |
c{motion} | Change (delete + insert) |
Key techniques:
Ctrl-oexecutes one Normal command while staying in Insert mode- Keep insertions atomic for better undo and dot command usage
- Exit with
EscorCtrl-[
Lesson 1.3: Visual Mode β Selecting Text#
Visual mode lets you select text before operating on it.
Three types:
| Mode | Command | Selects |
|---|---|---|
| Character | v | Characters |
| Line | V | Entire lines |
| Block | Ctrl-v | Rectangular regions |
Key techniques:
gvreselects last selectionotoggles cursor between selection ends- Text objects work:
viw,va", etc. - Block mode enables column editing
Lesson 1.4: Command-Line Mode β Ex Commands#
Command-line mode provides Ex commands for file operations and more.
Entry points:
:for Ex commands/for forward search?for backward search
Essential commands:
| Category | Commands |
|---|---|
| File | :w, :q, :e, :wq |
| Search | /pattern, n, N, :noh |
| Substitute | :%s/old/new/g |
| Global | :g/pattern/command |
| Settings | :set option |
Mode Comparison#
| Mode | Enter | Purpose | Exit |
|---|---|---|---|
| Normal | Esc | Navigate, command | β |
| Insert | i, a, o, etc. | Type text | Esc |
| Visual | v, V, Ctrl-v | Select text | Esc or operator |
| Command-line | :, /, ? | Ex commands | Enter or Esc |
Key Takeaways#
- Normal mode is home base β return here when not actively typing
- Each mode has a purpose β use the right mode for the task
- Commands compose β operators + motions = powerful combinations
- Visual mode previews β see selection before acting
- Ex commands extend β file ops, substitution, settings
Quiz Time#
Test your understanding of Vim modes.
Question #1
What is the difference between i and a when entering Insert mode?
Show Solution
i(insert) enters Insert mode with the cursor before the current charactera(append) enters Insert mode with the cursor after the current character
Use i when you want to insert text at the cursor position. Use a when you want to add text after the current character.
Question #2
You want to delete three words starting from your cursor. Whatβs the most efficient command?
Show Solution
d3w β This uses the operator (d for delete), a count (3), and a motion (w for word).
Alternative: 3dw also works (count before operator).
Question #3
Whatβs the difference between v, V, and Ctrl-v?
Show Solution
vβ Character-wise Visual mode: selects individual charactersVβ Line-wise Visual mode: selects entire linesCtrl-vβ Block-wise Visual mode: selects a rectangular block
Use v for selecting parts of lines, V for operating on whole lines, and Ctrl-v for column editing.
Question #4
How do you replace all occurrences of βfooβ with βbarβ in the entire file?
Show Solution
:%s/foo/bar/g
%β operate on all linessβ substitute command/foo/bar/β replace βfooβ with βbarβgβ global flag (all occurrences on each line)
Add c flag (:%s/foo/bar/gc) to confirm each replacement.
Question #5
Youβre in Insert mode and need to save the file without leaving Insert mode. How?
Show Solution
Press Ctrl-o to execute one Normal mode command, then type :w and press Enter.
Ctrl-o temporarily switches to Normal mode for a single command, then returns to Insert mode.
Question #6
What does gv do and when would you use it?
Show Solution
gv reselects the last visual selection.
Use it when:
- You need to perform another operation on the same selection
- You accidentally exited Visual mode before completing your action
- You want to adjust a selection you just made
Question #7
How do you add // to the beginning of lines 5-10 to comment them out?
Show Solution
Method 1 (Block Visual):
:5to go to line 5Ctrl-vto enter Block mode5jto select down to line 10I(capital I) to insert at start- Type
// - Press
Esc
Method 2 (Substitute):
:5,10s/^/\/\/ /
This substitutes the start of each line (^) with // .
Question #8
Whatβs the difference between dd and D?
Show Solution
ddβ Deletes the entire current lineDβ Deletes from the cursor to the end of the line (equivalent tod$)
Use dd to remove a whole line. Use D to delete only the remainder of a line.
Question #9
You have a word βhelloβ and want to change it to βworldβ. Your cursor is on the βhβ. What are two ways to do this?
Show Solution
cwthen type βworldβ β Changes from cursor to end of wordciwthen type βworldβ β Changes the entire inner word regardless of cursor position
ciw is often preferred because it works no matter where in the word your cursor is positioned.
Question #10
How do you delete all blank lines in a file?
Show Solution
:g/^$/d
:gβ Global command/^$/β Pattern matching empty lines (start of line immediately followed by end of line)dβ Delete command
This executes the delete command on every line matching the pattern.
Whatβs Next?#
In Chapter 2, weβll dive deep into navigation β learning all the ways to move around efficiently in Vim. Youβll master:
- Character and line movement
- Word-based navigation
- Line-level movements
- Screen and file navigation
Efficient navigation is the foundation of editing speed in Vim!