15

Given a file like the following:

blah
blah
collection = getCollection();
process(somethingInTheWay, target);

...after this short sequence of 'search' commands in vim...

/col<carriage return>

My cursor will be under the first appearance of "collection."

Now, what command(s) will remove the '/col' from my vim command line (in case I want to search afresh, for example)?

2
  • 2
    Assuming you are still in Normal mode, just start typing /<new search>. Sep 11, 2014 at 12:08
  • 2
    after you pressed Enter, you are already in Normal mode. just press / again to do new search
    – Kent
    Sep 11, 2014 at 13:35

1 Answer 1

30

There are a couple of things that play a role here. Your input ("/col") is displayed in the command line for some extra time after search. Usually people don't care about this. After some time, some find it even helpful. You already left "search mode" when you pressed Enter and after vim put the cursor on the first match. vim will lazily remove the search string when redrawing screen or when the space is needed. There are some ways to remove it manually, if you want to:

  • Ctrl-L (redraw)
  • :redraw
  • any combination of / or : with Esc or Backspace

Now I wrote, that you already left "search mode" with Enter, but you may continue your last search at any time with n / N. These commands will just take whatever is in the special register / and use it for further searching. It would be possible to "disable" this behaviour by removing the last search pattern from /:

:let @/ = ""

You could manually put something into that register which would enable you to "continue search" without ever having started any search.

If you just want to get rid of the currently highlighted matches, type:

:noh

You can turn off or toggle highlighting matches in general:

:set nohls
:set hls!

The latter is a good candidate for a key binding. I use this to toggle highlighting of the last search (mnemonic: klear - not very accurate but works for me):

:nno <C-k> :set hls!<CR>

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.