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

How do I center the screen on the cursor line?

Answer

zz

Explanation

The zz command scrolls the window so that the current cursor line appears in the middle of the screen. The cursor itself does not move to a different line — only the viewport shifts. This is incredibly useful after jumping to a specific line or search result, when the cursor ends up near the top or bottom edge of the screen.

How it works

  • zz repositions the viewport so the cursor line is vertically centered
  • The cursor stays on the same line and column — only the scroll position changes
  • It does not enter any special mode or modify the buffer

Example

After searching for a pattern with /TODO and landing on a match near the bottom of the screen, pressing zz recenters the view so you can see the surrounding context above and below the match.

Related scroll commands

  • zt scrolls so the cursor line is at the top of the screen
  • zb scrolls so the cursor line is at the bottom of the screen
  • zz scrolls so the cursor line is in the middle of the screen

Tips

  • Do not confuse zz with ZZ — uppercase ZZ saves the file and quits Vim
  • Use <C-d> and <C-u> to scroll by half a page, or <C-f> and <C-b> for a full page
  • Use <C-e> to scroll down by one line or <C-y> to scroll up by one line without moving the cursor
  • Some users add nnoremap n nzz to their vimrc so that every search result is automatically centered
  • Combine with zt when reading code top-down — zt puts the current line at the top, giving you the most visible context below

Next

How do I edit multiple lines at once using multiple cursors in Vim?