vimtricks.wiki Concise Vim tricks, one at a time.

How do I convert a register's type between characterwise and linewise?

Answer

:call setreg('a', @a, 'l')

Explanation

Registers in Vim have a type — characterwise, linewise, or blockwise — that affects how their contents are pasted. Using setreg(), you can change a register's type without modifying its content, controlling whether paste inserts inline or on new lines.

How it works

  • setreg({reg}, {value}, {type}) — set register with explicit type
  • Type flags: 'c' = characterwise, 'l' = linewise, 'b' = blockwise
  • getregtype({reg}) — returns the current type: v, V, or \x16{width}

Example

" Yank a word (characterwise by default)
yiw
" Convert unnamed register to linewise
:call setreg('"', @", 'l')
" Now p pastes on a new line instead of inline
Before conversion: p inserts 'word' inline
After conversion:  p inserts 'word' on a new line below

Tips

  • Check register type: :echo getregtype('a') returns v, V, or ^V{n}
  • Blockwise type includes width: setreg('a', text, 'b10') for 10-char wide block
  • Use getreg('a', 1, 1) to get register content as a list of lines
  • This is essential when writing plugins that need consistent paste behavior

Next

How do I return to normal mode from absolutely any mode in Vim?