How do I paste the contents of a register as a new line below the cursor regardless of the register type in Vim?
Answer
:put {reg}
Explanation
The :put Ex command always inserts a register's content as a new line below the current line, regardless of whether the register holds characterwise, linewise, or blockwise text. This is unlike p, which respects the register type and pastes inline when the content is characterwise.
How it works
p— pastes characterwise text after the cursor character (inline); linewise text as a new line:put {reg}— always opens a new line below and inserts the register content there, regardless of type:put! {reg}— same, but inserts above the current line (likePfor linewise)- The unnamed register
"is used if no register is specified::put
This means you can yank a word with yiw (characterwise) and then use :put to paste it onto its own line, which p alone cannot do without extra manipulation.
Example
Yank a function name with yiw (the register now holds a characterwise string like handleClick):
With cursor on: handleClick
After yiw: register contains 'handleClick' (characterwise)
Now use :put to paste it as its own line:
Before: function handleClick() {}
After :put:
function handleClick() {}
handleClick
With p, the word would be inserted inline after the cursor character, not as a new line.
Tips
:5put apastes registeraafter line 5 without moving the cursor — useful for collecting text at a fixed location:$putpastes at the end of the file- Combine with
=to paste expressions::put =strftime('%Y-%m-%d')inserts today's date as a new line - Use
:put _(black-hole register) to insert an empty line below the cursor — a quick way to add blank lines without leaving normal mode