justinmk / vim-sneak

The missing motion for Vim :athletic_shoe:
http://www.vim.org/scripts/script.php?script_id=4809
MIT License
3.26k stars 88 forks source link

Question: Why the nested CursorMoved autocmds to clear highlights? #305

Closed tuurep closed 1 year ago

tuurep commented 1 year ago

~Sneak clears its highlights after 2 CursorMove events.~ ^ This happens if you have let g:loaded_matchparen = 0 or disable matchparen with Lazy.nvim


I've gotten used to the vim-cool -train of thought that all Search highlights clear on the first cursormove so it'd be nice if I could reduce the CursorMoved to just the first.

It can sorta be achieved by un-nesting the autocmds in plugin/sneak.vim line 272

func! s:attach_autocmds() abort
  augroup sneak
    autocmd!
    autocmd InsertEnter,WinLeave,BufLeave * call sneak#cancel()
    "_nested_ autocmd to skip the _first_ CursorMoved event.
    "NOTE: CursorMoved is _not_ triggered if there is typeahead during a macro/script...
    autocmd CursorMoved * autocmd sneak CursorMoved * call sneak#cancel()
  augroup END
endf

However, I notice 2 issues:

  1. Sneak_t and Sneak_T highlights no longer work
  2. Sometimes pressing and holding , or ; turns off highlighting at an inappropriate time. Most reproducible for me was to hold down , but release it right before key repeat would start firing.

Did you choose the 2-moves threshold for aesthetic reasons, or for something similar I encountered above?

justinmk commented 1 year ago

I've gotten used to the vim-cool -train of thought that all Search highlights clear on the first cursormove so it'd be nice if I could reduce the CursorMoved to just the first.

Not sure what you mean. The "first" move is done internally by sneak, which is why the nested handler is used (although maybe that could be simplified, possibly by moving the s:attach_autocmds() call later. (edit: doesn't work)

But in any case, as a user you should only have to move the cursor once. Maybe some other plugin is interfering.

justinmk commented 1 year ago

If you're referring to the non-label-mode behavior where hitting ; doesn't clear the highlights... you can call sneak#cancel() from a <Plug>Sneak_; mapping.

That also raises the question, why have highlights at all for non-label-mode? To disable highlights see :help sneak-highlight:

To disable highlighting:  
    highlight link Sneak None
    " Needed if a plugin sets the colorscheme dynamically:
    autocmd User SneakLeave highlight clear Sneak
tuurep commented 1 year ago

But in any case, as a user you should only have to move the cursor once. Maybe some other plugin is interfering.

Hey thanks a lot, after reading this I tried with a minimal config and indeed I was wrong in my post.

The setting that caused this bug was:

let g:loaded_matchparen = 0

which I have had in my configs forever. What a weird interference, does that give you any idea of a bug?

As a workaround I can load matchparen and set MatchParen highlight group to None