2.x β€” Chapter 2 summary and quiz

2.x β€” Chapter 2 Summary and Quiz#

Let’s consolidate what we’ve learned about Vim navigation and test your understanding.

Chapter Summary#

Lesson 2.1: Character and Line Movement#

Basic movement keys (hjkl):

KeyDirection
hLeft
jDown
kUp
lRight

Line boundaries:

CommandPosition
0Column 0 (absolute start)
^First non-blank character
$End of line
g_Last non-blank character

Line jumps:

Counts: 5j moves down 5 lines, 10l moves right 10 characters

Lesson 2.2: Word-Based Movement#

Two types of β€œwords”:

MotionwordWORD
Forward to startwW
Forward to endeE
Backward to startbB
Backward to endgegE

With operators:

Lesson 2.3: Line Navigation#

Find and Till:

CommandAction
f{char}Find forward (cursor ON char)
F{char}Find backward (cursor ON char)
t{char}Till forward (cursor BEFORE char)
T{char}Till backward (cursor AFTER char)
;Repeat last find
,Repeat last find (reverse)

Key insight: df, deletes through comma; dt, deletes up to comma.

Lesson 2.4: Screen and File Navigation#

Screen position:

Scrolling:

CommandAmount
Ctrl-f / Ctrl-bFull screen
Ctrl-d / Ctrl-uHalf screen
Ctrl-e / Ctrl-ySingle line

Screen repositioning:

Paragraph/Section:

Jump history:

CategoryCommands
Basich, j, k, l
Wordsw, b, e, W, B, E
Line Start/End0, ^, $, g_
Findf, F, t, T, ;, ,
Filegg, G, {n}G
ScreenH, M, L
ScrollCtrl-f, Ctrl-b, Ctrl-d, Ctrl-u
Repositionzz, zt, zb
JumpsCtrl-o, Ctrl-i, %, {, }

Quiz Time#

Test your navigation knowledge!


Question #1

What’s the difference between 0 and ^?

Show Solution
  • 0 β€” moves to column 0, the absolute start of the line (even if it’s whitespace)
  • ^ β€” moves to the first non-blank character on the line

Example: On line int x;

  • 0 moves to the first space
  • ^ moves to the i in int

Question #2

You need to delete from your cursor to the end of the line. What command do you use?

Show Solution

D or d$

Both delete from the cursor position to the end of the line. D is a shorthand for d$.


Question #3

What’s the difference between w and W?

Show Solution
  • w β€” moves to start of next word (letters/digits/underscores OR sequences of other characters)
  • W β€” moves to start of next WORD (any non-blank sequence)

Example: On user.name = "value"

  • w from start stops at: user, ., name, =, ", value, "
  • W from start stops at: user.name, =, "value"

Use w for fine-grained movement, W to skip over punctuation.


Question #4

How do you jump to line 42?

Show Solution

Multiple ways:

  • 42G β€” Normal mode
  • 42gg β€” Normal mode
  • :42 β€” Command-line mode

All three take you to line 42.


Question #5

What’s the difference between f( and t(?

Show Solution
  • f( β€” Find the (, cursor lands ON the parenthesis
  • t( β€” Till the (, cursor lands BEFORE the parenthesis (on the character before it)

This matters with operators:

  • df( deletes through the ( (including it)
  • dt( deletes up to the ( (not including it)

Question #6

You’re looking at the bottom of your screen and want to jump there quickly. What command?

Show Solution

L β€” moves cursor to the Low (bottom) of the visible screen.

Related commands:

  • H β€” High (top) of screen
  • M β€” Middle of screen

Question #7

What does ; do and when would you use it?

Show Solution

; repeats the last f, F, t, or T command in the same direction.

Use case: Finding all commas in a line:

  1. f, β€” jump to first comma
  2. ; β€” jump to next comma
  3. ; β€” jump to next comma
  4. , β€” (comma key) go back one if you went too far

Question #8

How do you scroll down half a screen?

Show Solution

Ctrl-d β€” scrolls down half a screen.

Related scrolling:

  • Ctrl-u β€” up half screen
  • Ctrl-f β€” down full screen
  • Ctrl-b β€” up full screen

Question #9

You just made a jump to the end of the file with G. How do you get back to where you were?

Show Solution

Ctrl-o β€” jump to older position in the jump list.

Vim maintains a jump list of significant movements. Ctrl-o goes back through this list.

Alternatively, `` (two backticks) jumps to the exact position before the last jump.


Question #10

You want to center the current line on your screen. What command?

Show Solution

zz β€” repositions the screen so the current line is centered.

Related:

  • zt β€” current line at top of screen
  • zb β€” current line at bottom of screen

Question #11

You’re on an opening brace { and want to jump to its matching closing brace. What command?

Show Solution

% β€” jumps to the matching bracket.

Works with:

  • () parentheses
  • [] square brackets
  • {} curly braces

Pressing % again returns to the original bracket.


Question #12

How do you delete from the cursor to the third comma on a line?

Show Solution

d3f, or 3df,

Both delete from cursor through the third comma:

  • d β€” delete operator
  • 3 β€” count
  • f, β€” find comma motion

If you wanted to delete up to (not including) the third comma: d3t,


What’s Next?#

In Chapter 3, we’ll learn the heart of Vim’s power: Operators and Motions. You’ll understand:

This is where Vim starts to feel like a language you speak rather than commands you memorize!