Vim Tips Wiki
Advertisement

Obsolete tip

This tip has been merged into another tip.
See VimTip605 for the current tip.

Please do not edit this tip, and do not edit the discussion page.
If anything needs to be improved, please fix VimTip605.


Tip 497 Printable Monobook Previous Next

created June 27, 2003 · complexity basic · author Adam Wolff · version 6.0


It's common to replace a given string in a file with something that appears elsewhere in the file. Often I don't think to put the replacement string in a named register, so it's hard to delete the text I'm replacing without replacing what's in the default (@") copy register -- :let is too cumbersome for this.

Anyway, I've been using this map:

vmap R :<BACKSPACE><BACKSPACE><BACKSPACE><BACKSPACE><BACKSPACE>:let @9=@"<CR>gvx"9P

which replaces what's highlighted in visual mode the contents of ""

It's ugly though (all the backspaces are necessary to delete the default :'<,'> that shows up when you start a command in visual mode.)

Comments

Afaik, Vim already works like your mapping. If you press 'p' when in visual mode, the selected text is replaced by the contents of the default register ('"<chosen_register>p' works as well). The deleted text is yanked as if deleted normally.


Use the black hole register to delete without changing any registers ("_d). See :help "_.


And you can replace these <backspace>'es with one <c-u>


Advertisement