Is there a way to center the line I'm editing in the screen? This is sometimes needed to see a bit more context above and below the current line.

4 Answers 4


The z. and zz commands will recenter the line the cursor is on. z. also moves the cursor to the first non-whitespace character in the line, while zz keeps the cursor where it is.

There are similar commands for the top (z<CR>/zt) and bottom (z-/zb) of the window.

The versions of these commands that end in a letter keep the cursor column, while the ones ending in punctuation move the cursor.


Type zz to center the current line in the screen:

enter image description here

  • Perfect! I added this to my BufReadPost autocmd so I resume editing with the cursor line restored and centered on screen: au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | "normal! g'\"zz"
    – John P
    Oct 3, 2017 at 14:41

Yes, in normal mode you can use zz to do so. But as the docs forewarn, be careful with capslock as ZZ will write the buffer to file and quit.

  • For whatever reason this became a huge point of contention on another SO/SE thread... the consensus seemed to be that you should hold shift down indefinitely as needed and remap the caps lock key at the system level to remove the temptation, et voilà, no more caps lock whoopsies. Otherwise it's your own fault. I'm guessing they've never had to deal with preprocessor macros...
    – John P
    Oct 3, 2017 at 14:48

In normal mode, zz will move the line currently under the cursor to the center of the screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.