Sometimes I find it convenient to
- Search for text I want to replace
/original
- Start writing a substitution to replace that
:s/
- Use
C-r C-w
to put the current word hovered into the command line:s/original
I think some vimrc settings can be changed to combine 1 and 2? I recently switched to neovim and haven't copied all of my plugins and vimrc across yet, but I seem to remember that typing :s/wo...
would search in the text and show me partial matches, so I could immediately C-r C-w
.
Anyway, after choosing the word to replace, I want to choose the replacement word which is a word that appears somewhere else in the file, without typing that whole word manually into the command line.
Unfortunately, while typing the replacement part in :s
it seems like no words are highlighted in the file so I can't C-r C-w
.
For example, in this text I want to replace original
with replacement
, without typing all of replacement
.
lorem ipsum replacement dolor
original consectetur original
ullamcorper condimentum metus
How could I do it?
@/
, so you can do just/word_to_search
and thens//replace_with
– Matt May 10 '20 at 10:13/wo<C-r><C-w>
then I would do:s//re...
what next? so I don't have to type all ofreplace_with
? – theonlygusti May 10 '20 at 11:140
) before starting the:s
, you could do:s/original/\=getreg(0)/
– muru May 10 '20 at 11:40/
. So you can insert it with<C-r>/
. Only "better" if your last search was a regex not just a plain word. Regarding replacement: I don't think this is possible, but would be happy when someone proves me wrong. – Ralf May 10 '20 at 11:52