How do I move by visible screen lines instead of actual lines?
Answer
gj / gk
Explanation
When a long line wraps across multiple screen rows, the regular j and k motions skip the entire logical line. The gj and gk commands instead move by display lines — the visible rows on screen.
How it works
j/kmove by actual lines in the buffer (one newline character to the next)gj/gkmove by screen rows as they appear in the terminalg0moves to the beginning of the current display lineg$moves to the end of the current display lineg^moves to the first non-blank character of the current display line
Example
Given a line that wraps across 3 screen rows:
This is a very long line that wraps across multiple scr
een rows because it exceeds the terminal width and Vim
has to display it across several visual lines.
Pressing gj moves down one screen row within the same logical line, rather than jumping to the next actual line.
Tips
- Many users remap
j/ktogj/gkfor prose editing:nnoremap j gj nnoremap k gk - Combine with counts:
3gjmoves down 3 display lines - Essential when writing Markdown, LaTeX, or any long-form text with
wrapenabled