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

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 / k move by actual lines in the buffer (one newline character to the next)
  • gj / gk move by screen rows as they appear in the terminal
  • g0 moves to the beginning of the current display line
  • g$ moves to the end of the current display line
  • g^ 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/k to gj/gk for prose editing:
    nnoremap j gj
    nnoremap k gk
    
  • Combine with counts: 3gj moves down 3 display lines
  • Essential when writing Markdown, LaTeX, or any long-form text with wrap enabled

Next

How do I always access my last yanked text regardless of deletes?