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

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 line
  • g0 — move to the start of the display line
  • g$ — move to the end of the display line
  • g^ — 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/k to gj/gk for prose editing: nnoremap j gj and nnoremap k gk
  • Use a smart mapping: nnoremap <expr> j v:count ? 'j' : 'gj' — uses gj without count, j with count
  • g0 and g$ are the display-line equivalents of 0 and $
  • Essential when editing Markdown, plain text, or any file with long wrapped lines

Next

How do I return to normal mode from absolutely any mode in Vim?