[vim/vim] Highlight all matched text while incremental searching (#2198)

804 views
Skip to first unread message

haya14busa

unread,
Oct 8, 2017, 11:24:09 PM10/8/17
to vim/vim, Subscribed

inchlsearch-demo

This patch supports highlighting all matched text while incremental searching.

By removing SEARCH_KEEP flag, command line text is stored as last regexp
pattern and used for 'hlsearch' feture while incremental searching.

This patch is based on @itchyny's patch1. itchyny's patch didn't handle
cancelling incremental search by <Esc> or <C-c> 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.

Also, I added 'inchlsearch' ("inc"remental "hlsearch") option to turn on/off this feature.

I'm the author of https://github.com/haya14busa/incsearch.vim which provide
similar functionality.
Actually, I'm satisfied with this plugin but I believe this feature is so
useful that it should be implemented with default vim :)


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/2198

Commit Summary

  • Implement incremental highlight search feature
  • improve patch
  • add test and fix impl for ctrl-g/t handling and called from user functions
  • up
  • fix
  • improve test
  • move variable declaration
  • move 'saved_last_search_spat' declaration
  • fix if def
  • rm testok
  • fix style, if-def and update runtime files
  • fix style

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Yegappan Lakshmanan

unread,
Oct 9, 2017, 12:05:11 AM10/9/17
to vim_dev, reply+00b1d198983056f7e88a7803e098182a6866c87...@reply.github.com, vim/vim, Subscribed
Hi,

This is great. I have been looking for this feature for a long time.

Regards,
Yegappan

vim-dev ML

unread,
Oct 9, 2017, 12:05:32 AM10/9/17
to vim/vim, vim-dev ML, Your activity
Hi,

This is great. I have been looking for this feature for a long time.

Regards,
Yegappan

On Sun, Oct 8, 2017 at 8:24 PM, haya14busa <vim-dev...@256bit.org>
wrote:

> This patch supports highlighting all matched text while incremental
> searching.
>
> By removing SEARCH_KEEP flag, command line text is stored as last regexp
> pattern and used for 'hlsearch' feture while incremental searching.
>
> This patch is based on @itchyny <https://github.com/itchyny>'s patch1
> <https://groups.google.com/forum/#!searchin/vim_dev/incsearch%7Csort:relevance/vim_dev/zdp8W-6xUzg/PrqDpP7cilIJ>.

> itchyny's patch didn't handle
> cancelling incremental search by <Esc> or <C-c> 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.
>
> Also, I added 'inchlsearch' ("inc"remental "hlsearch") option to turn
> on/off this feature.
>
> I'm the author of https://github.com/haya14busa/incsearch.vim which
> provide
> similar functionality.
> Actually, I'm satisfied with this plugin but I believe this feature is so
> useful that it should be implemented with default vim :)
> ------------------------------

> You can view, comment on, or merge this pull request online at:
>
> https://github.com/vim/vim/pull/2198
> Commit Summary
>
> - Implement incremental highlight search feature
> - improve patch
> - add test and fix impl for ctrl-g/t handling and called from user
> functions
> - up
> - fix
> - improve test
> - move variable declaration
> - move 'saved_last_search_spat' declaration
> - fix if def
> - rm testok
> - fix style, if-def and update runtime files
> - fix style
>
> File Changes
>
> - *M* runtime/doc/options.txt
> <https://github.com/vim/vim/pull/2198/files#diff-0> (15)
> - *M* runtime/doc/quickref.txt
> <https://github.com/vim/vim/pull/2198/files#diff-1> (1)
> - *M* runtime/optwin.vim
> <https://github.com/vim/vim/pull/2198/files#diff-2> (2)
> - *M* src/ex_getln.c
> <https://github.com/vim/vim/pull/2198/files#diff-3> (17)
> - *M* src/option.c <https://github.com/vim/vim/pull/2198/files#diff-4>
> (3)
> - *M* src/option.h <https://github.com/vim/vim/pull/2198/files#diff-5>
> (1)
> - *M* src/proto/search.pro
> <https://github.com/vim/vim/pull/2198/files#diff-6> (2)
> - *M* src/search.c <https://github.com/vim/vim/pull/2198/files#diff-7>
> (43)
> - *M* src/testdir/test_search.vim
> <https://github.com/vim/vim/pull/2198/files#diff-8> (33)
>
> Patch Links:
>
> - https://github.com/vim/vim/pull/2198.patch
> - https://github.com/vim/vim/pull/2198.diff

