1

If I have a file that contains

this_is_the_first_underscore_phrase
this_is_the_first_underscore_phrase

I search for "first" /first and my cursor is placed onto the start of the word "first".

I know I can change this word by doing ct_ but I wonder if there's a different way, is there a way to "change inside currently highlighted text" ?

7

You can do:

gnc

gn will do a visual selection of the search result, then c is, as you know, change.

Also, cgn works (change the next occurence of the search result).

8
  • Awesome (will accept in 9 mins), had no idea that existed. How can I discover this for myself in the future? Apr 24 '19 at 14:59
  • 2
    Related Vimcasts episode: Operating on search matches using gn Apr 24 '19 at 15:35
  • 2
    @theonlygusti :help and :helpgrep are my go-tos
    – D. Ben Knoble
    Apr 24 '19 at 17:26
  • 1
    @theonlygusti for searching i like :helpgrep.
    – D. Ben Knoble
    Apr 25 '19 at 0:40
  • 1
    @theonlygusti if you are looking for text-objects, start reading at :h text-objects. And note, the gn and gN is mentioned right there. Apr 25 '19 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.