Vim Line Navigation — 0, ^, $, and Line Jumps
Navigate within and between lines in Vim using 0, ^, $, gg, G, and line number jumps. Essential commands for fast line-level cursor positioning.
Navigation
Detailed Explanation
Moving Within a Line
Vim provides several ways to jump to specific positions on the current line:
| Key | Position |
|---|---|
0 |
First column (absolute beginning) |
^ |
First non-blank character |
$ |
End of the line |
g_ |
Last non-blank character |
Line Jumps
| Command | Action |
|---|---|
gg |
Go to the first line of the file |
G |
Go to the last line of the file |
{n}G |
Go to line n (e.g., 42G goes to line 42) |
:{n} |
Same as above, using command-line mode |
The Difference Between 0 and ^
0 always goes to column 1, regardless of indentation. ^ goes to the first non-whitespace character. In code with indentation, ^ is usually what you want because it skips leading whitespace.
Combining with Operators
Line navigation keys compose beautifully with operators:
d$— Delete from cursor to end of linec^— Change from cursor to first non-blanky0— Yank from cursor to beginning of linedG— Delete from current line to end of fileygg— Yank from current line to beginning of file
These operator+motion combinations are what make Vim so powerful for editing.
Use Case
You need to quickly position your cursor at the beginning or end of lines, or jump to specific line numbers when debugging or editing code.