Replace a word with the yanked text
From Vim Tips Wiki
Tip 605 Previous Next Created: November 18, 2003 Complexity: basic Author: Yang Xiangyu Version: 6.0
With this mapping, you can press S to replace the current word with the last-yanked text.
map S diw"0P
The S command is then not available – use the equivalent cc command instead.
Here is an alternative mapping that replaces the current word with the last yanked or deleted text. You can use the last yanked or deleted text multiple times to replace words at different locations.
nmap <silent> S :let @x=@"<CR>"_diw"xP
The mapping uses the x register to save the unnamed register (@") before deleting the current word. The black hole register (@_) is used for the deletion so the unnamed register won't be changed.
If you don't have a mapping, you can always type commands like the following.
yiw " yank inner word (FIRST) ... " move the cursor to some other word (SECOND) viwP " select SECOND, then replace it with FIRST
[edit] References
[edit] Comments
Use numbered register 2 to insert previously deleted text.
map S diw"2P
