navigation
gg / G
gg jumps to the first line of the file; G jumps to the last line. Prefix G with a number to jump to that absolute line — the fastest way to reach a specific line from a stack trace.
gg G (normal mode) Variations
| Keystroke | Effect |
|---|---|
| 42G | Jump to line 42 |
| :42<Enter> | Alternative — jump to line 42 via command mode |
| ggVG | Select the entire file (gg then visual-line to end) |
| gg=G | Reindent the whole file |
Examples
gg Go to line 1
G Go to last line of file
100G Jump to line 100
Gotcha
G without a count goes to the LAST line, not line 0. If you accidentally type Gg or gG, nothing happens — G must come after the count.
Related
Ctrl-D / Ctrl-U
Ctrl-D scrolls the view (and cursor) half a screen down; Ctrl-U scrolls half a screen up. Faster than jkjk when skimming a long file, and the cursor stays in a predictable place on screen.
%
In normal mode, % jumps between matching pairs of (), [], {}, and (with matchit) HTML/XML tags. Indispensable for navigating nested code and confirming that a stray brace really does close where you think it does.
0 / $
0 jumps to the very first column of the line; $ jumps to the last character. Use ^ (bonus) if you want the first non-blank character instead of column zero.
h j k l
The four fundamental cursor keys in Vim: h moves left, j down, k up, l right. Reach for them any time you would instinctively hit an arrow key — keeping your hands on the home row is the whole point.
w / b / e
Word motions: w jumps to the start of the next word, b to the start of the previous word, e to the end of the current/next word. These are the fastest way to hop across a line without leaving the home row.