History Report a problem
Article Edit this page Discussion

Replace a word with the yanked text

From Vim Tips Wiki

(Redirected from VimTip605)
Jump to: navigation, search

Tip 605 Previous TipNext Tip

Created: November 18, 2003 Complexity: basic Author: Yang Xiangyu Minimum version: 6.0 Karma: 28/12 Imported from: Tip#605


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

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pushing Daisies
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Astronomy Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for featured Wikia!

Send this article to a friend
"Replace a word with the yanked text"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation