Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I edit the search text in vim?

I've searched online for this a while, but I couldn't find an answer.

What I want to do is to edit the previously entered search text in vim.

For example, say I just searched for "FooClass". Then I want to search for "FooMethod", but rather than typing the whole word from scratch, I would like to backspace 5 times to remove "Class", and just type "Method" after "Foo".

Thanks!

like image 955
steve Avatar asked Nov 29 '22 18:11

steve


1 Answers

Press / then Up, then backspace five times. (Probably assumes nocp is set).


Stop reading now unless you want to learn some fancy new tricks...

If you want to get clever, you can also use Ctrl-R to pull things onto the search box (e.g. put the cursor on a word, press /, then press and hold Ctrl and press R then W and it will pull the word under the cursor onto the search line: similar to pressing *, but editable and without the word boundaries).

If you want to get really clever, you can use all of vimscript's cleverness to set @/ to be whatever you want to search for and then press n:

:let @/ = 'Foo' . 'Method'
n

Probably more than you wanted to know though...

See:

:help 'nocp'
:help c_CTRL-R
:help c_CTRL-R_CTRL-W
:help *
:help quote/
:help :let-@
like image 50
DrAl Avatar answered Dec 04 '22 22:12

DrAl