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" ?

1 Answer 1

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?
    – minseong
    Commented Apr 24, 2019 at 14:59
  • 2
    Related Vimcasts episode: Operating on search matches using gn Commented Apr 24, 2019 at 15:35
  • 2
    @theonlygusti :help and :helpgrep are my go-tos
    – D. Ben Knoble
    Commented Apr 24, 2019 at 17:26
  • 1
    @theonlygusti for searching i like :helpgrep.
    – D. Ben Knoble
    Commented Apr 25, 2019 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. Commented Apr 25, 2019 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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