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:

Essential commands:

CategoryCommands
Movementh, j, k, l, w, b, 0, $
Deletionx, dd, d{motion}
Changec{motion}, cc
Yank/Pasteyy, y{motion}, p, P
Undo/Redou, Ctrl-r

Lesson 1.2: Insert Mode β€” Entering Text#

Insert mode is where you type text.

Ways to enter Insert mode:

CommandPosition
i / aBefore / after cursor
I / AStart / end of line
o / ONew line below / above
s / SSubstitute character / line
c{motion}Change (delete + insert)

Key techniques:

Lesson 1.3: Visual Mode β€” Selecting Text#

Visual mode lets you select text before operating on it.

Three types:

ModeCommandSelects
CharactervCharacters
LineVEntire lines
BlockCtrl-vRectangular regions

Key techniques:

Lesson 1.4: Command-Line Mode β€” Ex Commands#

Command-line mode provides Ex commands for file operations and more.

Entry points:

Essential commands:

CategoryCommands
File:w, :q, :e, :wq
Search/pattern, n, N, :noh
Substitute:%s/old/new/g
Global:g/pattern/command
Settings:set option

Mode Comparison#

ModeEnterPurposeExit
NormalEscNavigate, commandβ€”
Inserti, a, o, etc.Type textEsc
Visualv, V, Ctrl-vSelect textEsc or operator
Command-line:, /, ?Ex commandsEnter or Esc

Key Takeaways#

  1. Normal mode is home base β€” return here when not actively typing
  2. Each mode has a purpose β€” use the right mode for the task
  3. Commands compose β€” operators + motions = powerful combinations
  4. Visual mode previews β€” see selection before acting
  5. 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 character
  • a (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 characters
  • V β€” Line-wise Visual mode: selects entire lines
  • Ctrl-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 lines
  • s β€” 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):

  1. :5 to go to line 5
  2. Ctrl-v to enter Block mode
  3. 5j to select down to line 10
  4. I (capital I) to insert at start
  5. Type //
  6. 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 line
  • D β€” Deletes from the cursor to the end of the line (equivalent to d$)

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
  1. cw then type β€œworld” β€” Changes from cursor to end of word
  2. ciw then 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:

Efficient navigation is the foundation of editing speed in Vim!