rhysd / clever-f.vim

Extended f, F, t and T key mappings for Vim.
https://rhysd.github.io/clever-f.vim
1.01k stars 44 forks source link

Feature Request: Reset highlights when <Esc> key is pressed #72

Closed ranelpadon closed 1 year ago

ranelpadon commented 1 year ago

I have this mapping to clear/reset the Vim's search results highlights (i.e. when using /):

nnoremap <Esc> :noh<CR>

So, I'm thinking if it's possible to use the <Esc> key also to reset the clever-f highlights instead of using the cursor keys?

Highlight won't be cleared until the cursor moves.

I think it's better UX than using g:clever_f_highlight_timeout_ms since sometimes you're not done yet, but the highlight will be auto-cleared. Clearing it on-demand offers more timing control. I think <Esc> is also a natural choice since it's kinda escaping the clever-f (find) mode.

BTW, thanks a lot for this useful/practical plugin! :)

rhysd commented 1 year ago

You can do both :noh and resetting highlights.

nnoremap <Esc> :noh<CR>:call clever_f#reset()<CR>

Automatically mapping it to <Esc> causes many issues across other plugins which also use <Esc> so this plugin does not map it by default. But you can configure it in your .vimrc.

ranelpadon commented 1 year ago

@rhysd This works! Thanks for the brilliant tip! Will close this issue now. :)