How do I move to the end of the visible screen line when text is soft-wrapped?
Answer
g$
Explanation
The g$ command moves the cursor to the last character of the current screen line, not the end of the logical line. This distinction matters when 'wrap' is enabled and a long line spans multiple rows on screen.
Vim distinguishes between logical lines (lines separated by newlines) and screen lines (rows rendered on the display). The standard $ motion always jumps to the end of the logical line, skipping past any wrapped portions. g$ stops at the edge of what is currently visible in the row the cursor is on.
How it works
g— prefix that switches many motions to operate on screen lines instead of logical lines$— move to end of line
The full family of screen-line motions:
g0 " first character of screen line
g^ " first non-blank character of screen line
gj " move down one screen line
gk " move up one screen line
g$ " last character of screen line
Example
With 'wrap' on and a long logical line that wraps:
This is a very long sentence that wraps onto
a second screen row inside the editor window.
With the cursor at the start of the first screen row:
- Pressing
$→ jumps to the period at the very end of the second screen row - Pressing
g$→ stops at theoat the end of the first screen row (...wraps onto)
Tips
- Pair
g0andg$when editing wrapped prose or Markdown files where lines intentionally exceedtextwidth - Combine with operators:
dg$deletes from the cursor to the end of the current screen line only - If
'wrap'is off,g$behaves identically to$ - Use
gj/gkto navigate wrapped lines andg$to reach their ends without jumping to the logical end