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_f + s_next ("clever s") breaks :normal #264

Open mattboehm opened 4 years ago

mattboehm commented 4 years ago

I recently updated my vimrc to use sneak's versions of f/t:

let g:sneak#s_next = 1
map f <Plug>Sneak_f
map F <Plug>Sneak_F
map t <Plug>Sneak_t
map T <Plug>Sneak_T

However, if I try to run a command like :%normal f(D, I often get unexpected results. For instance on this file:

a(b)
c(d)

I end up with:

<blank line>
c(d)

(<blank line> is a literal blank line)

If I unmap f, I get the expected result:

a
c

Do you know if there's a fix/workaround for this? Thanks!

mattboehm commented 3 years ago

I think I'm going to have to make a custom :Normal command that disables sneak first and re-enables it afterwards. I've used :normal! to get around this, but this disables other custom mappings that I'd like to still be able to use.

justinmk commented 3 years ago

With s_next disabled it works fine. The problem seems to be g:sneak#s_next=1 ("clever s"). Not sure anything can be done here, because "clever s" works by setting up temporary mappings.

mattboehm commented 3 years ago

@justinmk hmm I was thinking I could fix my specific problem by toggling this setting off/on on CmdLineEnter/CmdLineLeave events, but I believe these settings are just read once on init(). The best hack I can think of for now is to unmap/remap f/t on these events.

Actually, CmdLineLeave probably triggers before the normal mode changes are executed, so I'd probably actually need to wrap :normal in a custom command that does this.

ggandor commented 3 years ago

@mattboehm Awesome, you might just have solved a problem regarding our somewhat related issue (which in fact could apply to Sneak too). CmdlineEnter seems a fine way to detect :normal execution, I haven't thought about that. Many thanks :) CmdlineLeave triggering before the actual execution of the changes seems a problem though.