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

Unable to move the end of a visual selection with `;` when a match is inside a closed fold #212

Closed lacygoill closed 6 years ago

lacygoill commented 6 years ago

After remapping f to <Plug>Sneak_s, and pressing ; while in visual mode, as soon as the next match is inside a fold, instead of moving to the latter, it seems the cursor moves to the end of the fold. And it's impossible to get back to a match before the fold by pressing ,.

Here's a minimal vimrc to reproduce:

set fdm=marker

set rtp+=~/.vim/plugged/vim-sneak/ "{{{1
map f <Plug>Sneak_f
map F <Plug>Sneak_F

Start Vim like this:

vim -Nu /tmp/vimrc /tmp/vimrc +'norm! 1|1'

Press:

The cursor should move to the equal sign, right after set rtp+, and you should be able to move the end of the selection between the 2 equal signs. Instead the cursor is stuck on the end of the fold.

lacygoill commented 6 years ago

Ah, after thinking about this a little more, I suspect the issue does not come from the plugin but from a limitation inside Vim. Maybe I should try to write a wrapper to temporarily disable folds.

Edit:

This seems to work:

set fdm=marker
set rtp+=~/.vim/plugged/vim-sneak

fu! s:visual_sneak(fwd) abort
    let fen_save = &l:fen
    let &l:fen = 0
    call feedkeys("\<plug>Sneak_".(a:fwd ? ';' : ','), 'it')
    call timer_start(0, {-> execute('let &l:fen ='.fen_save.'|norm! zv')})
    return ''
endfu

map         f    <plug>Sneak_f
map         F    <plug>Sneak_F

nmap        ;    <plug>Sneak_;
nmap        ,    <plug>Sneak_,
xmap <expr> ;    <sid>visual_sneak(1)
xmap <expr> ,    <sid>visual_sneak(0)