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

How do I scroll the screen to position the cursor line at the center, top, or bottom?

Answer

zz / zt / zb

Explanation

Vim's z scroll commands reposition the screen relative to the cursor without moving the cursor itself. This is essential for getting context around your current position — centering a function definition, or pushing it to the top to see more of its body.

How it works

  • zz — scroll to center the cursor line on screen
  • zt — scroll to place the cursor line at the top
  • zb — scroll to place the cursor line at the bottom
  • The cursor stays on the same line — only the viewport moves

Example

Before zz (cursor on line 50, shown near bottom):
...
line 48
line 49
line 50  ← cursor (near bottom of screen)

After zz:
line 40
...
line 50  ← cursor (centered on screen)
...
line 60

Tips

  • zt is perfect after jumping to a function definition — shows the full function body below
  • z. centers like zz but also moves cursor to the first non-blank character
  • z<CR> is like zt but also moves cursor to first non-blank
  • Combine with scrolloff: :set scrolloff=5 keeps 5 lines of context above/below cursor always

Next

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