DEV Community

Discussion on: My Vim Story

Collapse
 
konart profile image
Artem Kondratev

nnoremap <Leader>/ :let @/=""<CR>

Might be a better way to clear / after the search. See stackoverflow.com/a/657484 (+ comments)

Collapse
 
ianturton profile image
Ian Turton

I use :command! C let @/="" so I can simply hit :C to clear

Collapse
 
konart profile image
Artem Kondratev

Well, mapping is one's personal preference of course :)

Collapse
 
gaveen profile image
Gaveen Prabhasara

It can definitely be useful depending on what you want to achieve. However, I wouldn't necessarily call it "better" without a context.

To elaborate, while :let @/=""<CR> clears the search pattern, what I have (i.e., :noh/:nohlsearch) only clears the highlighting (i.e., search pattern remains the same, just without highlighting), which is exactly what I want in most cases. This way, if I need to jump to the next occurrence of search pattern, I only need to press n which will do so, as well as start highlighting again.

Collapse
 
konart profile image
Artem Kondratev

Sure, different workflow, different approach.

I guess I'm too used to my typical workflow: while I still need my search result - I want it highlighted, but after I'm done with it - it should be gone.