0.x — Chapter 0 summary and quiz
0.x — Chapter 0 Summary and Quiz#
Let’s review what we’ve learned in Chapter 0 and test your understanding with a quiz.
Chapter Summary#
Lesson 0.1: Introduction to Vim#
- Vim is a modal text editor that separates navigation from text entry
- The Vim language combines operators, motions, and text objects (e.g.,
d2wdeletes 2 words) - Vim’s philosophy emphasizes:
- Composition: Small commands combine into powerful operations
- Repeatability: The
.command and macros enable efficient repetitive edits - Keyboard-centric: Hands stay on the home row
Lesson 0.2: Installing and Launching Vim#
- Check if Vim is installed:
vim --version - Install via package managers:
- macOS:
brew install vim - Linux:
apt install vim,dnf install vim, orpacman -S vim - Windows:
winget install vim.vim
- macOS:
- Neovim is a modern fork that’s 99% compatible with Vim
- Launch Vim:
vimorvim filename - Useful options:
vim +10 file(open at line 10),vim -O file1 file2(vertical splits)
Lesson 0.3: Survival Guide#
The Three Essential Modes:
| Mode | Purpose | Enter | Exit |
|---|---|---|---|
| Normal | Navigate, manipulate | Esc | Enter another mode |
| Insert | Type text | i, a, o | Esc |
| Command-line | Ex commands | : | Esc or Enter |
Save and Exit Commands:
| Command | Action |
|---|---|
:w | Write (save) |
:q | Quit |
:wq | Write and quit |
:q! | Quit without saving |
ZZ | Save and quit (shortcut) |
Basic Navigation:
| Key | Movement |
|---|---|
h | Left |
j | Down |
k | Up |
l | Right |
Basic Editing:
| Command | Action |
|---|---|
x | Delete character |
dd | Delete line |
u | Undo |
Ctrl-r | Redo |
Key Terms#
- Modal Editing: A paradigm where different modes handle different tasks (navigation vs. text entry)
- Normal Mode: The default mode for navigating and executing commands
- Insert Mode: The mode for entering text
- Command-line Mode: The mode for executing Ex commands (
:w,:q, etc.) - Buffer: An in-memory representation of a file
- Operator: A command that performs an action (delete, change, yank)
- Motion: A command that moves the cursor
Quiz Time#
Test your understanding of Chapter 0 concepts.
Question #1
What is the key difference between Vim and traditional text editors?
Show Solution
Vim is a modal editor. Unlike traditional editors where pressing a key always types that character, Vim has different modes for different purposes:
- Normal mode: Keys trigger commands (navigation, deletion, etc.)
- Insert mode: Keys type characters
This separation allows simple keystrokes to perform powerful operations without modifier keys.
Question #2
You’ve opened Vim and started typing, but instead of text appearing, the screen is doing strange things. What happened and how do you fix it?
Show Solution
You’re in Normal mode, where keystrokes are interpreted as commands, not text.
To fix:
- Press
Escto ensure you’re in Normal mode - Press
urepeatedly to undo any unintended changes - Press
ito enter Insert mode - Now you can type text normally
Question #3
How do you exit Vim without saving your changes? How do you exit while saving?
Show Solution
Exit without saving:
:q!(quit and discard changes)ZQ(Normal mode shortcut)
Exit with saving:
:wq(write and quit):x(write if modified, then quit)ZZ(Normal mode shortcut)
Question #4
What do the keys h, j, k, and l do in Normal mode? Why are these keys used instead of arrow keys?
Show Solution
In Normal mode:
h- Move leftj- Move downk- Move upl- Move right
These keys are used because:
- They keep your fingers on the home row of the keyboard
- Historical reason: The original vi was created on a keyboard where these keys had arrow symbols
- Efficiency: No need to move your hand to the arrow keys
Tip: Remember j points down (like a fishhook).
Question #5
You made several edits to a file and realize they were all wrong. What command undoes changes? What if you undo too much?
Show Solution
Undo: Press u in Normal mode. Each press undoes one change. You can press multiple times to undo multiple changes.
Redo (undo the undo): Press Ctrl-r in Normal mode. This “redoes” changes you’ve undone.
Alternative: If you haven’t saved, you can also use :q! to quit without saving and reopen the file to start fresh.
Question #6
Describe three different ways to enter Insert mode from Normal mode, and explain when you might use each.
Show Solution
-
i(insert): Enter Insert mode before the cursor- Use when: You want to insert text at the current cursor position
-
a(append): Enter Insert mode after the cursor- Use when: You want to add text immediately after the current character
-
o(open): Open a new line below and enter Insert mode- Use when: You want to start typing on a new line
Other options include:
I: Insert at the beginning of the lineA: Append at the end of the lineO: Open a new line above
Question #7
What happens if you try to quit Vim with :q when you have unsaved changes? What are your options?
Show Solution
Vim will display an error:
E37: No write since last change (add ! to override)
Your options are:
:wthen:q- Save the changes, then quit:wq- Save and quit in one command:q!- Quit without saving, discarding all changes
The ! after :q forces Vim to quit despite unsaved changes.
Question #8
What is the command to delete the entire current line in Normal mode? What about deleting just the character under the cursor?
Show Solution
dd- Delete the entire current linex- Delete the character under the cursor
Both commands can be undone with u.
Note: dd is actually the delete operator d applied twice, which Vim interprets as “delete the current line.”
What’s Next?#
In Chapter 1, we’ll dive deeper into Vim’s modes, understanding:
- The nuances of Normal mode
- Different ways to enter Insert mode
- Visual mode for selection
- Command-line mode for powerful operations
You now have the survival skills to edit files in Vim without getting stuck. The next step is building efficiency and fluency with Vim’s command language.