How do I move by display lines when long lines wrap?
Answer
gj
Explanation
The gj command moves the cursor down by one display line rather than one physical line. When lines are long and wrap across multiple screen lines, j jumps a whole paragraph, but gj moves just one visual line.
How it works
gjmoves down one screen line within a wrapped linegkmoves up one screen line within a wrapped line- These ignore the actual line numbers and follow the visual display
Example
A very long line that wraps across 3 screen lines:
This is a very long line that wraps around the screen multiple times because it contains
a lot of text and the window is not wide enough to show it all on one line.
With the cursor at the start, j would jump to the next actual line, while gj moves to the next screen row within the same line.
Tips
g0moves to the start of the display lineg$moves to the end of the display lineg^moves to the first non-blank of the display line- Map
jtogjandktogkif you work with wrapped text often