How do I center the screen on my cursor without leaving insert mode?
Answer
<C-o>zz
Explanation
When you are typing in insert mode and the cursor drifts near the top or bottom of the screen, you normally have to press <Esc>, then zz, then i or a to continue editing. The <C-o> key in insert mode lets you skip that round trip entirely by executing a single normal mode command and returning to insert mode automatically.
How it works
<C-o>— while in insert mode, temporarily switch to normal mode for one commandzz— center the current line vertically in the window
After zz executes, Vim drops you right back into insert mode at the exact same cursor position. Your typing flow is never interrupted.
Example
You are editing a long file and your cursor has scrolled to the very bottom of the visible screen:
(line 1 visible at top)
...
(line 40 visible at bottom) █ cursor here, barely visible
Press <C-o>zz while still in insert mode:
...
(line 20 now at top)
(line 40 now centered) █ cursor here, centered on screen
(line 60 now at bottom)
...
Tips
- Use
<C-o>ztto scroll the cursor line to the top of the screen from insert mode - Use
<C-o>zbto scroll the cursor line to the bottom of the screen <C-o>works with any single normal mode command — for example,<C-o>dddeletes the current line without leaving insert mode