I have incsearch on, so when I type :s/thingS it will highlight the thingS part of thingSoFar in the below text

see, this thing is the thingSoFar thing

When I am typing that command line with my cursor at the first column, first the t, then th, then thi of "this" are highlighted. When I type the n, it no longer matches this, so the highlighting jumps to the first thing's thin. When I type g the highlighting remains on that word. Then when I type S it jumps forwards to highlight the thingS of thingSoFar. Standard incsearch behaviour.

Now, I would like to <C-r><C-w> the currently highlighted word, rather than the word that my cursor was on when I entered command line mode.

E.g., I put my cursor on the first column in the line above (on the s of see)

Now I type


I would like my command line to be filled like this:


instead I get this


How can I actually get the result I want? How can I complete the word I'm typing in the command line with the currently incsearch-highlighted word?

2 Answers 2


There is :help c_ctrl-l, which inserts one character of the first match:

:s/thingSo       " <C-l>
:s/thingSoF      " <C-l>
:s/thingSoFa     " <C-l>
:s/thingSoFar    " <C-l>

but a) the characters come from the first match, which is probably not that useful, and b) it only inserts one character, which possibly means doing lots of <C-l>s to get what you want. In this case, pressing <C-l> four times is not a lot worse than pressing <C-r><C-w> once but still.

At a much higher level, you have the venerable CmdlineComplete plugin.


running vim -u NONE and activating set incsearch does result in your desired behaviour.

<C-R><C-W> does fill in the entire word thingSoFar. Within substitution and search on the cmdline.

I am not able to provide you a specific patch from the repository which implements this functionality but it is documented since this commit to be the default behaviour for incsearch: Version 7.0226

  • You're right, that works for me too. My main editor is actually neovim, hadn't thought to check this sorry about that.
    – minseong
    Commented Dec 10, 2022 at 23:32

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.