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

How do I recover the last small deletion without disrupting my numbered registers?

Answer

"-

Explanation

Vim silently stores every deletion of less than one line in the special "- register (the "small delete" register). Unlike the numbered registers "1"9 which only track linewise or multi-line deletes, "- captures word deletions, character deletions, and any {operator}{motion} that stays within a single line — giving you a dedicated rescue slot for small edits.

How it works

  • Any deletion shorter than a full line is saved to "- automatically
  • Paste it anywhere with "-p (after cursor) or "-P (before cursor)
  • "- is overwritten by the next small delete — but it does not disturb registers "0"9
  • This means you can yank a large block (yy), make several small deletions, and still paste the original yank with "0p while recovering the most recent small delete with "-p

Example

Suppose your cursor is on important:

This is important for the function.

You accidentally run dw, removing important. Later you yank a different line, then realise you need the word back. Because the deletion was one word (less than a line), "-p restores it exactly:

"-p

Result:

This is important for the function.

Tips

  • Use :registers - to inspect the current contents of "- at any time
  • For linewise deletions, check "1 (most recent) through "9 (oldest)
  • Combine with "0p for the last yank — together "0 and "- cover most accidental-overwrite scenarios without needing named registers

Next

How do I match a pattern only when it is preceded or followed by another pattern, without including that context in the match?