1

In my .vimrc I've enabled highlighting the searched text (which I find to be a handy feature and wouldn't want to disable it).

set hlsearch

And, following answers to this question, I've made a mapping to be able to clear the highlight:

nmap <silent> ,/ :nohlsearch<CR>

The problem comes with commands which include search. For example, delete to next character 'x':

d/x

This will automatically highlight all the instances of 'x'. To remove this highlight I have to punch ,/ to clear it, which is quite annoying.

The question. Is it possible to enforce :nohl if the search is a part of a preceding command? Maybe, it is possible at least for a selected list of commands (say, d, y and c) before / character is hit?

Community
  • 1
  • 1
sashkello
  • 17,306
  • 24
  • 81
  • 109

2 Answers2

0

d/x does not work for me as you describe. (I'm on vim 7.3 here and it can't make sense of the / following d in normal mode, so disregards the d and starts a regular / search.)
If you want to delete to the next x, then dfx or dtx are what I would use (depending on whether you want to also delete the x itself or not).
No highlighting involved.
Hope that helps.

[Following some clarification in the comments.]
I'm thinking that it should be possible to write a custom function to do what you want, and then assign a custom key sequence to call that function.
I played around a little, but am not very well versed in vim functions and couldn't make it work.
Here's what I tried:

function! g:DeleteToSearchAndNohls(term)  
    :normal d/a:term  
    :nohlsearch  
endfunc  
Edward
  • 1,000
  • 5
  • 16
  • Did you try pushing Enter after d/x? This is what I have to do because search may contain several symbols and you need to tell vim where it ends. – sashkello Oct 18 '13 at 01:32
  • This does provide a nice alternative to what I'm trying to do though. Thanks. – sashkello Oct 18 '13 at 01:35
  • So `dtx` may not take you directly to your real target. In case you weren't aware of this, `.` will repeat the last action, so you can keep deleting to the next x easily until you do reach your target. That's probably still more work than you're already doing, though... – Edward Oct 19 '13 at 19:26
0

If 'x' is on the same line than the cursor, you can use dtx (meaning delete to x).

Yann Moisan
  • 8,161
  • 8
  • 47
  • 91