justinmk / vim-sneak

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

sneak removes user-defined <Esc> mapping #287

Closed stumash closed 2 years ago

stumash commented 2 years ago

If I map <esc> like so

nnoremap <esc> <esc>:call sneak#cancel()<cr>:<esc>

Then when I sneak around with, e.g., sXX, I can hit <esc> to stop showing the sneak highlighting.

However, I'd also like <esc> to clear highlights from regular searching with /. So, I do

nnoremap <esc> <esc>:call sneak#cancel()<cr>:noh<cr>:<esc>
" or I do it in reverse order
" nnoremap <esc> <esc>:noh<cr>:call sneak#cancel()<cr>:<esc>

Problems is, if I search /XX once and then hit <esc>, it clears the search highlights. But if I search /XX a second time then hit <esc>, it does not clear the search highlights. It does still clear sneak highlights though.

Any idea what's going on?

justinmk commented 2 years ago

sneak#cancel() checks if it exists in an <esc> mapping, because that is how sneak normally supports its ESC behavior: https://github.com/justinmk/vim-sneak/blob/95374ad3e4b5ef902854e8f4bcfa9a7a31a91d71/plugin/sneak.vim#L64

It doesn't know that it didn't set this mapping itself. And it can't know, because Vim doesn't provide that info.

You can workaround this by calling sneak#cancel() in a slightly different way:

nnoremap <esc> <esc>:call call('s'.'neak#cancel', [])<cr>:noh<cr>:<esc>

OTOH, perhaps sneak should do the hack to avoid this confusion.