[feature request] Highlight all the matches while searching

168 views
Skip to first unread message

itchyny

unread,
Feb 6, 2015, 12:38:17 PM2/6/15
to vim...@googlegroups.com
The option 'incsearch' just jumps to the first matching place and highlights it.
We then press enter, all the matches are get highlighted (if we set hlsearch on).
If Vim highlights all the matching strings, it would be nice.

There's already an implementation in Vim script (https://github.com/haya14busa/incsearch.vim).
However, this plugin uses its own command-line like interface thus very limited and the code is too complicated.

If this feature will be implemented with a small patch, it would be nice and I hope it merged.

Here's a simple patch I wrote.
I noticed that just removing the SEARCH_KEEP flag enables Vimt to highlight the
matches while searching (search.c:L1149, ex_getln.c:L1795).
Of course, as you notice, the following patch overwrites the default behavior
and it must be fixed if the feature will be merged to Vim.
Does anyone get interested in implementing the followings?
- new option ('incsearchhlall' or something like that)to highlight all the matches
while searching (disabled by default)
- related documents and helps

diff -r cd5eff09c1ae src/ex_getln.c
--- a/src/ex_getln.c Thu Feb 05 20:29:59 2015 +0100
+++ b/src/ex_getln.c Sat Feb 07 02:09:58 2015 +0900
@@ -1778,8 +1778,10 @@
curwin->w_cursor = old_cursor; /* start at old position */

/* If there is no command line, don't do anything */
- if (ccline.cmdlen == 0)
+ if (ccline.cmdlen == 0) {
i = 0;
+ SET_NO_HLSEARCH(TRUE);
+ }
else
{
cursor_off(); /* so the user knows we're busy */
@@ -1790,7 +1792,7 @@
profile_setlimit(500L, &tm);
#endif
i = do_search(NULL, firstc, ccline.cmdbuff, count,
- SEARCH_KEEP + SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK,
+ SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK,
#ifdef FEAT_RELTIME
&tm

Regards, itchyny.
Thanks.

Ben Fritz

unread,
Feb 6, 2015, 1:23:25 PM2/6/15
to vim...@googlegroups.com
On Friday, February 6, 2015 at 11:38:17 AM UTC-6, itchyny wrote:
> The option 'incsearch' just jumps to the first matching place and highlights it.
> We then press enter, all the matches are get highlighted (if we set hlsearch on).
> If Vim highlights all the matching strings, it would be nice.
>

When I use incsearch, it is because I want to be able to see quickly whether my current search takes me where I want to go, so that I can hit Enter rather than continuing my typing. I think highlighting all of the matches would make that task more difficult since I would need to figure out which highlighted match my cursor may be on.

So if the ability to highlight all matches is useful and gets added, I'd certainly like it to be an option to keep the existing behavior.

Bram Moolenaar

unread,
Feb 7, 2015, 8:39:05 AM2/7/15
to itchyny, vim...@googlegroups.com

Itchyny wrote:

> The option 'incsearch' just jumps to the first matching place and
> highlights it.
> We then press enter, all the matches are get highlighted (if we set
> hlsearch on).
> If Vim highlights all the matching strings, it would be nice.
>
> There's already an implementation in Vim script
> (https://github.com/haya14busa/incsearch.vim).
> However, this plugin uses its own command-line like interface thus
> very limited and the code is too complicated.
>
> If this feature will be implemented with a small patch, it would be
> nice and I hope it merged.
>
> Here's a simple patch I wrote.
> I noticed that just removing the SEARCH_KEEP flag enables Vimt to
> highlight the
> matches while searching (search.c:L1149, ex_getln.c:L1795).
> Of course, as you notice, the following patch overwrites the default behavior
> and it must be fixed if the feature will be merged to Vim.
> Does anyone get interested in implementing the followings?
> - new option ('incsearchhlall' or something like that)to highlight
> all the matches
> while searching (disabled by default)
> - related documents and helps

We need different highlighting for the matches other than the one that
the cursor would jump to. If that's different enough then I don't think
we need yet-another-option. At least for me the search highlighting and
the incsearch match highlighting are very different.


--
hundred-and-one symptoms of being an internet addict:
191. You rate eating establishments not by the quality of the food,
but by the availability of electrical outlets for your PowerBook.

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

itchyny

unread,
Feb 8, 2015, 12:09:53 AM2/8/15
to vim...@googlegroups.com, itchyny...@gmail.com
Thank you, Bram and Ben.
However, Bram, I do not understand what you mean -- they are different _then_ you don't think we need yet-another-option.
I now understand that highlighting all the matches and incsearch are different, _therefore_
we need another option to enable highlighting all the matches while searching, right?
Of course the highlighting color should be different from both of Search and IncSearch.
Considering the reputation the existing plugin (https://github.com/haya14busa/incsearch.vim while the
plugin name might be misleading) got, it is apparent that many people want the feature implemented in Vim.
(I again state that the existing plugin uses many dirty hacks (own cmdline-like interface
and getchar() loops) to implement the feature)

itchyny
Reply all
Reply to author
Forward
0 new messages