When I do an interactive search for some pattern, each time I hit n, I get the next result. How do I delete / change each result that I come to?
Ideally, what I'm looking for would work like this: I hit n to get the search result, and then magic command to highlight that result in visual mode, and then I can do d or c to delete or change the highlighted text.
Example:
I enter the command
/hello .
and it matches hello, a space, and any character after it.
So say the first match it reaches is "hello w".
Now, I want to delete all of hello w, search for the next match (say it is hello a), change the next match to hello there, and keep doing different things to each match.
I'm not looking for just search-and-replace, because I want to be able to perform any action on each result interactively, such as delete the first result, replace the second result with bye, and replace the third result with later.
You can also just search using /phrase , select the next match with gn , and delete it with d .
To select the entire match of the current match (if you are at the start of the match) you can type
v//e
To delete to the end of the match
d//e
To change the match
c//e
Only negative is that you cant use n (as that will redo //e ) and instead have to use //
So typical workflow would look like this
/hello ./ : Jump to the start of the next "hello ."
d//e : Delete the item
// : repeat the search to get to the begining of the next "hello ."
c//e : change it
// : next one.
etc.
I think you want gn: (Go to the next match and) select it in visual mode. You can prefix this with a command, e.g. cgn changes the match, dgn deletes etc. I found that if already on a match, this match is used, so that this should do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With