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!
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-@
I find editing the history is best for complicated searches. You can edit the search history with q/
. Just edit the line you want to use and press enter to execute the line.
There is also a great vimcast on refining search patterns using this technique.
:h q/
精彩评论