From 7973b1aecddf1058da65fcf2b6d9ba02a3dff009 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 7 Oct 2017 10:25:59 +0000 Subject: [PATCH 1/8] Implement incremental highlight search feature By removing SEARCH_KEEP flag, command line text is stored as last regexp pattern and used for 'hlsearch' feture while incremental searching. Add 'inchlsearch' ("inc"remental "hlsearch") option to turn on/off this feature. This patch is based on itchyny's patch[1]. itchyny's patch didn't handle cancelling incremental search by or and command line text is stored as last pattern even if users cancell the search. This patch fix this problem by store/restore the search pattern. [1]: https://groups.google.com/forum/#!searchin/vim_dev/incsearch|sort:relevance/vim_dev/zdp8W-6xUzg/PrqDpP7cilIJ --- runtime/doc/options.txt | 15 +++++++++++-- runtime/doc/quickref.txt | 1 + runtime/optwin.vim | 2 ++ src/ex_getln.c | 17 ++++++++++++--- src/option.c | 3 +++ src/option.h | 1 + src/proto/search.pro | 2 ++ src/search.c | 43 +++++++++++++++++++++++++++++++++---- src/testdir/test_search.vim | 33 ++++++++++++++++++++++++++++ 9 files changed, 108 insertions(+), 9 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index ebe9c926209741..8cfb964c8da9dc 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4175,7 +4175,7 @@ A jump table for the options with a short description can be found at |Q_op|. 'highlight' option. This uses the "Search" highlight group by default. Note that only the matching text is highlighted, any offsets are not applied. - See also: 'incsearch' and |:match|. + See also: 'incsearch', 'inchlsearch' and |:match|. When you get bored looking at the highlighted matches, you can turn it off with |:nohlsearch|. This does not change the option value, as soon as you use a search command, the highlighting comes back. @@ -4386,6 +4386,17 @@ A jump table for the options with a short description can be found at |Q_op|. default now. This should work fine for most people, however if you have any problem with it, try using on-the-spot style. + *'inchlsearch'* *'ihls'* *'noinchlsearch'* *'noihls'* +'inchlsearch' 'ihls' boolean (default off) + global + {not in Vi} + {not available when compiled without the + |+extra_search| features} + While typing a search command, all matched strings are highlighted. + It works only when both 'incsearch' and 'hlsearch' are on. The type of + highlighting is same as highlight of 'hlsearch' and same as highlight + of 'incsearch' for the current match. + *'include'* *'inc'* 'include' 'inc' string (default "^\s*#\s*include") global or local to buffer |global-local| @@ -4447,7 +4458,7 @@ A jump table for the options with a short description can be found at |Q_op|. match may not be found. This is to avoid that Vim hangs while you are typing the pattern. The highlighting can be set with the 'i' flag in 'highlight'. - See also: 'hlsearch'. + See also: 'hlsearch' and 'inchlsearch'. CTRL-L can be used to add one character from after the current match to the command line. If 'ignorecase' and 'smartcase' are set and the command line has no uppercase characters, the added character is diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index c4d67907e3e04a..3a3da90d35bc99 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -750,6 +750,7 @@ Short explanation of each option: *option-list* 'imsearch' 'ims' use :lmap or IM when typing a search pattern 'imstatusfunc' 'imsf' function to obtain X input method status 'imstyle' 'imst' specifies the input style of the input method +'inchlsearch' 'ihls' highlight all matches while typing search pattern 'include' 'inc' pattern to be used to find an include file 'includeexpr' 'inex' expression used to process an include line 'incsearch' 'is' highlight match while typing search pattern diff --git a/runtime/optwin.vim b/runtime/optwin.vim index ac7000630ffaf5..3f622348d9e708 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -409,6 +409,8 @@ call append("$", "highlight\twhich highlighting to use for various occasions") call OptionG("hl", &hl) call append("$", "hlsearch\thighlight all matches for the last used search pattern") call BinOptionG("hls", &hls) +call append("$", "inchlsearch\thighlight all matches while typing search pattern") +call BinOptionG("ihls", &ihls) if has("termguicolors") call append("$", "termguicolors\tuse GUI colors for the terminal") call BinOptionG("tgc", &tgc) diff --git a/src/ex_getln.c b/src/ex_getln.c index 9f7dad99aa5ea7..578a7c5fd70fc0 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -1680,11 +1680,11 @@ getcmdline( if (p_is && !cmd_silent && (firstc == '/' || firstc == '?')) { pos_T t; - int search_flags = SEARCH_KEEP + SEARCH_NOOF - + SEARCH_PEEK; + int search_flags = SEARCH_NOOF + SEARCH_PEEK; if (char_avail()) continue; + save_last_search_pattern(); cursor_off(); out_flush(); if (c == Ctrl_G) @@ -1694,6 +1694,8 @@ getcmdline( } else t = match_start; + if (!p_ihls) + search_flags += SEARCH_KEEP; ++emsg_off; i = searchit(curwin, curbuf, &t, c == Ctrl_G ? FORWARD : BACKWARD, @@ -1745,6 +1747,7 @@ getcmdline( # endif old_botline = curwin->w_botline; update_screen(NOT_VALID); + restore_last_search_pattern(); redrawcmdline(); } else @@ -1902,12 +1905,17 @@ getcmdline( } incsearch_postponed = FALSE; curwin->w_cursor = search_start; /* start at old position */ + save_last_search_pattern(); /* If there is no command line, don't do anything */ if (ccline.cmdlen == 0) + { i = 0; + SET_NO_HLSEARCH(TRUE); /* Turn off previous highlight */ + } else { + int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; cursor_off(); /* so the user knows we're busy */ out_flush(); ++emsg_off; /* So it doesn't beep if bad expr */ @@ -1915,8 +1923,10 @@ getcmdline( /* Set the time limit to half a second. */ profile_setlimit(500L, &tm); #endif + if (!p_ihls) + search_flags += SEARCH_KEEP; i = do_search(NULL, firstc, ccline.cmdbuff, count, - SEARCH_KEEP + SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK, + search_flags, #ifdef FEAT_RELTIME &tm, NULL #else @@ -1973,6 +1983,7 @@ getcmdline( save_cmdline(&save_ccline); update_screen(SOME_VALID); restore_cmdline(&save_ccline); + restore_last_search_pattern(); /* Leave it at the end to make CTRL-R CTRL-W work. */ if (i != 0) diff --git a/src/option.c b/src/option.c index 2743f16071b027..2fd6a6089e02e1 100644 --- a/src/option.c +++ b/src/option.c @@ -1611,6 +1611,9 @@ static struct vimoption options[] = {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM, (char_u *)&p_is, PV_NONE, {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, + {"inchlsearch", "ihls", P_BOOL|P_VI_DEF|P_VIM, + (char_u *)&p_ihls, PV_NONE, + {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM, #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) (char_u *)&p_inde, PV_INDE, diff --git a/src/option.h b/src/option.h index 88eadae4c81fc4..3f361cb203991a 100644 --- a/src/option.h +++ b/src/option.h @@ -586,6 +586,7 @@ EXTERN int p_imcmdline; /* 'imcmdline' */ EXTERN int p_imdisable; /* 'imdisable' */ #endif EXTERN int p_is; /* 'incsearch' */ +EXTERN int p_ihls; /* 'inchlsearch' */ EXTERN int p_im; /* 'insertmode' */ EXTERN char_u *p_isf; /* 'isfname' */ EXTERN char_u *p_isi; /* 'isident' */ diff --git a/src/proto/search.pro b/src/proto/search.pro index 63955adee0d385..41c200612f0443 100644 --- a/src/proto/search.pro +++ b/src/proto/search.pro @@ -5,6 +5,8 @@ char_u *reverse_text(char_u *s); void save_re_pat(int idx, char_u *pat, int magic); void save_search_patterns(void); void restore_search_patterns(void); +void save_last_search_pattern(void); +void restore_last_search_pattern(void); void free_search_patterns(void); int ignorecase(char_u *pat); int ignorecase_opt(char_u *pat, int ic_in, int scs); diff --git a/src/search.c b/src/search.c index c3c5503095e45b..5d4d6e2b8f4a01 100644 --- a/src/search.c +++ b/src/search.c @@ -100,11 +100,14 @@ static int lastc_bytelen = 1; /* >1 for multi-byte char */ #if defined(FEAT_AUTOCMD) || defined(FEAT_EVAL) || defined(PROTO) /* copy of spats[], for keeping the search patterns while executing autocmds */ static struct spat saved_spats[2]; -static int saved_last_idx = 0; +#endif # ifdef FEAT_SEARCH_EXTRA +/* copy of spats[RE_SEARCH], for keeping the search patterns while incremental + * searching */ +static struct spat saved_last_search_spat; +static int saved_last_idx = 0; static int saved_no_hlsearch = 0; # endif -#endif static char_u *mr_pattern = NULL; /* pattern used by search_regcomp() */ #ifdef FEAT_RIGHTLEFT @@ -329,9 +332,9 @@ restore_search_patterns(void) { vim_free(spats[0].pat); spats[0] = saved_spats[0]; -#if defined(FEAT_EVAL) +# if defined(FEAT_EVAL) set_vv_searchforward(); -#endif +# endif vim_free(spats[1].pat); spats[1] = saved_spats[1]; last_idx = saved_last_idx; @@ -360,6 +363,38 @@ free_search_patterns(void) } #endif +#ifdef FEAT_SEARCH_EXTRA +/* + * Save and restore the search pattern for incremental highlight search + * feature ('inchlsearch'). + * + * It's similar but differnt from save_search_patterns() and + * restore_search_patterns(), because the search pattern must be restored when + * cannceling incremental searching even if it's called inside user functions. + */ + void +save_last_search_pattern(void) +{ + saved_last_search_spat = spats[RE_SEARCH]; + if (spats[RE_SEARCH].pat != NULL) + saved_last_search_spat.pat = vim_strsave(spats[RE_SEARCH].pat); + saved_last_idx = last_idx; + saved_no_hlsearch = no_hlsearch; +} + + void +restore_last_search_pattern(void) +{ + vim_free(spats[RE_SEARCH].pat); + spats[RE_SEARCH] = saved_last_search_spat; +# if defined(FEAT_EVAL) + set_vv_searchforward(); +# endif + last_idx = saved_last_idx; + SET_NO_HLSEARCH(saved_no_hlsearch); +} +#endif + /* * Return TRUE when case should be ignored for search pattern "pat". * Uses the 'ignorecase' and 'smartcase' options. diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index 5ae101f1ecd295..433567dfe2ceaf 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -412,3 +412,36 @@ func Test_search_regexp() set undolevels& enew! endfunc + +func Test_search_cmdline_inchlsearch() + if !exists('+inchlsearch') + return + endif + set incsearch hlsearch inchlsearch + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third']) + + 1 + call feedkeys("/second\", 'tx') + call assert_equal('second', @/) + call assert_equal(' 2 the second', getline('.')) + + " Canceling search won't change @/ + 1 + let @/ = 'last pattern' + call feedkeys("/third\", 'tx') + call assert_equal('last pattern', @/) + call feedkeys("/third\", 'tx') + call assert_equal('last pattern', @/) + call feedkeys("/3\\", 'tx') + call assert_equal('last pattern', @/) + call feedkeys("/third\\\", 'tx') + call assert_equal('last pattern', @/) + + " clean up + set noincsearch nohlsearch noinchlsearch + bw! +endfunc From a552edd17e8601c124d4e7d20179384d52bfad22 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 14 Oct 2017 19:08:13 +0900 Subject: [PATCH 2/8] add test for incremental hlsearch --- src/testdir/test_search.vim | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index 433567dfe2ceaf..a42a5121d057b7 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -1,5 +1,7 @@ " Test for the search command +source shared.vim + set belloff=all func Test_search_cmdline() if !exists('+incsearch') @@ -445,3 +447,57 @@ func Test_search_cmdline_inchlsearch() set noincsearch nohlsearch noinchlsearch bw! endfunc + +func Test_search_cmdline_inchlsearch_highlight() + if !exists('+inchlsearch') || !has('terminal') || has('gui_running') + return + endif + let h = winheight(0) + 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") . "\gg0") + call term_wait(g:buf, 200) + call assert_equal(lines[0], term_getline(g:buf, 1)) + + " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight + call term_sendkeys(g:buf, ":set incsearch hlsearch inchlsearch\") + call term_sendkeys(g:buf, '/b') + call term_wait(g:buf, 200) + let screen_line1 = term_scrape(g:buf, 1) + call assert_true(len(screen_line1) > 2) + " a0: attr_normal + let a0 = screen_line1[0].attr + " a1: attr_incsearch + let a1 = screen_line1[1].attr + " a2: attr_hlsearch + let a2 = screen_line1[2].attr + call assert_notequal(a0, a1) + call assert_notequal(a0, a2) + call assert_notequal(a1, a2) + call term_sendkeys(g:buf, "\gg0") + + " Test incremental highlight search + call term_sendkeys(g:buf, "/vim") + call term_wait(g:buf, 200) + " Buffer: + " abb vim vim vi + " vimvivim + " Search: /vim + let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] + 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')) + " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) + call term_sendkeys(g:buf, "\") + call term_wait(g:buf, 200) + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] + 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')) + bwipe! +endfunc From af93dc6405538b83da5649d559dbd5ac50378e51 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 14 Oct 2017 20:12:37 +0900 Subject: [PATCH 3/8] re-run CI Asan failed unexpectedly https://travis-ci.org/vim/vim/jobs/287883356 Error: https://gist.github.com/haya14busa/ff1e09dbe8d21f7bc6731cdd37fe2d81 I confirme the test passed with the same code on my forked repository https://travis-ci.org/haya14busa/vim, so try it again. From d6d5aa23537c1f31181a53a36d64f41887fdb8c0 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 20 Oct 2017 12:43:04 +0900 Subject: [PATCH 4/8] Remove 'inchlsearch' option --- runtime/doc/options.txt | 16 +++------------- runtime/doc/quickref.txt | 1 - runtime/optwin.vim | 2 -- src/ex_getln.c | 4 ++-- src/option.c | 3 --- src/option.h | 1 - src/search.c | 2 +- src/testdir/test_search.vim | 14 +++++++------- 8 files changed, 13 insertions(+), 30 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 8cfb964c8da9dc..16dba291cde987 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4175,7 +4175,7 @@ A jump table for the options with a short description can be found at |Q_op|. 'highlight' option. This uses the "Search" highlight group by default. Note that only the matching text is highlighted, any offsets are not applied. - See also: 'incsearch', 'inchlsearch' and |:match|. + See also: 'incsearch' and |:match|. When you get bored looking at the highlighted matches, you can turn it off with |:nohlsearch|. This does not change the option value, as soon as you use a search command, the highlighting comes back. @@ -4386,17 +4386,6 @@ A jump table for the options with a short description can be found at |Q_op|. default now. This should work fine for most people, however if you have any problem with it, try using on-the-spot style. - *'inchlsearch'* *'ihls'* *'noinchlsearch'* *'noihls'* -'inchlsearch' 'ihls' boolean (default off) - global - {not in Vi} - {not available when compiled without the - |+extra_search| features} - While typing a search command, all matched strings are highlighted. - It works only when both 'incsearch' and 'hlsearch' are on. The type of - highlighting is same as highlight of 'hlsearch' and same as highlight - of 'incsearch' for the current match. - *'include'* *'inc'* 'include' 'inc' string (default "^\s*#\s*include") global or local to buffer |global-local| @@ -4458,7 +4447,8 @@ A jump table for the options with a short description can be found at |Q_op|. match may not be found. This is to avoid that Vim hangs while you are typing the pattern. The highlighting can be set with the 'i' flag in 'highlight'. - See also: 'hlsearch' and 'inchlsearch'. + When 'hlsearch' is on, all matched strings are highlighted too while typing + a search command. See also: 'hlsearch'. CTRL-L can be used to add one character from after the current match to the command line. If 'ignorecase' and 'smartcase' are set and the command line has no uppercase characters, the added character is diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index 3a3da90d35bc99..c4d67907e3e04a 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -750,7 +750,6 @@ Short explanation of each option: *option-list* 'imsearch' 'ims' use :lmap or IM when typing a search pattern 'imstatusfunc' 'imsf' function to obtain X input method status 'imstyle' 'imst' specifies the input style of the input method -'inchlsearch' 'ihls' highlight all matches while typing search pattern 'include' 'inc' pattern to be used to find an include file 'includeexpr' 'inex' expression used to process an include line 'incsearch' 'is' highlight match while typing search pattern diff --git a/runtime/optwin.vim b/runtime/optwin.vim index 3f622348d9e708..ac7000630ffaf5 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -409,8 +409,6 @@ call append("$", "highlight\twhich highlighting to use for various occasions") call OptionG("hl", &hl) call append("$", "hlsearch\thighlight all matches for the last used search pattern") call BinOptionG("hls", &hls) -call append("$", "inchlsearch\thighlight all matches while typing search pattern") -call BinOptionG("ihls", &ihls) if has("termguicolors") call append("$", "termguicolors\tuse GUI colors for the terminal") call BinOptionG("tgc", &tgc) diff --git a/src/ex_getln.c b/src/ex_getln.c index 578a7c5fd70fc0..31eb8c22ea6126 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -1694,7 +1694,7 @@ getcmdline( } else t = match_start; - if (!p_ihls) + if (!p_hls) search_flags += SEARCH_KEEP; ++emsg_off; i = searchit(curwin, curbuf, &t, @@ -1923,7 +1923,7 @@ getcmdline( /* Set the time limit to half a second. */ profile_setlimit(500L, &tm); #endif - if (!p_ihls) + if (!p_hls) search_flags += SEARCH_KEEP; i = do_search(NULL, firstc, ccline.cmdbuff, count, search_flags, diff --git a/src/option.c b/src/option.c index 788f3bc0b6312a..baa8d855c6a18f 100644 --- a/src/option.c +++ b/src/option.c @@ -1611,9 +1611,6 @@ static struct vimoption options[] = {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM, (char_u *)&p_is, PV_NONE, {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, - {"inchlsearch", "ihls", P_BOOL|P_VI_DEF|P_VIM, - (char_u *)&p_ihls, PV_NONE, - {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM, #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) (char_u *)&p_inde, PV_INDE, diff --git a/src/option.h b/src/option.h index 3f361cb203991a..88eadae4c81fc4 100644 --- a/src/option.h +++ b/src/option.h @@ -586,7 +586,6 @@ EXTERN int p_imcmdline; /* 'imcmdline' */ EXTERN int p_imdisable; /* 'imdisable' */ #endif EXTERN int p_is; /* 'incsearch' */ -EXTERN int p_ihls; /* 'inchlsearch' */ EXTERN int p_im; /* 'insertmode' */ EXTERN char_u *p_isf; /* 'isfname' */ EXTERN char_u *p_isi; /* 'isident' */ diff --git a/src/search.c b/src/search.c index 5d4d6e2b8f4a01..e56cb1b41c31b0 100644 --- a/src/search.c +++ b/src/search.c @@ -366,7 +366,7 @@ free_search_patterns(void) #ifdef FEAT_SEARCH_EXTRA /* * Save and restore the search pattern for incremental highlight search - * feature ('inchlsearch'). + * feature. * * It's similar but differnt from save_search_patterns() and * restore_search_patterns(), because the search pattern must be restored when diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index d0f66fbe934644..d88d25d7f86bac 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -414,11 +414,11 @@ func Test_search_regexp() enew! endfunc -func Test_search_cmdline_inchlsearch() - if !exists('+inchlsearch') +func Test_search_cmdline_incsearch_highlight() + if !exists('+incsearch') return endif - set incsearch hlsearch inchlsearch + set incsearch hlsearch " need to disable char_avail, " so that expansion of commandline works call test_override("char_avail", 1) @@ -443,12 +443,12 @@ func Test_search_cmdline_inchlsearch() call assert_equal('last pattern', @/) " clean up - set noincsearch nohlsearch noinchlsearch + set noincsearch nohlsearch bw! endfunc -func Test_search_cmdline_inchlsearch_highlight() - if !exists('+inchlsearch') || !has('terminal') || has('gui_running') +func Test_search_cmdline_incsearch_highlight_attr() + if !exists('+incsearch') || !has('terminal') || has('gui_running') return endif let h = winheight(0) @@ -464,7 +464,7 @@ func Test_search_cmdline_inchlsearch_highlight() call assert_equal(lines[0], term_getline(g:buf, 1)) " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight - call term_sendkeys(g:buf, ":set incsearch hlsearch inchlsearch\") + call term_sendkeys(g:buf, ":set incsearch hlsearch\") call term_sendkeys(g:buf, '/b') call term_wait(g:buf, 200) let screen_line1 = term_scrape(g:buf, 1) From 147d165a7c03d3a942f068f4eceea5feb1229f23 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 20 Oct 2017 12:55:46 +0900 Subject: [PATCH 5/8] add example configuration --- runtime/doc/options.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 16dba291cde987..36ca87c992ac9c 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4449,6 +4449,15 @@ A jump table for the options with a short description can be found at |Q_op|. The highlighting can be set with the 'i' flag in 'highlight'. When 'hlsearch' is on, all matched strings are highlighted too while typing a search command. See also: 'hlsearch'. + If you don't want turn 'hlsearch' on, but want to highlight all matches + while searching, you can turn on and off 'hlsearch' with autocmd. + Example: > + augroup vimrc-incsearch-highlight + autocmd! + autocmd CmdlineEnter * :if expand('') == '/' | set hlsearch | endif + autocmd CmdlineLeave * :if expand('') == '/' | set nohlsearch | endif + augroup END +< CTRL-L can be used to add one character from after the current match to the command line. If 'ignorecase' and 'smartcase' are set and the command line has no uppercase characters, the added character is From 8bc7dccdba76f4a2e7c9ad53f6d7974522073d2f Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 20 Oct 2017 13:11:01 +0900 Subject: [PATCH 6/8] add test --- src/testdir/test_search.vim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index d88d25d7f86bac..2c4405541b3e72 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -498,5 +498,16 @@ func Test_search_cmdline_incsearch_highlight_attr() let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] 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')) + + " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) + call term_sendkeys(g:buf, ":1\") + call term_sendkeys(g:buf, ":set nohlsearch\") + call term_sendkeys(g:buf, "/vim") + call term_wait(g:buf, 200) + let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] + 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')) + bwipe! endfunc From 3b948feb7dbb76355cc712945de24c7d00340fb6 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 21 Oct 2017 21:33:00 +0000 Subject: [PATCH 7/8] Update autocmd --- runtime/doc/options.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 36ca87c992ac9c..181aa94b2dbc32 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4454,8 +4454,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 * :if expand('') == '/' | set hlsearch | endif - autocmd CmdlineLeave * :if expand('') == '/' | set nohlsearch | endif + autocmd CmdlineEnter [/\?] :set hlsearch + autocmd CmdlineLeave [/\?] :set nohlsearch augroup END < CTRL-L can be used to add one character from after the current match From ad1e575d615ea9e3965c4ad1086f4e2dcf5bd3ab Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 28 Oct 2017 14:08:30 +0000 Subject: [PATCH 8/8] add incremental highlight tests for / --- src/testdir/test_search.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index 19e0efbe97f11d..eb781106a909c4 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -511,6 +511,23 @@ func Test_search_cmdline_incsearch_highlight_attr() let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] 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')) + + " Test + call term_sendkeys(g:buf, "\\") + call term_wait(g:buf, 200) + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] + let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] + 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')) + + " Test + call term_sendkeys(g:buf, "\") + call term_wait(g:buf, 200) + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] + 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')) + " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) call term_sendkeys(g:buf, "\") call term_wait(g:buf, 200)