summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/search.c21
-rw-r--r--src/testdir/test_gn.vim39
-rw-r--r--src/version.c2
3 files changed, 46 insertions, 16 deletions
diff --git a/src/search.c b/src/search.c
index 726013e62..57434ec0b 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4665,6 +4665,7 @@ current_search(
{
pos_T start_pos; /* position before the pattern */
pos_T orig_pos; /* position of the cursor at beginning */
+ pos_T first_match; /* position of first match */
pos_T pos; /* position after the pattern */
int i;
int dir;
@@ -4758,6 +4759,8 @@ current_search(
ml_get(curwin->w_buffer->b_ml.ml_line_count));
}
}
+ if (i == 0)
+ first_match = pos;
p_ws = old_p_ws;
}
@@ -4774,9 +4777,25 @@ current_search(
/* move to match, except for zero-width matches, in which case, we are
* already on the next match */
if (!one_char)
- result = searchit(curwin, curbuf, &pos, direction,
+ {
+ p_ws = FALSE;
+ for (i = 0; i < 2; i++)
+ {
+ result = searchit(curwin, curbuf, &pos, direction,
spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0,
NULL, NULL);
+ /* Search successfull, break out from the loop */
+ if (result)
+ break;
+ /* search failed, try again from the last search position match */
+ pos = first_match;
+ }
+ }
+
+ p_ws = old_p_ws;
+ /* not found */
+ if (!result)
+ return FAIL;
if (!VIsual_active)
VIsual = start_pos;
diff --git a/src/testdir/test_gn.vim b/src/testdir/test_gn.vim
index 7a77d9d88..6d48915c1 100644
--- a/src/testdir/test_gn.vim
+++ b/src/testdir/test_gn.vim
@@ -4,51 +4,51 @@ func Test_gn_command()
noautocmd new
" replace a single char by itsself quoted:
call setline('.', 'abc x def x ghi x jkl')
- let @/='x'
+ let @/ = 'x'
exe "norm! cgn'x'\<esc>.."
call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
sil! %d_
" simple search match
call setline('.', 'foobar')
- let @/='foobar'
+ let @/ = 'foobar'
exe "norm! gncsearchmatch"
call assert_equal('searchmatch', getline('.'))
sil! %d _
" replace a multi-line match
call setline('.', ['', 'one', 'two'])
- let @/='one\_s*two\_s'
+ let @/ = 'one\_s*two\_s'
exe "norm! gnceins\<CR>zwei"
call assert_equal(['','eins','zwei'], getline(1,'$'))
sil! %d _
" test count argument
call setline('.', ['', 'abcdx | abcdx | abcdx'])
- let @/='[a]bcdx'
+ let @/ = '[a]bcdx'
exe "norm! 2gnd"
call assert_equal(['','abcdx | | abcdx'], getline(1,'$'))
sil! %d _
" join lines
call setline('.', ['join ', 'lines'])
- let @/='$'
+ let @/ = '$'
exe "norm! 0gnd"
call assert_equal(['join lines'], getline(1,'$'))
sil! %d _
" zero-width match
call setline('.', ['', 'zero width pattern'])
- let @/='\>\zs'
+ let @/ = '\>\zs'
exe "norm! 0gnd"
call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
sil! %d _
" delete first and last chars
call setline('.', ['delete first and last chars'])
- let @/='^'
+ let @/ = '^'
exe "norm! 0gnd$"
- let @/='\zs'
+ let @/ = '\zs'
exe "norm! gnd"
call assert_equal(['elete first and last char'], getline(1,'$'))
sil! %d _
@@ -61,14 +61,14 @@ func Test_gn_command()
" backwards search
call setline('.', ['my very excellent mother just served us nachos'])
- let @/='mother'
+ let @/ = 'mother'
exe "norm! $cgNmongoose"
call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
sil! %d _
" search for single char
call setline('.', ['','for (i=0; i<=10; i++)'])
- let @/='i'
+ let @/ = 'i'
exe "norm! cgnj"
call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
sil! %d _
@@ -76,28 +76,28 @@ func Test_gn_command()
" search hex char
call setline('.', ['','Y'])
set noignorecase
- let @/='\%x59'
+ let @/ = '\%x59'
exe "norm! gnd"
call assert_equal(['',''], getline(1,'$'))
sil! %d _
" test repeating gdn
call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
- let @/='Johnny'
+ let @/ = 'Johnny'
exe "norm! dgn."
call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
sil! %d _
" test repeating gUgn
call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
- let @/='Depp'
+ let @/ = 'Depp'
exe "norm! gUgn."
call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
sil! %d _
" test using look-ahead assertions
call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
- let @/='a:0\@!\zs\d\+'
+ let @/ = 'a:0\@!\zs\d\+'
exe "norm! 2nygno\<esc>p"
call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
sil! %d _
@@ -113,12 +113,21 @@ func Test_gn_command()
" search upwards with nowrapscan set
call setline('.', ['foo', 'bar', 'foo', 'baz'])
set nowrapscan
- let @/='foo'
+ let @/ = 'foo'
$
norm! dgN
call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
sil! %d_
+ " search using the \zs atom
+ call setline(1, [' nnoremap', '' , 'nnoremap'])
+ set wrapscan&vim
+ let @/ = '\_s\zsnnoremap'
+ $
+ norm! cgnmatch
+ call assert_equal([' nnoremap', '', 'match'], getline(1,'$'))
+ sil! %d_
+
set wrapscan&vim
endfu
diff --git a/src/version.c b/src/version.c
index 4e4c1fbee..1f8cfefb0 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 18,
+/**/
17,
/**/
16,