Vim changes the text or immediately after entering it

Recently, I have been y anking and p , using a lot of code that needs to be changed a bit (usually it's just a simple substitution). I can manually select it after insertion or for longer blocks, I suppose I could look at the number of inserted lines ( 20 new lines ) and use 20:s... , but given that this vim seems to be easier / faster way to do this.

So, is there a way to select or perform substitution in the text since this is p ut?

+7
source share
2 answers

Immediately after executing p labels [ and ] refer to the numbers of the start and end lines of the nested area (also applies to y ). For help, see Help '[ and '] .

Thus, you can use these labels to form the range on which :s will work, like :'[,']s/// . Then it will work on the region just pulled or inserted. Of course, this is not short, but if you care about it, you can display it. Perhaps something like nnoremap <Leader>pp:'[,']s/ .

+8
source

Chris Morgan has already posted the best solution. But you can also perform some types of manipulations directly on the text in the register. The default case for yank is " , so you can do something like:

 :let @" = substitute(@",'someword', 'somedifferentword','g') 

Then paste the modified case text. Not so easy for manipulations related to the linear context in multiline register text, because the text in the register is one line with one start pattern ( ^ ) and one end ( $ ). But it can still be useful.

I just thought that I would throw it away, because that's what I sometimes do.

+3
source

All Articles