1

I recently learned a new shortcut in VIM that I find extremely useful.

d/search_text

Which will delete everything up to, but not including, "search_text", from the current position.

However, the thing that is annoying is that this will highlight all occurrences of "search_text" after performing the operation.

Is there any way that I could disable the highlight feature when performing this operation?

3 Answers 3

2

Type:

:noh

I need to add more to overcome the post size limit.

2
  • My current solution was to type /sdgsah Or some other string that probably does not exist in the document. But see, both of these solutions are annoying - turning things on and off. Or searching for something that does not exist, in my 'solution'.
    – mateusz
    Apr 4, 2012 at 19:51
  • :noh is more "correct", though I agree that it's a pain to type. That's why I have it mapped to a shortcut key. I have map <F5> :nohls<CR> in my .vimrc, but which key you use is up to you. I picked <F5> because I use this so much it made sense to pick a prominent, single key. Apr 5, 2012 at 14:29
1

Seems like overkill to mess with the 'highlightsearch' setting just for this delete operation, but you could.


:set nohls
d/search_text
:set hls

There are more complicated ways, but they would require writing a function, or grabbing input.

1

I hate it so I leave hlsearch off (its default value) but have set incsearch in my ~/.vimrc.

Matching is done incrementally, the first occurence is highlighted and goes back to normal upon hitting <Return>. It's incredibly clean and useful.

See :help incsearch.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .