Skip to content

Instantly share code, notes, and snippets.

@nelstrom
Last active September 3, 2022 19:42
Show Gist options
  • Save nelstrom/7615833 to your computer and use it in GitHub Desktop.
Save nelstrom/7615833 to your computer and use it in GitHub Desktop.

Download the inspect-registers.vim file from this gist. Open the file in Vim, launching with no vimrc:

vim -Nu NONE inspect-registers.vim

Source the file:

:source %

Insert text on line one:

:0put='Word by word, line by line'

Then run :w to save the buffer.

Execute operations and inspect registers

for {OPERATION} in [yw, yy, "ayw, "ayy, dw, dd, "adw, "add]

  1. QQ to clear the registers
  2. gg to place the cursor at the start of line one
  3. {OPERATION}
  4. QW to inspect the registers
  5. :e! to revert any changes to the document

Results

When {OPERATION} is yw:

:RegInspect
--- Registers ---
""   Word
"0   Word
"1
"a
"-

When {OPERATION} is yy:

:RegInspect
--- Registers ---
""   Word by word, line by line^J
"0   Word by word, line by line^J
"1
"a
"-

When {OPERATION} is "ayw:

:RegInspect
--- Registers ---
""   Word
"0
"1
"a   Word
"-

When {OPERATION} is "ayy:

:RegInspect
--- Registers ---
""   Word by word, line by line^J
"0
"1
"a   Word by word, line by line^J
"-

When {OPERATION} is dw:

:RegInspect
--- Registers ---
""   Word
"0
"1
"a
"-   Word

When {OPERATION} is dd:

:RegInspect
--- Registers ---
""   Word by word, line by line^J
"0
"1   Word by word, line by line^J
"a
"-

When {OPERATION} is "adw:

:RegInspect
--- Registers ---
""   Word
"0
"1   Word
"a   Word
"-

When {OPERATION} is "add:

:RegInspect
--- Registers ---
""   Word by word, line by line^J
"0
"1   Word by word, line by line^J
"a   Word by word, line by line^J
"-

Summary

This table summarizes the results:

{OPERATION} "" (default) "0 (yank) "1 (numbered) "a (named) "- (small delete)
yw X X - - -
yy X X - - -
"ayw X - - X -
"ayy X - - X -
dw X - - - X
dd X - X - -
"adw X - X X -
"add X - X X -
command! RegClear :let @a='' | let @-='' | let @0='' | let @1=''
command! RegInspect :reg "a-01
nnoremap QQ :RegClear<CR>
nnoremap QW :RegInspect<CR>
@wizardwerdna
Copy link

Great work, Drew! Doing this exercise helped a great deal in terms of grokking and visualizing what's going on.

@ddrscott
Copy link

I never realized it was possible to Gist a markdown file and have it rendered nicely.
The register info is great, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment