How do I scroll the buffer up or down while staying in insert mode?
Answer
<C-x><C-e> and <C-x><C-y>
Explanation
While in insert mode, <C-x><C-e> scrolls the window up one line and <C-x><C-y> scrolls it down one line — all without leaving insert mode. This lets you peek at code above or below your current position mid-edit, which is especially useful in long functions when you need to reference context that has scrolled off screen.
How it works
<C-x>in insert mode enters a special sub-mode for completions and window operations<C-e>within that sub-mode scrolls the view up (same direction as normal-mode<C-e>)<C-y>within that sub-mode scrolls the view down (same direction as normal-mode<C-y>- The cursor stays at its current position in the buffer; only the viewport moves
Note: <C-e> alone in insert mode copies the character from below the cursor — a different command entirely. The <C-x> prefix is what activates the scroll behavior.
Example
You're inserting a function call on line 80 and need to check the signature declared at line 50:
" You are in insert mode, mid-line
" Press <C-x><C-e> several times to scroll up and read line 50
" Press <C-x><C-y> to scroll back down to your edit point
" Continue typing — insert mode was never exited
Tips
- Hold
<C-x>then tap<C-e>or<C-y>repeatedly to scroll multiple lines - Pair with
'scrolloff'set to a small value so the context display is predictable - In Neovim, these commands work identically; see
:help i_CTRL-X_CTRL-E