Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim, is it possible to search and replace content inside the register?

Tags:

vim

For example, one of my registers "a has content "vim is awesome" and I want to replace awesome with "cool" inside the register "a

BTW, I'm not looking using content of register as search/replacement pattern. I knew I can paste the content of register a in command mode with CTRL-R a

like image 295
user3663904 Avatar asked Sep 04 '25 17:09

user3663904


1 Answers

Maybe something like this. Which is basically take the value in register a and send it through the substitute command and put it back into the register (with the correct register type)

:call setreg('a', substitute(getreg('a'), 'pat', 'sub', 'g'), getregtype('a'))

Or if you don't care about the regtype when you are done

:let @a=substitute(@a, 'pat', 'sub', 'g')

would be simplier.

like image 63
FDinoff Avatar answered Sep 07 '25 20:09

FDinoff