How do I insert a blank line above or below the current line without entering insert mode?
Answer
:put =''
Explanation
Using :put ='' with an empty expression lets you insert blank lines in normal mode without ever entering insert mode. This is especially useful in mappings, since it avoids the state-change side effects of o or O, and it preserves the current register contents.
How it works
:putpastes the result of a register or expression after the current line (likep):put!pastes before the current line (likeP)=''uses the expression register and evaluates to an empty string, which Vim inserts as a blank line- Unlike
oorO, the cursor ends up on the new blank line but normal mode is preserved
Example
Before (cursor on line 2):
line 1
line 2 ← cursor here
line 3
:put ='' → inserts blank line after:
line 1
line 2
← new blank line
line 3
:put! ='' → inserts blank line before:
line 1
← new blank line
line 2
line 3
Tips
- Map these to convenient keys:
nnoremap <leader>o :put =''<CR>andnnoremap <leader>O :put! =''<CR> - Useful in scripts and autocommands where you need to add spacing without changing mode
- The expression register
=is powerful here — you can insert any computed value::put =repeat('-', 80)inserts a line of 80 dashes - Combine with a range:
:5put =''inserts a blank line after line 5 regardless of cursor position