So often if I have a code expression like points.length - 1
and I want to replace it with a variable (for example, named target_idx
then I'll define the variable:
int target_idx = points.length - 1;
But now I want to go and replace all instances of points.length - 1
with target_idx
. I'm aware I could do :%s/points.length - 1/target_idx/g
, but I'm not too confident in my regex and don't want to mistakenly replace points.length - 11
or points+length - 1
by mistake. (I'm also aware of very magic searching, but also am not super confident about all the subtleties of what it does/doesn't consider special characters)
So what I want is to be able to search for instances matching points.length - 1
via /points.length - 1
and then go through the search results with n
, and then replace the text with target_idx
.
But because the searched-for text could have spaces or other characters, I can't simply change to the end of the Word cE
since this would only change points.length
in my example.
Is there a text motion that goes to the end of the searched-for text?
So I could go
n
c<special text motion here>
target_idx
- repeat from 1.
I'm using neovim with CoC installed, so am open to more in-depth ideas with plugins or language server replacements, but this feels like it should be a simple text motion that I just don't know of.