-
-
Couldn't load subscription status.
- Fork 5.9k
Highlight all matched text while incremental searching #2198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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 ***@***.***> 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:
#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
|
|
Hi,
On Sun, Oct 8, 2017 at 9:05 PM, Yegappan Lakshmanan ***@***.***> 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 ***@***.***>
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'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:
>
> #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 (15)
> M runtime/doc/quickref.txt (1)
> M runtime/optwin.vim (2)
> M src/ex_getln.c (17)
> M src/option.c (3)
> M src/option.h (1)
> M src/proto/search.pro (2)
> M src/search.c (43)
> M src/testdir/test_search.vim (33)
>
> Patch Links:
>
> https://github.com/vim/vim/pull/2198.patch
> https://github.com/vim/vim/pull/2198.diff
|
|
Hi,
On Sun, Oct 8, 2017 at 9:05 PM, Yegappan Lakshmanan ***@***.***> 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 ***@***.***>
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'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:
>
> #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 (15)
> M runtime/doc/quickref.txt (1)
> M runtime/optwin.vim (2)
> M src/ex_getln.c (17)
> M src/option.c (3)
> M src/option.h (1)
> M src/proto/search.pro (2)
> M src/search.c (43)
> M src/testdir/test_search.vim (33)
>
> Patch Links:
>
> https://github.com/vim/vim/pull/2198.patch
> https://github.com/vim/vim/pull/2198.diff
|
|
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 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) |
|
Hi,
On Tue, Oct 10, 2017 at 11:32 PM, haya14busa ***@***.***> 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
…
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)
|
|
did you check the build failure? |
|
I don't think it is related to this PR, because the master branch also failed with the same error. |
|
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) |
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 <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.
[1]: https://groups.google.com/forum/#!searchin/vim_dev/incsearch|sort:relevance/vim_dev/zdp8W-6xUzg/PrqDpP7cilIJ
18261aa to
ec14f43
Compare
ec14f43 to
a552edd
Compare
Codecov Report
@@ Coverage Diff @@
## master #2198 +/- ##
==========================================
+ Coverage 74.31% 74.42% +0.11%
==========================================
Files 90 90
Lines 132039 132089 +50
Branches 28994 29001 +7
==========================================
+ Hits 98126 98310 +184
+ Misses 33884 33750 -134
Partials 29 29
Continue to review full report at Codecov.
|
|
I added test for highlight while incremental searching by runnning vim with I cannot find a way to test highlight while searching with Vim itself because We cannot test gVim with term_start, but I think it's better than nothing :) |
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.
|
Hi, Bram! Could you tell me your thought about this patch? (I updated the patch to fix the conflict with recent changes) |
runtime/doc/options.txt
Outdated
| {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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help text needs to be updated. The 'hlsearch' option is not needed
to enable this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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".
|
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 -- [email protected] -- 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 ///
|
|
Hi Bram,
On Thu, Oct 19, 2017 at 4:26 AM, Bram Moolenaar ***@***.***> 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
…
Perhaps it can even be done with an autocommand, setting 'hlsearch' when
typing the search and disabling it again afterwards.
|
|
Yegappan wrote:
On Thu, Oct 19, 2017 at 4:26 AM, Bram Moolenaar
***@***.***> 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
/// Bram Moolenaar -- [email protected] -- 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 ///
|
|
If this patch relied on I think idea of using |
Not sure what you mean with work... |
|
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? |
|
it is not included yet. |
|
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. |
Go to this link: Or: |
|
Thanks very much for the link! |
|
You don't have to checkout the contributors repository. You can also switch directly to a pull request using something like this: Now you can build and test yourself. See also the github documentation: |
|
Hi! I added tests for incremental highlight of
bwt, this works well for first time, but there is no tracking information (no
Work like the GIF I pasted on the top comment? Sorry for repeating it, but I assume you didn't use the latest patch. If your report is true, it's certainly the problem of this patch, not the problem of the autocmd. |
that was unrelated to your patch and was only a comment that setting the 'hlsearch' setting on |
|
Ok, then what is your expectation? Last pattern should be highlighted right after pressing search command ( Or, you mentioned
but, without my patch, it's totally expected behavior. Incremental searching won't change the last search pattern. |
By calling Other behavior you reported seems expected behavior. When |
|
Thank you for including it! ✨ |
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this option! It works great!
|
The augroup provided in description of 'incsearch' doesn't work on Windows. |
|
yeah, it looks like this: does not match on Windows. However this works: |
|
Why is backslash needed? It works without it. |
|
I think it's used in a sense of wildcards not patterns. But when I tried to use autocommand with only |
|
Hi all, I've noticed that after updating to This didn't occur before. Is this considered intended behavior (i.e. that an empty search pattern with the |
|
@benknoble I saw the same behavior. For now at least, I removed my |
|
It is discussed at #2337. |
Problem: Incremental search only shows one match.
Solution: When 'incsearch' and and 'hlsearch' are both set highlight all
matches. (haya14busa, closes vim#2198)
Replaced by native functionality: neovim/neovim#7463 vim/vim#2198 Set `hlsearch` and `incsearch` to get the same functionality natively.
Problem: Incremental search only shows one match.
Solution: When 'incsearch' and and 'hlsearch' are both set highlight all
matches. (haya14busa, closes vim/vim#2198)
vim/vim@2e51d9a
Problem: Incremental search only shows one match.
Solution: When 'incsearch' and and 'hlsearch' are both set highlight all
matches. (haya14busa, closes vim/vim#2198)
vim/vim@2e51d9a
Problem: Incremental search only shows one match.
Solution: When 'incsearch' and and 'hlsearch' are both set highlight all
matches. (haya14busa, closes vim/vim#2198)
vim/vim@2e51d9a
>⚠️ Deprecated This plugin is no longer necessary since the main functionality is now built into vim/neovim > > See: > - https://medium.com/@haya14busa/incsearch-vim-is-dead-long-live-incsearch-2b7070d55250 > - vim/vim#2198 > - Successor plugin: https://github.com/haya14busa/is.vim
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 isstored 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 :)