Can vim(or by some plugin) highlight current matching words when I input replace command? For example, given following document:

attribute_list = [
    ("attribute_1", int),
    ("attribute_2", float),
    ("attribute_3", int),

I want to replace all int by bool with vim command :%s/int/bool/g. When I input :%s/in can vim highlight all the in in the document? I need this feature because I want to check my search pattern is correct when I replace some text by regexp.

The vim plugin EasyMotion have a similar feature. It can highlight all the current matching words when you search.

  • 1
    Assuming you have hlsearch and incsearch set, how about first searching using / and after you have verified replacing? Apr 13, 2015 at 12:15
  • @LievenKeersmaekers Before I ask this question, I do first searching using / before replacing. I ask this question because I don't want to type the search pattern twice. But now I saw the answer of @IngoKarkat, turn out I don't need to repeat the search pattern. So I think it acceptable for me.
    – kkpattern
    Apr 14, 2015 at 7:20
  • I didn't know you didn't know about not having to repeat the search pattern :) Apr 14, 2015 at 8:35

1 Answer 1


There's no such built-in option. Such behavior could be built by hooking into the typing of characters into the command-line, but as there's no generic autocmd for that, you'd have to override every possible typed key, and run the risk of interfering with other plugins or abbreviations.

There's a simple tweak to your workflow that gives you similar behavior, though, and I would suggest that as a much better alternative: First search for the pattern via /int; if you have :set hlsearch incsearch, you'll then have the on-the-fly highlighting of matches. Accept the match via <CR>, and then do the subsitution. You don't need to repeat the search pattern there, so this becomes:

  • Didn't know I don't need to repeat the search pattern. Thank you.
    – kkpattern
    Apr 14, 2015 at 7:22

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.