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

How do I delete a word and save it to a specific register?

Answer

"adiw

Explanation

The "adiw command deletes the inner word under the cursor and stores it in register a. The text is available for pasting with "ap.

How it works

  • "a specifies register a
  • d is the delete operator
  • iw is the inner word text object
  • The word is removed from the buffer and stored

Example

You want to move a variable name from one location to another:

  1. "adiw on the word to cut it into register a
  2. Navigate to the new location
  3. "aP pastes it before the cursor

Tips

  • "aciw changes the word and stores the old text in a
  • "add deletes the entire line to register a
  • Named registers preserve text across other operations
  • Use different registers for different pieces of text

Next

How do you yank a single word into a named register?