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

How do I inspect a Vim register's full details including its type (charwise, linewise, or blockwise) in Vimscript?

Answer

getreginfo('a')

Explanation

getreginfo('{reg}') (Vim 8.1+ / Neovim) returns a dictionary describing a register's complete state: its content as a list of lines, its type (charwise, linewise, or blockwise), and metadata like isunnamed (whether it is also the unnamed register). This is more informative than getreg() and getregtype() separately, and is especially useful in scripts and plugins that need to save and fully restore register state.

How it works

The returned dictionary contains:

  • regcontents — a list of strings (one per line in the register)
  • regtype'v' (charwise), 'V' (linewise), or '\x16' + width (blockwise)
  • isunnamedv:true if this register is also the unnamed "" register
  • points_to — for * or + registers, which register they alias

Example

" Yank a word, then inspect the register
normal! yiw
echo getreginfo('"')
" → {'regcontents': ['hello'], 'regtype': 'v', 'isunnamed': v:true}
" Save and restore a register around an operation
let saved = getreginfo('a')
call setreg('a', saved)

Tips

  • Pass the result directly to setreg() to do a lossless register restore: call setreg('a', getreginfo('a'))setreg() accepts a dictionary from getreginfo() and restores type correctly
  • Compare with getregtype('a') (returns just the type string) and getreg('a', 1, 1) (returns content as list) — getreginfo() consolidates all this in one call
  • Essential for writing operators or macros that need to temporarily use a register without corrupting the user's register state

Next

How do I use Neovim's built-in lazy iterator API to chain filter and map operations over a list?