Yegappan Lakshmanan

unread,
Oct 9, 2017, 12:26:23 AM10/9/17
to vim_dev, reply+00b1d198983056f7e88a7803e098182a6866c87...@reply.github.com, vim/vim, Subscribed
Hi,

On Sun, Oct 8, 2017 at 9:05 PM, Yegappan Lakshmanan <yega...@gmail.com> wrote:
> Hi,
>
> This is great. I have been looking for this feature for a long time.
>

We should also add the live substitution feature (neovim's inccommand feature).

vim-dev ML

unread,
Oct 9, 2017, 12:26:41 AM10/9/17
to vim/vim, vim-dev ML, Your activity
Hi,

On Sun, Oct 8, 2017 at 9:05 PM, Yegappan Lakshmanan <yega...@gmail.com> wrote:
> Hi,
>
> This is great. I have been looking for this feature for a long time.
>

We should also add the live substitution feature (neovim's inccommand feature).

Regards,
Yegappan

>
> On Sun, Oct 8, 2017 at 8:24 PM, haya14busa <vim-dev...@256bit.org>
> wrote:
>>

Yegappan Lakshmanan

unread,
Oct 9, 2017, 12:47:32 AM10/9/17
to vim_dev, reply+00b1d198983056f7e88a7803e098182a6866c87...@reply.github.com
Hi,

On Sun, Oct 8, 2017 at 9:05 PM, Yegappan Lakshmanan <yega...@gmail.com> wrote:
> Hi,
>
> This is great. I have been looking for this feature for a long time.
>

I tested this feature for some time and it worked correctly. I don't use
'hlsearch' as it is distracting. Is it possible to make this feature work
independent of 'hlsearch'?

Thanks,

vim-dev ML

unread,
Oct 9, 2017, 12:47:52 AM10/9/17
to vim/vim, vim-dev ML, Your activity
Hi,

On Sun, Oct 8, 2017 at 9:05 PM, Yegappan Lakshmanan <yega...@gmail.com> wrote:
> Hi,
>
> This is great. I have been looking for this feature for a long time.
>

I tested this feature for some time and it worked correctly. I don't use
'hlsearch' as it is distracting. Is it possible to make this feature work
independent of 'hlsearch'?

Thanks,
Yegappan

>
> On Sun, Oct 8, 2017 at 8:24 PM, haya14busa <vim-dev...@256bit.org>
> wrote:
>>

h_east

unread,
Oct 9, 2017, 7:14:30 AM10/9/17
to vim_dev
Hi haya14busa and list,

Good patch👍
If you only modify highlight I think that you do not need to add 'inchlsearch' option.
When 'incsearch' is set, I think that it is possible to do that feature in search-commands.
Of course, regardless of 'hlsearch'.

--Best regards,
Hirohito Higashi (h_east)

haya14busa

unread,
Oct 11, 2017, 2:32:42 AM10/11/17
to vim/vim, vim-dev ML, Comment

We can enable this feature without new 'inchlsearch' option and regardless 'hlsearch' with following patch.

But, I wonder is it really ok to make it default behavior. IncSearch and Search highlight is similar in some colorscheme and when you type ., all characters will be highlighted.
I thought someone may feel it's annoying behavior.

What do you think?

diff --git a/src/ex_getln.c b/src/ex_getln.c
index 578a7c5fd..adc226fbf 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -1681,10 +1681,12 @@ getcmdline(
 		{
 		    pos_T  t;
 		    int    search_flags = SEARCH_NOOF + SEARCH_PEEK;
+		    int    save_p_hls = p_hls;
 
 		    if (char_avail())
 			continue;
 		    save_last_search_pattern();
+		    p_hls = TRUE;
 		    cursor_off();
 		    out_flush();
 		    if (c == Ctrl_G)
@@ -1694,8 +1696,6 @@ getcmdline(
 		    }
 		    else
 			t = match_start;
-		    if (!p_ihls)
-			search_flags += SEARCH_KEEP;
 		    ++emsg_off;
 		    i = searchit(curwin, curbuf, &t,
 				 c == Ctrl_G ? FORWARD : BACKWARD,
@@ -1748,6 +1748,7 @@ getcmdline(
 			old_botline = curwin->w_botline;
 			update_screen(NOT_VALID);
 			restore_last_search_pattern();
+			p_hls = save_p_hls;
 			redrawcmdline();
 		    }
 		    else
@@ -1896,6 +1897,7 @@ cmdline_changed:
 #ifdef FEAT_RELTIME
 	    proftime_T	tm;
 #endif
+	    int save_p_hls = p_hls;
 
 	    /* if there is a character waiting, search and redraw later */
 	    if (char_avail())
@@ -1906,6 +1908,7 @@ cmdline_changed:
 	    incsearch_postponed = FALSE;
 	    curwin->w_cursor = search_start;  /* start at old position */
 	    save_last_search_pattern();
+	    p_hls = TRUE;
 
 	    /* If there is no command line, don't do anything */
 	    if (ccline.cmdlen == 0)
@@ -1923,8 +1926,6 @@ cmdline_changed:
 		/* 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_flags,
 #ifdef FEAT_RELTIME
@@ -1984,6 +1985,7 @@ cmdline_changed:
 	    update_screen(SOME_VALID);
 	    restore_cmdline(&save_ccline);
 	    restore_last_search_pattern();
+	    p_hls = save_p_hls;
 
 	    /* Leave it at the end to make CTRL-R CTRL-W work. */
 	    if (i != 0)


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Oct 11, 2017, 3:19:42 AM10/11/17
to vim_dev, reply+00b1d198a2ea9c1412cd772123221420cdb69c5...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi,

On Tue, Oct 10, 2017 at 11:32 PM, haya14busa <vim-dev...@256bit.org> wrote:
> We can enable this feature without new 'inchlsearch' option and regardless
> 'hlsearch' with following patch.
>

I tested the below patch and it seems to work correctly.

>
> But, I wonder is it really ok to make it default behavior. IncSearch and
> Search highlight is similar in some colorscheme and when you type ., all
> characters will be highlighted.
> I thought someone may feel it's annoying behavior.
>

I agree. Enabling this behavior by default may surprise some existing
Vim users. Adding an option to control this behavior might be the way
to go (except that this will introduce one more option). New Vim users
may benefit from this feature if it is enabled by default.

Regards,
Yegappan

vim-dev ML

unread,
Oct 11, 2017, 3:20:06 AM10/11/17
to vim/vim, vim-dev ML, Your activity

Christian Brabandt

unread,
Oct 11, 2017, 4:42:05 PM10/11/17
to vim/vim, vim-dev ML, Comment

did you check the build failure?


You are receiving this because you commented.

K.Takata

unread,
Oct 11, 2017, 7:13:30 PM10/11/17
to vim/vim, vim-dev ML, Comment

I don't think it is related to this PR, because the master branch also failed with the same error.
Not sure why lua fails.


You are receiving this because you commented.

haya14busa

unread,
Oct 12, 2017, 10:46:38 AM10/12/17
to vim/vim, vim-dev ML, Comment

It looks like #2203 will fix the build failure. Will update this pull-request to include the fix once #2203 included. (I ran CI against my fork repo and I confirmed CI passed in OSX too. haya14busa#5)


You are receiving this because you commented.

haya14busa

unread,
Oct 14, 2017, 6:06:59 AM10/14/17
to vim/vim, vim-dev ML, Push

@haya14busa pushed 1 commit.

  • 18261aa Add test for incremental highlight


You are receiving this because you are subscribed to this thread.

View it on GitHub

Codecov

unread,
Oct 14, 2017, 6:09:24 AM10/14/17
to vim/vim, vim-dev ML, Comment

Codecov Report

Merging #2198 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2198      +/-   ##
==========================================
- Coverage   74.34%   74.29%   -0.05%     
==========================================
  Files          90       90              
  Lines      131984   132006      +22     
  Branches    28988    30871    +1883     
==========================================
- Hits        98121    98079      -42     
- Misses      33863    33923      +60     
- Partials        0        4       +4
Impacted Files Coverage Δ
src/option.c 84.47% <ø> (ø) ⬆️
src/search.c 73.71% <100%> (+0.12%) ⬆️
src/ex_getln.c 72.94% <100%> (+0.57%) ⬆️
src/memline.c 70.81% <0%> (-3.42%) ⬇️
src/if_xcmdsrv.c 83.63% <0%> (-0.9%) ⬇️
src/fold.c 84.66% <0%> (-0.72%) ⬇️
src/ex_cmds2.c 80.21% <0%> (-0.3%) ⬇️
src/term.c 51.2% <0%> (-0.22%) ⬇️
src/message.c 68.26% <0%> (-0.2%) ⬇️
src/if_py_both.h 76.09% <0%> (-0.15%) ⬇️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1d68d9b...a552edd. Read the comment docs.


You are receiving this because you commented.

haya14busa

unread,
Oct 14, 2017, 6:13:31 AM10/14/17
to vim/vim, vim-dev ML, Comment

I added test for highlight while incremental searching by runnning vim with term_start().

I cannot find a way to test highlight while searching with Vim itself because
"redraw" command while searching turn of incserach and inchlsearch highlight.

We cannot test gVim with term_start, but I think it's better than nothing :)


You are receiving this because you commented.

haya14busa

unread,
Oct 18, 2017, 8:08:41 AM10/18/17
to vim/vim, vim-dev ML, Push

@haya14busa pushed 1 commit.

  • 7c78384 Merge branch 'master' into incsearch-hi-all


You are receiving this because you are subscribed to this thread.

View it on GitHub

haya14busa

unread,
Oct 18, 2017, 8:24:10 AM10/18/17
to vim/vim, vim-dev ML, Comment

Hi, Bram!

Could you tell me your thought about this patch?
I understand bug fixes have higher priority than new feature like this and I
won't say please merge it right now, but I want to hear your opinion and
improve this patch if needed.

(I updated the patch to fix the conflict with recent changes)


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Oct 18, 2017, 12:29:10 PM10/18/17
to vim/vim, vim-dev ML, Comment

@yegappan commented on this pull request.


In runtime/doc/options.txt:

> @@ -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

The help text needs to be updated. The 'hlsearch' option is not needed
to enable this feature.


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Oct 18, 2017, 12:34:20 PM10/18/17
to vim/vim, vim-dev ML, Comment

@yegappan commented on this pull request.

Few help files need to be updated to refer to this new option.

The eval.txt help file needs to be updated to include this option. Search for 'extra_search' in eval.txt.

Remove the following item from todo.txt:
Should be easy to highlight all matches with 'incsearch'. Idea by Itchyny,
2015 Feb 6.

Add some text about this feature to usr_03.txt under "TUNING SEARCHES".

Add a reference to this option in various.txt under "+extra_search".


You are receiving this because you commented.

Bram Moolenaar

unread,
Oct 19, 2017, 7:26:23 AM10/19/17
to vim/vim, vim-dev ML, Comment

haya14busa wrote:

> Could you tell me your thought about this patch?
> I understand bug fixes have higher priority than new feature like this and I
> won't say please merge it right now, but I want to hear your opinion and
> improve this patch if needed.
>
> (I updated the patch to fix the conflict with recent changes)

I like the feature, just wondering when exactly we should do this.
I don't like adding yet another option.
I think that the combination of 'incsearch' and 'hlsearch' is
sufficient. If someone disables 'hlsearch', e.g., because they don't
like seeing more matches or it's too slow, then they most likely also
don't want it for inc-searching.
There will be a group of users who would want 'nohlsearch' but
still highlight all matches when inc-searching, but I would say this
group is too small to add another option for.
Perhaps it can even be done with an autocommand, setting 'hlsearch' when
typing the search and disabling it again afterwards.


--
CUSTOMER: You're not fooling anyone y'know. Look, isn't there something
you can do?
DEAD PERSON: I feel happy... I feel happy.
[whop]
CUSTOMER: Ah, thanks very much.
MORTICIAN: Not at all. See you on Thursday.
CUSTOMER: Right.
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


You are receiving this because you commented.

Yegappan Lakshmanan

unread,
Oct 19, 2017, 10:43:09 AM10/19/17
to vim_dev, reply+00b1d198cd2955c255a74d2511bf27100886859...@reply.github.com, vim/vim, vim-dev ML, Comment
Hi Bram,

On Thu, Oct 19, 2017 at 4:26 AM, Bram Moolenaar
<vim-dev...@256bit.org> wrote:
>
> haya14busa wrote:
>
>> Could you tell me your thought about this patch?
>> I understand bug fixes have higher priority than new feature like this and
>> I
>> won't say please merge it right now, but I want to hear your opinion and
>> improve this patch if needed.
>>
>> (I updated the patch to fix the conflict with recent changes)
>
> I like the feature, just wondering when exactly we should do this.
> I don't like adding yet another option.
>
> I think that the combination of 'incsearch' and 'hlsearch' is
> sufficient. If someone disables 'hlsearch', e.g., because they don't
> like seeing more matches or it's too slow, then they most likely also
> don't want it for inc-searching.
>
> There will be a group of users who would want 'nohlsearch' but
> still highlight all matches when inc-searching, but I would say this
> group is too small to add another option for.
>

I don't set/like the 'hlsearch' option but I like the new feature.
I don't know whether I am in a minority group of users who
like this combination. If we are not going to add a new option,
what about enabling this by default when 'incsearch' is set?

Regards,
Yegappan

vim-dev ML

unread,
Oct 19, 2017, 10:43:41 AM10/19/17
to vim/vim, vim-dev ML, Your activity

Bram Moolenaar

unread,
Oct 19, 2017, 11:42:34 AM10/19/17
to vim...@googlegroups.com, Yegappan Lakshmanan, reply+00b1d198cd2955c255a74d2511bf27100886859...@reply.github.com, vim/vim, vim-dev ML, Comment

Yegappan wrote:

> On Thu, Oct 19, 2017 at 4:26 AM, Bram Moolenaar
> <vim-dev...@256bit.org> wrote:
> >
> > haya14busa wrote:
> >
> >> Could you tell me your thought about this patch?
> >> I understand bug fixes have higher priority than new feature like this and
> >> I
> >> won't say please merge it right now, but I want to hear your opinion and
> >> improve this patch if needed.
> >>
> >> (I updated the patch to fix the conflict with recent changes)
> >
> > I like the feature, just wondering when exactly we should do this.
> > I don't like adding yet another option.
> >
> > I think that the combination of 'incsearch' and 'hlsearch' is
> > sufficient. If someone disables 'hlsearch', e.g., because they don't
> > like seeing more matches or it's too slow, then they most likely also
> > don't want it for inc-searching.
> >
> > There will be a group of users who would want 'nohlsearch' but
> > still highlight all matches when inc-searching, but I would say this
> > group is too small to add another option for.
> >
>
> I don't set/like the 'hlsearch' option but I like the new feature.
> I don't know whether I am in a minority group of users who
> like this combination. If we are not going to add a new option,
> what about enabling this by default when 'incsearch' is set?

One problem is that it needs another highlight group. If it is not set
correctly then 'incsearch' might not work properly, all matches may look
similar. If 'hlsearch' is set we can assume the user has setup the
highlighting.

I'll add the CmdlineEnter and CmdlineLeave autocommand events, these are
useful for other things as well.

--
A mathematician is a device for turning coffee into theorems.
Paul Erdos
A computer programmer is a device for turning coffee into bugs.
Bram Moolenaar

vim-dev ML

unread,
Oct 19, 2017, 11:42:56 AM10/19/17
to vim/vim, vim-dev ML, Your activity

xtal8

unread,
Oct 19, 2017, 12:27:46 PM10/19/17
to vim/vim, vim-dev ML, Comment

If this patch relied on incsearch options then old behavior could not be preserved even with CmdlineEnter and CmdlineLeave events. It would be a pithy for those users who use search mostly as navigation tool.

I think idea of using hlsearch and autocommands is the best. It allows preservation of old behavior and is consistent with current current hlsearch option description.


You are receiving this because you commented.

haya14busa

unread,
Oct 20, 2017, 12:11:58 AM10/20/17
to vim/vim, vim-dev ML, Push

@haya14busa pushed 4 commits.

  • d6d5aa2 Remove 'inchlsearch' option
  • bcaefe6 Merge branch 'master' into incsearch-hi-all
  • 147d165 add example configuration
  • 8bc7dcc add test


You are receiving this because you are subscribed to this thread.

View it on GitHub

haya14busa

unread,
Oct 20, 2017, 12:19:10 AM10/20/17
to vim/vim, vim-dev ML, Comment

Thanks for the responses!

I'll add the CmdlineEnter and CmdlineLeave autocommand events, these are
useful for other things as well.

This is really great!
Now that we have Cmdline{Enter,Leave}, I also believe combination of 'incsearch' and 'incsearch' is enough instead of adding another option.
Users can control the behavior on their own.

I updated the patch. Changed document and added one additional test (test highlight while searching with &hlsearch == false.

Christian Brabandt

unread,
Oct 20, 2017, 2:28:48 AM10/20/17
to vim/vim, vim-dev ML, Comment
augroup vimrc-incsearch-highlight
+		  autocmd!
+		  autocmd CmdlineEnter * :if expand('<afile>') == '/' | set hlsearch | endif
+		  autocmd CmdlineLeave * :if expand('<afile>') == '/' | set nohlsearch | endif
+		augroup END

That does not work as expected. I tried this configuration when the patch was released. It does enable hlsearch when you search something (actually, only when typing the first char after entering search mode (e.g. not after / but only after you enter the first character to search for)). However, the way it works is, it will highlight the last used search pattern and not the currently entered pattern. And once we finish the search, it will be disabled.

You can try this: vim --clean -c ':h'. Enter the autocommand au CmdlineEnter * :if expand('<afile>') == '/' | set hlsearch | endif, and then do :let @/='.*'. Now enter /vim. Note, highlighting starts only after pressing v. Note also, it highlights the last search pattern .* instead of the typed one v and therefore highlights the complete text. Once you have typed vim and pressed enter the highlight vanishes, so you never actually see only vim highlighted.

Of course this is not a problem with your patch, I am just pointing out, that this does not work as expected.

BTW: You actually want rather this in the documentation: :if expand('<afile>') =~ '[/?]'

Bram Moolenaar

unread,
Oct 21, 2017, 3:00:01 PM10/21/17
to vim/vim, vim-dev ML, Comment

Christian Brabandt wrote:

> ```

> augroup vimrc-incsearch-highlight
> + autocmd!
> + autocmd CmdlineEnter * :if expand('<afile>') == '/' | set hlsearch | endif
> + autocmd CmdlineLeave * :if expand('<afile>') == '/' | set nohlsearch | endif
> + augroup END
> ```
>
> That does not work as expected. I tried this configuration when the
> patch was released. It does enable hlsearch when you search something
> (actually, only when typing the first char after entering search mode
> (e.g. not after `/` but only after you enter the first character to
> search for)). However, the way it works is, it will highlight the last
> used search pattern and not the currently entered pattern. And once we
> finish the search, it will be disabled.

But it does work when 'hlsearch' is always on?


> You can try this: `vim --clean -c ':h'`. Enter the autocommand `au
> CmdlineEnter * :if expand('<afile>') == '/' | set hlsearch | endif`,
> and then do `:let @/='.*'`. Now enter `/vim`. Note, highlighting
> starts only after pressing `v`. Note also, it highlights the last

> search pattern `.*` instead of the typed one `v` and therefore
> highlights the complete text. Once you have typed `vim` and pressed
> enter the highlight vanishes, so you never actually see only `vim`
> highlighted.
>
> Of course this is not a problem with your patch, I am just pointing
> out, that this does not work as expected.
>
> BTW: You actually want rather this in the documentation: `:if
> expand('<afile>') =~ '[/?]'`

You can use / for the pattern instead:
autocmd CmdlineEnter / set hlsearch


--
ARTHUR: I am your king!
WOMAN: Well, I didn't vote for you.
ARTHUR: You don't vote for kings.
WOMAN: Well, 'ow did you become king then?

The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

haya14busa

unread,
Oct 21, 2017, 5:33:39 PM10/21/17
to vim/vim, vim-dev ML, Push

@haya14busa pushed 1 commit.

haya14busa

unread,
Oct 21, 2017, 5:39:15 PM10/21/17
to vim/vim, vim-dev ML, Comment

@chrisbra I was confused with your report. I couldn't reproduce it nor understand what you mean. But on second thought, the report totally makes sense if I assume you didn't apply the latest attached patch. Can you confirm that you used the latest attached patch?

BTW: You actually want rather this in the documentation: :if expand('') =~ '[/?]'


You can use / for the pattern instead:
autocmd CmdlineEnter / set hlsearch

Thanks! That's nice. I updated the patch.

haya14busa

unread,
Oct 22, 2017, 9:13:51 AM10/22/17
to vim/vim, vim-dev ML, Push

@haya14busa pushed 1 commit.

  • 9fbe6fb Merge branch 'master' into incsearch-hi-all

Christian Brabandt

unread,
Oct 23, 2017, 3:49:47 AM10/23/17
to vim/vim, vim-dev ML, Comment

But it does work when 'hlsearch' is always on?

Not sure what you mean with work...

mj-2017

unread,
Oct 26, 2017, 12:21:05 PM10/26/17
to vim/vim, vim-dev ML, Comment

I pulled the latest vim.git repo yesterday and it appears this patch was included (based on looking at the source files). However, I have both incsearch and hlsearch options set to On, but I don't get the new functionality provided by the patch. What am I missing?

Christian Brabandt

unread,
Oct 26, 2017, 4:06:07 PM10/26/17
to vim/vim, vim-dev ML, Comment

it is not included yet.

mj-2017

unread,
Oct 26, 2017, 4:54:24 PM10/26/17
to vim/vim, vim-dev ML, Comment

Oh, that explains it. I guess when I pull'd what I thought was this patch based on a hash of 9fbe6fb, I didn't do it correctly and apparently got one of Bram's latest patches which was of course was already in the vim pull that I had done. Um, so how can I download the latest version of this patch?

Thanks very much for the reply.

K.Takata

unread,
Oct 26, 2017, 5:57:46 PM10/26/17
to vim/vim, vim-dev ML, Comment

Um, so how can I download the latest version of this patch?

Go to this link:
https://github.com/vim/vim/pull/2198.diff

Or:

git checkout -b haya14busa-incsearch-hi-all master
git pull https://github.com/haya14busa/vim.git incsearch-hi-all

mj-2017

unread,
Oct 26, 2017, 6:04:20 PM10/26/17
to vim/vim, vim-dev ML, Comment

Thanks very much for the link!

Christian Brabandt

unread,
Oct 27, 2017, 2:28:50 AM10/27/17
to vim/vim, vim-dev ML, Comment

You don't have to checkout the contributors repository. You can also switch directly to a pull request using something like this:

git fetch origin pull/<ID>/head:branch
git checkout branch

Now you can build and test yourself.

See also the github documentation:
https://help.github.com/articles/checking-out-pull-requests-locally/

haya14busa

unread,
Oct 28, 2017, 10:09:16 AM10/28/17
to vim/vim, vim-dev ML, Push

@haya14busa pushed 1 commit.

  • ad1e575 add incremental highlight tests for <C-g>/<C-t>

haya14busa

unread,
Oct 28, 2017, 10:23:08 AM10/28/17
to vim/vim, vim-dev ML, Comment

Hi!

I added tests for incremental highlight of <C-g> and <C-t> (I found that I forgot to write them...).
I think the tests covered enough cases for this patch now.

git fetch origin pull//head:branch
git checkout branch

bwt, this works well for first time, but there is no tracking information (no
upstream branch) for the created branch, so you cannot update the branch by
simple git pull command. Instead you need to run this following command.

$ git pull origin pull/2198/head

@chrisbra

Not sure what you mean with work...

Work like the GIF I pasted on the top comment?

Sorry for repeating it, but I assume you didn't use the latest patch.
Can you confirm that you used the latest patch?

If your report is true, it's certainly the problem of this patch, not the problem of the autocmd.
So, I want to confirm that and want to fix if the problem is reproducible with latest code.
Thanks!

Christian Brabandt

unread,
Oct 29, 2017, 4:58:20 AM10/29/17
to vim/vim, vim-dev ML, Comment

@haya14busa

Sorry for repeating it, but I assume you didn't use the latest patch.

that was unrelated to your patch and was only a comment that setting the 'hlsearch' setting on CmdlineEnter/ CmdlineLeave autocommands won't work as expected.

haya14busa

unread,
Oct 29, 2017, 8:10:40 AM10/29/17
to vim/vim, vim-dev ML, Comment

Ok, then what is your expectation?

Last pattern should be highlighted right after pressing search command (/) instead of first character?

Or, you mentioned

it highlights the last search pattern .* instead of the typed one v

but, without my patch, it's totally expected behavior. Incremental searching won't change the last search pattern.

haya14busa

unread,
Oct 29, 2017, 8:30:22 AM10/29/17
to vim/vim, vim-dev ML, Comment
autocmd CmdlineEnter [/\?] :set hlsearch | redraw

By calling :redraw, last pattern will be highlighted right after pressing / or ?.

Other behavior you reported seems expected behavior. When ':set hlsearchand:set incsearch`, last pattern is highlighted same as before. The autocmd just turn on and off 'hlsearch' when entering/leaving cmdline.

Bram Moolenaar

unread,
Oct 29, 2017, 11:41:05 AM10/29/17
to vim/vim, vim-dev ML, Comment

Closed #2198 via 2e51d9a.

haya14busa

unread,
Oct 29, 2017, 6:28:09 PM10/29/17
to vim/vim, vim-dev ML, Comment

Thank you for including it!

duff

unread,
Oct 30, 2017, 6:37:39 PM10/30/17
to vim/vim, vim-dev ML, Comment

@duff commented on this pull request.


In runtime/doc/options.txt:

> @@ -4447,7 +4447,17 @@ 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'.
+	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

Thank you for this option! It works great!

xtal8

unread,
Nov 1, 2017, 10:26:44 AM11/1/17
to vim/vim, vim-dev ML, Comment

The augroup provided in description of 'incsearch' doesn't work on Windows.

Christian Brabandt

unread,
Nov 1, 2017, 11:01:14 AM11/1/17
to vim/vim, vim-dev ML, Comment

yeah, it looks like this:

		  autocmd CmdlineEnter [/\?] :set hlsearch

does not match on Windows. However this works:

		  autocmd CmdlineEnter /,\? :set hlsearch
		  autocmd CmdlineLeave /,\? :set nohlsearch

xtal8

unread,
Nov 1, 2017, 11:07:47 AM11/1/17
to vim/vim, vim-dev ML, Comment

Why is backslash needed? It works without it.

lacygoill

unread,
Nov 1, 2017, 11:14:09 AM11/1/17
to vim/vim, vim-dev ML, Comment

@xtal8 I think that the question mark has a special meaning inside the pattern used in an autocmd. It matches any character. But here, you don't want the special meaning, you want a literal question mark. The one standing for a search command line you entered after pressing ? while in normal mode. Otherwise ? would match all symbols standing for any Ex command line (see :h cmdwind-char).

xtal8

unread,
Nov 1, 2017, 11:31:35 AM11/1/17
to vim/vim, vim-dev ML, Comment

I think it's used in a sense of wildcards not patterns. But when I tried to use autocommand with only ? (without backslahs) hlsearch wasn't enabled inside a search started with /. That's why I asked.

David Ben Knoble

unread,
Nov 18, 2017, 12:40:37 AM11/18/17
to vim/vim, vim-dev ML, Comment

Hi all, I've noticed that after updating to vim 8.0.1250, my search behavior was a little weird. I think it's related to this patch, but it seems
/\v
matches every character in a file, where it didn't previously. When I got to search now (using my nnoremap / /\v), the entire file is highlighted by incsearch and hlsearch until I start typing my pattern. Further, if I hit <CR>, pressing n will simply take me character-by-character through the file.

This didn't occur before. Is this considered intended behavior (i.e. that an empty search pattern with the very-magic flag is a match for every character?

h_east

unread,
Nov 18, 2017, 3:29:36 AM11/18/17
to vim_dev
Hi David,

2017-11-18(Sat) 14:40:37 UTC+9 David Ben Knoble:


> Hi all, I've noticed that after updating to vim 8.0.1250, my search behavior was a little weird. I think it's related to this patch, but it seems
>
> /\v
>
> matches every character in a file, where it didn't previously. When I got to search now (using my nnoremap / /\v), the entire file is highlighted by incsearch and hlsearch until I start typing my pattern. Further, if I hit <CR>, pressing n will simply take me character-by-character through the file.
>
> This didn't occur before. Is this considered intended behavior (i.e. that an empty search pattern with the very-magic flag is a match for every character?

Your reported issue is discussed in following thread.
https://groups.google.com/d/topic/vim_dev/YlKJq45uYY8/discussion

--
Best regards,
Hirohito Higashi (h_east)

duff

unread,
Nov 18, 2017, 8:42:29 AM11/18/17
to vim/vim, vim-dev ML, Comment

@benknoble I saw the same behavior. For now at least, I removed my nnoremap / /\v mapping.

K.Takata

unread,
Nov 18, 2017, 10:24:19 AM11/18/17
to vim/vim, vim-dev ML, Comment

It is discussed at #2337.

Reply all
Reply to author
Forward
0 new messages