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):
| Key | Direction |
|---|---|
h | Left |
j | Down |
k | Up |
l | Right |
Line boundaries:
| Command | Position |
|---|---|
0 | Column 0 (absolute start) |
^ | First non-blank character |
$ | End of line |
g_ | Last non-blank character |
Line jumps:
ggβ first lineGβ last line{n}Gor:{n}β go to line n
Counts: 5j moves down 5 lines, 10l moves right 10 characters
Lesson 2.2: Word-Based Movement#
Two types of βwordsβ:
- word (lowercase): separated by punctuation and whitespace
- WORD (uppercase): separated only by whitespace
| Motion | word | WORD |
|---|---|---|
| Forward to start | w | W |
| Forward to end | e | E |
| Backward to start | b | B |
| Backward to end | ge | gE |
With operators:
dwβ delete wordciwβ change inner wordyawβ yank a word (with surrounding space)
Lesson 2.3: Line Navigation#
Find and Till:
| Command | Action |
|---|---|
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:
Hβ High (top of screen)Mβ Middle of screenLβ Low (bottom of screen)
Scrolling:
| Command | Amount |
|---|---|
Ctrl-f / Ctrl-b | Full screen |
Ctrl-d / Ctrl-u | Half screen |
Ctrl-e / Ctrl-y | Single line |
Screen repositioning:
zzβ center cursor on screenztβ cursor at topzbβ cursor at bottom
Paragraph/Section:
{/}β previous/next blank line%β matching bracket
Jump history:
Ctrl-oβ older positionCtrl-iβ newer position
Navigation Command Reference#
| Category | Commands |
|---|---|
| Basic | h, j, k, l |
| Words | w, b, e, W, B, E |
| Line Start/End | 0, ^, $, g_ |
| Find | f, F, t, T, ;, , |
| File | gg, G, {n}G |
| Screen | H, M, L |
| Scroll | Ctrl-f, Ctrl-b, Ctrl-d, Ctrl-u |
| Reposition | zz, zt, zb |
| Jumps | Ctrl-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;
0moves to the first space^moves to theiinint
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"
wfrom start stops at:user,.,name,=,",value,"Wfrom 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 mode42ggβ 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 parenthesist(β 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 screenMβ 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:
f,β jump to first comma;β jump to next comma;β jump to next comma,β (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 screenCtrl-fβ down full screenCtrl-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 screenzbβ 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 operator3β countf,β 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:
- How operators and motions combine
- The full power of the dot command
- Advanced counts and repetition
This is where Vim starts to feel like a language you speak rather than commands you memorize!