1

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

:s/thingS<C-r><C-w>

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

:s/thingSoFar

instead I get this

:s/thingSsee

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

3

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

:s/thingS
: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.

2

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

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

Your Answer

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

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