Lately I’ve been yanking and putting a lot of code that needs to be altered somewhat (usually just a simple substitution). I can manually select it after it’s pasted in, or for longer blocks I suppose I could look at the number of lines pasted (20 new lines) and use 20:s..., but given that it’s vim, it seems like there should be an easier/faster way to do this.
So is there a way to either select or execute a substitution on text as it’s being put?
Immediately after the execution of the
p, the[and]marks refer to the start and end line numbers of the pasted region (applies duringyas well). See the help for'[and']for explanation.Thus, you can use these marks to form the range on which to work the
:s, as:'[,']s///. This will then work on the region just yanked or pasted. Sure, it’s not short, but if you care about it you can map it. Perhaps something likennoremap <Leader>p p:'[,']s/.