vimtricks.wiki Concise Vim tricks, one at a time.

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

  • gj moves down one screen line within a wrapped line
  • gk moves 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

  • g0 moves to the start of the display line
  • g$ moves to the end of the display line
  • g^ moves to the first non-blank of the display line
  • Map j to gj and k to gk if you work with wrapped text often

Next

How do you yank a single word into a named register?