Bram, attached patch contains the fixes discussed at https://github.com/vim/vim/issues/2267 including some tests.
Those newly added (or changed) tests are: - Test_search_cmdline6 makes sure, that <c-g> will skip to the next pattern and does not skip consecutive patterns - Test_search_cmdline7 makes sure, that <c-g> does not move the cursor, if no pattern has been entered (and so does not move to the previous used pattern) (This might have been a feature for some people, however in #2267 it was considered a bug, so I removed that "feature"). Fix is courtesy of h-east - Test_search_cmdline8 make sure, that all windows are redrawn after leaving the commandline. This makes sense, since the hlsearch pattern applies globally to all windows. Fix is courtesy of haya14busa Note: The test does not fail on an unpatched Vim, however when run interactively it works correctly. Don't know why this happens. - Test_search_cmdline_incsearch_highlight_attr Fix that this does not work on Windows (as mentioned in https://groups.google.com/d/msg/vim_dev/YvyOOnc3KW0/wTPvl2bIBgAJ) It includes the fix for the test from that message. It also throws skipped on Windows, as `term_sendkeys(...,"\<esc>")` does not work correctly on windows and this is needed to verify that Test_search_cmdline8 works correctly. It also contains a bugfix for the documentation: - autocmd CmdlineEnter [/\?] :set hlsearch - autocmd CmdlineLeave [/\?] :set nohlsearch + autocmd CmdlineEnter /,\? :set hlsearch + autocmd CmdlineLeave /,\? :set nohlsearch This does not work on Windows. Don't know why. Somehow the cmdwin-char for forward search seems to be `\` on a windows machine, at least this is what I get with ,---- | au CmdlineEnter * :echomsg expand("<afile>") `---- However, this does not explain, why the pattern /,\? works. But since it does, I just updated the documentation. Another pattern that works would be `[/\\?]` Christian -- Meinungen sind wie Grundstücke: Erstens sind sie zu teuer, und zweitens kann man nicht immer darauf bauen. -- Dieter Hildebrandt -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
From a1e88ac0b2fa8b2a10a730b86ce3da85104ab0f7 Mon Sep 17 00:00:00 2001 From: Christian Brabandt <[email protected]> Date: Wed, 1 Nov 2017 17:01:21 +0100 Subject: [PATCH] Some small fixes for incsearch feature --- runtime/doc/options.txt | 4 +- src/ex_getln.c | 10 +++- src/testdir/test_search.vim | 119 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 127 insertions(+), 6 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 0a07cc257..b006dc61a 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4515,8 +4515,8 @@ A jump table for the options with a short description can be found at |Q_op|. Example: > augroup vimrc-incsearch-highlight autocmd! - autocmd CmdlineEnter [/\?] :set hlsearch - autocmd CmdlineLeave [/\?] :set nohlsearch + autocmd CmdlineEnter /,\? :set hlsearch + autocmd CmdlineLeave /,\? :set nohlsearch augroup END < CTRL-L can be used to add one character from after the current match diff --git a/src/ex_getln.c b/src/ex_getln.c index 717a01224..027047728 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -1717,12 +1717,19 @@ getcmdline( pos_T t; int search_flags = SEARCH_NOOF; + if (ccline.cmdlen == 0) + goto cmdline_not_changed; + save_last_search_pattern(); cursor_off(); out_flush(); if (c == Ctrl_G) { t = match_end; + if (LT_POS(match_start, match_end)) + /* start searching at the end of the match + * not at the beginning of the next column */ + (void)decl(&t); search_flags += SEARCH_COL; } else @@ -1945,6 +1952,7 @@ cmdline_changed: { i = 0; SET_NO_HLSEARCH(TRUE); /* turn off previous highlight */ + redraw_all_later(SOME_VALID); } else { @@ -2082,7 +2090,7 @@ returncmd: curwin->w_botline = old_botline; highlight_match = FALSE; validate_cursor(); /* needed for TAB */ - redraw_later(SOME_VALID); + redraw_all_later(SOME_VALID); } #endif diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index b863fcbba..ab599fe4d 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -397,6 +397,117 @@ func Test_search_cmdline5() bw! endfunc +func Test_search_cmdline6() + " Test that consecutive matches + " are caught by <c-g>/<c-t> + 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, [' bbvimb', '']) + set incsearch + " first match + norm! gg0 + call feedkeys("/b\<cr>", 'tx') + call assert_equal([0,1,2,0], getpos('.')) + " second match + norm! gg0 + call feedkeys("/b\<c-g>\<cr>", 'tx') + call assert_equal([0,1,3,0], getpos('.')) + " third match + norm! gg0 + call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal([0,1,7,0], getpos('.')) + " first match again + norm! gg0 + call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal([0,1,2,0], getpos('.')) + set nowrapscan + " last match + norm! gg0 + call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal([0,1,7,0], getpos('.')) + " clean up + set wrapscan&vim + set noincsearch + call test_override("char_avail", 0) + bw! +endfunc + +func Test_search_cmdline7() + " 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('.')) + set noincsearch + call test_override("char_avail", 0) + bw! +endfunc + +func Test_search_cmdline8() + " Highlighting is cleared in all windows + " since hls applies to all windows + if !exists('+incsearch') || !has('terminal') || has('gui_running') || winwidth(0) < 30 + return + endif + if has("win32") + throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet" + endif + let h = winheight(0) + if h < 3 + return + endif + " Prepare buffer text + let lines = ['abb vim vim vi', 'vimvivim'] + call writefile(lines, 'Xsearch.txt') + let g:buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) + + call term_wait(g:buf, 200) + call assert_equal(lines[0], term_getline(g:buf, 1)) + call assert_equal(lines[1], term_getline(g:buf, 2)) + + call term_sendkeys(g:buf, ":set incsearch hlsearch\<cr>") + call term_sendkeys(g:buf, ":14vsp\<cr>") + call term_sendkeys(g:buf, "/vim\<cr>") + call term_sendkeys(g:buf, "/b\<esc>") + call term_sendkeys(g:buf, "gg0") + call term_wait(g:buf, 500) + let screen_line = term_scrape(g:buf, 1) + let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, + \ screen_line[18].attr, screen_line[19].attr] + call assert_notequal(a0, a1) + call assert_notequal(a0, a3) + call assert_notequal(a1, a2) + call assert_equal(a0, a2) + call assert_equal(a1, a3) + " clean up + call delete('Xsearch.txt') + + bwipe! +endfunc + " Tests for regexp with various magic settings func Test_search_regexp() enew! @@ -494,13 +605,14 @@ func Test_search_cmdline_incsearch_highlight_attr() if h < 3 return endif - let g:buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3}) - " Prepare buffer text let lines = ['abb vim vim vi', 'vimvivim'] - call term_sendkeys(g:buf, 'i' . join(lines, "\n") . "\<esc>gg0") + call writefile(lines, 'Xsearch.txt') + let g:buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) + call term_wait(g:buf, 200) call assert_equal(lines[0], term_getline(g:buf, 1)) + call assert_equal(lines[1], term_getline(g:buf, 2)) " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight call term_sendkeys(g:buf, ":set incsearch hlsearch\<cr>") @@ -564,6 +676,7 @@ func Test_search_cmdline_incsearch_highlight_attr() let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) + call delete('Xsearch.txt') bwipe! endfunc -- 2.14.1
