Skip to content

Commit

Permalink
Enforce search behavior according to &foldopen
Browse files Browse the repository at this point in the history
Sneaking now behaves like / when "foldopen-=search" is set: Closed folds
are considered to be single targets and are not opened when sneaking to
them. They are opened, however, when the default-&foldopen is used or
"foldopen+=search" is set.
Resolve justinmk#102.

This does not affect streak-mode (which still ignores &foldopen).
  • Loading branch information
milsen committed Nov 30, 2015
1 parent c6b5708 commit 9670818
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion plugin/sneak.vim
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,19 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
let nudge = sneak#util#nudge(!a:reverse) "special case for t
endif

" detect whether folds should be opened during search according to &foldopen
let l:search_foldopen = !empty(matchstr(&foldopen,"search"))

for i in range(1, max([1, skip])) "jump to the [count]th match
" if in a closed fold, jump to end of it for 'set foldopen-=search'
let l:winview = winsaveview()
if !l:search_foldopen && foldclosed('.') > -1
call cursor(a:reverse ? foldclosed('.') : foldclosedend('.'),
\ a:reverse ? 1 : col('$'))
endif
let matchpos = s.dosearch()
if 0 == max(matchpos)
if 0 == max(matchpos) " if no search results found
call winrestview(l:winview) " revert jump to end of fold and break
break
else
let nudge = !a:inclusive
Expand All @@ -172,6 +182,11 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
endif
"search succeeded

" open folds when jumping to matches if necessary
if l:search_foldopen
norm! zv
endif

call sneak#hl#removehl()

if (!is_op || a:op ==# 'y') "position _after_ search
Expand Down

0 comments on commit 9670818

Please sign in to comment.