@@ -18,16 +18,16 @@ func! sneak#init()
18
18
unlockvar g: sneak #opt
19
19
" options v-- for backwards-compatibility
20
20
let g: sneak #opt = { ' f_reset' : get (g: , ' sneak#nextprev_f' , get (g: , ' sneak#f_reset' , 1 ))
21
- \ ,' t_reset' : get (g: , ' sneak#nextprev_t' , get (g: , ' sneak#t_reset' , 1 ))
22
- \ ,' s_next' : get (g: , ' sneak#s_next' , 0 )
23
- \ ,' absolute_dir' : get (g: , ' sneak#absolute_dir' , 0 )
24
- \ ,' textobject_z' : get (g: , ' sneak#textobject_z' , 1 )
25
- \ ,' use_ic_scs' : get (g: , ' sneak#use_ic_scs' , 0 )
26
- \ ,' map_netrw' : get (g: , ' sneak#map_netrw' , 1 )
27
- \ ,' streak' : get (g: , ' sneak#streak' , 0 ) && (v: version >= 703 ) && has (" conceal" )
28
- \ ,' streak_esc' : get (g: , ' sneak#streak_esc' , " \<space> " )
29
- \ ,' prompt' : get (g: , ' sneak#prompt' , ' >' )
30
- \ }
21
+ \ ,' t_reset' : get (g: , ' sneak#nextprev_t' , get (g: , ' sneak#t_reset' , 1 ))
22
+ \ ,' s_next' : get (g: , ' sneak#s_next' , 0 )
23
+ \ ,' absolute_dir' : get (g: , ' sneak#absolute_dir' , 0 )
24
+ \ ,' textobject_z' : get (g: , ' sneak#textobject_z' , 1 )
25
+ \ ,' use_ic_scs' : get (g: , ' sneak#use_ic_scs' , 0 )
26
+ \ ,' map_netrw' : get (g: , ' sneak#map_netrw' , 1 )
27
+ \ ,' streak' : get (g: , ' sneak#streak' , 0 ) && (v: version >= 703 ) && has (" conceal" )
28
+ \ ,' streak_esc' : get (g: , ' sneak#streak_esc' , " \<space> " )
29
+ \ ,' prompt' : get (g: , ' sneak#prompt' , ' >' )
30
+ \ }
31
31
32
32
for k in [' f' , ' t' ] " if user mapped f/t to Sneak, then disable f/t reset.
33
33
if maparg (k , ' n' ) = ~# ' Sneak'
@@ -152,9 +152,19 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
152
152
let nudge = sneak#util#nudge (! a: reverse ) " special case for t
153
153
endif
154
154
155
+ " detect whether folds should be opened during search according to &foldopen
156
+ let l: search_foldopen = ! empty (matchstr (&foldopen ," search" ))
157
+
155
158
for i in range (1 , max ([1 , skip ])) " jump to the [count]th match
159
+ " if in a closed fold, jump to end of it for 'set foldopen-=search'
160
+ let l: winview = winsaveview ()
161
+ if ! l: search_foldopen && foldclosed (' .' ) > -1
162
+ call cursor (a: reverse ? foldclosed (' .' ) : foldclosedend (' .' ),
163
+ \ a: reverse ? 1 : ' $' )
164
+ endif
156
165
let matchpos = s .dosearch ()
157
- if 0 == max (matchpos)
166
+ if 0 == max (matchpos) " if no search results found
167
+ call winrestview (l: winview ) " revert jump to end of fold and break
158
168
break
159
169
else
160
170
let nudge = ! a: inclusive
@@ -172,9 +182,9 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
172
182
endif
173
183
" search succeeded
174
184
175
- " if &foldopen contains search, folds are opened when jumping to matches
176
- if ! empty ( matchstr (& foldopen , " search " ))
177
- norm! zv
185
+ " open folds when jumping to matches if necessary
186
+ if l: search_foldopen
187
+ norm! zv
178
188
endif
179
189
180
190
call sneak#hl#removehl ()
0 commit comments