How do I navigate through wrapped lines visually instead of by actual lines?
Answer
gj and gk
Explanation
When wrap is enabled, long lines wrap across multiple screen lines. Normal j and k move by actual lines, which can skip large visual sections. gj and gk move by display (screen) lines, navigating through wrapped text naturally.
How it works
gj— move down one display line (within a wrapped line)gk— move up one display lineg0— move to the start of the display lineg$— move to the end of the display lineg^— move to the first non-blank of the display line
Example
A very long line that wraps across
multiple screen lines in Vim when
the window is narrow
This is one actual line.
j skips the entire thing.
gj moves one visual line at a time.
Tips
- Map
j/ktogj/gkfor prose editing:nnoremap j gjandnnoremap k gk - Use a smart mapping:
nnoremap <expr> j v:count ? 'j' : 'gj'— usesgjwithout count,jwith count g0andg$are the display-line equivalents of0and$- Essential when editing Markdown, plain text, or any file with long wrapped lines