How do I move to the first non-blank character of a line?
Answer
^
Explanation
The ^ command moves the cursor to the first non-blank character of the current line. This is especially useful in code, where lines are often indented with tabs or spaces and you want to jump straight to where the actual content begins.
How it works
^skips over any leading whitespace (spaces and tabs) and lands on the first non-blank character- If the line has no leading whitespace,
^moves to column 1, the same as0 - If the line is entirely blank, the cursor stays at the beginning
Example
Given the text with the cursor at the end of the line:
return result;
Pressing ^ moves the cursor to the r of return, skipping over the 8 leading spaces.
Tips
- Use
0to move to the absolute beginning of the line (column 1), including any whitespace - Use
$to move to the end of the line - The
Icommand is equivalent to^i— it moves to the first non-blank character and enters insert mode - Combine with operators:
d^deletes from the cursor back to the first non-blank character,c^changes from the cursor to the first non-blank character - Use
_(underscore) as a synonym for^in operator-pending mode —d_deletes the current line content without the newline - When writing mappings,
^is often more useful than0because it respects indentation