vimtricks.wiki Concise Vim tricks, one at a time.

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 as 0
  • 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 0 to move to the absolute beginning of the line (column 1), including any whitespace
  • Use $ to move to the end of the line
  • The I command 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 than 0 because it respects indentation

Next

How do I edit multiple lines at once using multiple cursors in Vim?