How do I jump to the next or previous fold in Vim without moving line by line?
Answer
zj / zk
Explanation
zj and zk move the cursor to the start of the next fold or the end of the previous fold, treating each fold as a single unit to jump over. Unlike j/k which step line by line through open fold content, these commands skip cleanly from fold header to fold header, making them indispensable for navigating a large, heavily-folded file.
How it works
zj— moves down to the first line of the next fold (whether that fold is open or closed)zk— moves up to the last line of the previous fold- Both work regardless of the current fold method (
indent,syntax,marker,manual) - Accept a count prefix:
3zjjumps three folds forward in one motion
Example
A file with three syntax-folded classes:
▸ class AuthManager: (lines 1–30) ← cursor on line 5
▸ class RequestHandler: (lines 31–80)
▸ class ResponseFormatter: (lines 81–120)
Pressing zj moves the cursor to line 31 (the start of RequestHandler). Pressing zj again lands on line 81. Pressing zk goes back to line 31.
If folds are open, zj skips all the visible content and lands on the first line of the next fold definition.
Tips
- Use
[zto jump to the start of the fold containing the cursor, and]zto jump to its end — useful for knowing the full extent of the current fold - Combine with a count and a mark:
mz3zjsaves position, then jumps three folds ahead —'zreturns you - In a diff buffer,
zj/zknavigate between diff change blocks iffoldmethod=diffis active