README

October 31, 2014 ยท View on GitHub

This is a mirror of http://www.vim.org/scripts/script.php?script_id=2703

DESCRIPTION Replacing an existing text with the contents of a register is a very common task during editing. One typically first deletes the existing text via the d, D or dd commands, then pastes the register with p or P. Most of the time, the unnamed register is involved, with the following pitfall: If you forget to delete into the black-hole register ("_), the replacement text is overwritten!

This plugin offers a two-in-one command that replaces text covered by a {motion}, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. (But of course, the command can be easily undone.)

The replacement mode (characters or entire lines) is determined by the replacement command / selection, not by the register contents. This avoids surprises like when the replacement text was a linewise yank, but the replacement is characterwise: In this case, no additional newline is inserted.

SEE ALSO

  • ReplaceWithSameIndentRegister.vim (vimscript #5046) is a companion plugin for the special (but frequent) case of replacing lines while keeping the original indent.
  • LineJugglerCommands.vim (vimscript #4465) provides a similar :Replace [["]x] Ex command.

RELATED WORKS

USAGE [count]["x]gr{motion} Replace {motion} text with the contents of register x. Especially when using the unnamed register, this is quicker than "_d{motion}P or "_c{motion}" [count]["x]grr Replace [count] lines with the contents of register x. To replace from the cursor position to the end of the line use ["x]gr$ {Visual}["x]gr Replace the selection with the contents of register x.