diff options
-rw-r--r-- | src/nvim/ex_getln.c | 5 | ||||
-rw-r--r-- | src/nvim/testdir/test_search.vim | 87 |
2 files changed, 70 insertions, 22 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a30b13ae34..6023b8d26b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -295,7 +295,10 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, if (*cmd == 's' || *cmd == 'g' || *cmd == 'v') { // Skip over "substitute" to find the pattern separator. for (p = cmd; ASCII_ISALPHA(*p); p++) {} - if (*p != NUL) { + if (*p != NUL + && (STRNCMP(cmd, "substitute", p - cmd) == 0 + || STRNCMP(cmd, "global", p - cmd) == 0 + || STRNCMP(cmd, "vglobal", p - cmd) == 0)) { delim = *p++; end = skip_regexp(p, delim, p_magic, NULL); if (end > p) { diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 087a261cca..7348c8c4e2 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -346,27 +346,6 @@ func Test_searchc() bw! endfunc -func Test_search_cmdline3() - throw 'skipped: Nvim does not support test_override()' - if !exists('+incsearch') - return - endif - " need to disable char_avail, - " so that expansion of commandline works - call test_override("char_avail", 1) - new - call setline(1, [' 1', ' 2 the~e', ' 3 the theother']) - set incsearch - 1 - " first match - call feedkeys("/the\<c-l>\<cr>", 'tx') - call assert_equal(' 2 the~e', getline('.')) - " clean up - set noincsearch - call test_override("char_avail", 0) - bw! -endfunc - func Cmdline3_prep() throw 'skipped: Nvim does not support test_override()' " need to disable char_avail, @@ -384,6 +363,20 @@ func Cmdline3_cleanup() bw! endfunc +func Test_search_cmdline3() + throw 'skipped: Nvim does not support test_override()' + if !exists('+incsearch') + return + endif + call Cmdline3_prep() + 1 + " first match + call feedkeys("/the\<c-l>\<cr>", 'tx') + call assert_equal(' 2 the~e', getline('.')) + + call Cmdline3_cleanup() +endfunc + func Test_search_cmdline3s() throw 'skipped: Nvim does not support test_override()' if !exists('+incsearch') @@ -393,6 +386,12 @@ func Test_search_cmdline3s() 1 call feedkeys(":%s/the\<c-l>/xxx\<cr>", 'tx') call assert_equal(' 2 xxxe', getline('.')) + undo + call feedkeys(":%subs/the\<c-l>/xxx\<cr>", 'tx') + call assert_equal(' 2 xxxe', getline('.')) + undo + call feedkeys(":%substitute/the\<c-l>/xxx\<cr>", 'tx') + call assert_equal(' 2 xxxe', getline('.')) call Cmdline3_cleanup() endfunc @@ -406,6 +405,9 @@ func Test_search_cmdline3g() 1 call feedkeys(":g/the\<c-l>/d\<cr>", 'tx') call assert_equal(' 3 the theother', getline(2)) + undo + call feedkeys(":global/the\<c-l>/d\<cr>", 'tx') + call assert_equal(' 3 the theother', getline(2)) call Cmdline3_cleanup() endfunc @@ -420,6 +422,10 @@ func Test_search_cmdline3v() call feedkeys(":v/the\<c-l>/d\<cr>", 'tx') call assert_equal(1, line('$')) call assert_equal(' 2 the~e', getline(1)) + undo + call feedkeys(":vglobal/the\<c-l>/d\<cr>", 'tx') + call assert_equal(1, line('$')) + call assert_equal(' 2 the~e', getline(1)) call Cmdline3_cleanup() endfunc @@ -480,6 +486,45 @@ func Test_search_cmdline5() bw! endfunc +func Test_search_cmdline7() + throw 'skipped: Nvim does not support test_override()' + " Test that an pressing <c-g> in an empty command line + " does not move the cursor + if !exists('+incsearch') + return + endif + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + let @/ = 'b' + call setline(1, [' bbvimb', '']) + set incsearch + " first match + norm! gg0 + " moves to next match of previous search pattern, just like /<cr> + call feedkeys("/\<c-g>\<cr>", 'tx') + call assert_equal([0,1,2,0], getpos('.')) + " moves to next match of previous search pattern, just like /<cr> + call feedkeys("/\<cr>", 'tx') + call assert_equal([0,1,3,0], getpos('.')) + " moves to next match of previous search pattern, just like /<cr> + call feedkeys("/\<c-t>\<cr>", 'tx') + call assert_equal([0,1,7,0], getpos('.')) + + " using an offset uses the last search pattern + call cursor(1, 1) + call setline(1, ['1 bbvimb', ' 2 bbvimb']) + let @/ = 'b' + call feedkeys("//e\<c-g>\<cr>", 'tx') + call assert_equal('1 bbvimb', getline('.')) + call assert_equal(4, col('.')) + + set noincsearch + call test_override("char_avail", 0) + bw! +endfunc + " Tests for regexp with various magic settings func Test_search_regexp() enew! |