How do I move to the start of the current screen line rather than the start of the buffer line when text is soft-wrapped?
Answer
g0
Explanation
When wrap is on, a long buffer line can span multiple screen (display) lines. The ordinary 0 command jumps to column 1 of the buffer line — potentially scrolling the cursor far to the left away from what you're looking at. The g0 command instead moves to the first character of the screen line currently under the cursor, which is what you usually want when editing wrapped text.
How it works
g0— move to the first character of the current screen line (equivalent of0for display lines)g^— move to the first non-blank character of the current screen line (equivalent of^for display lines)- These commands are part of a family of display-line motions:
gj/gk(move by display line),g$(end of display line),g0/g^(start of display line)
Example
With a 120-character line wrapped at column 80:
Line 1: The quick brown fox jumps over the lazy [cursor here, on screen line 2]
dog while the rain falls softly down.
Pressing 0 would jump to T at the very beginning of the buffer line.
Pressing g0 keeps you on screen line 2, moving the cursor to d in dog.
Tips
- Combine
g0with thegj/gkdisplay-line movement family for a fully wrapped-line-aware navigation style - Add
nnoremap 0 g0andnnoremap ^ g^to yourvimrcif you prefer display-line navigation as the default whenwrapis on - When
nowrapis set these commands are identical to their non-gcounterparts, so the mappings are safe to use unconditionally