mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:8.0.1238
Problem: Incremental search only shows one match.
Solution: When 'incsearch' and and 'hlsearch' are both set highlight all
matches. (haya14busa, closes vim/vim#2198)
2e51d9a097
This commit is contained in:
@@ -3299,7 +3299,17 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
pattern and/or a lot of text the match may not be found. This is to
|
pattern and/or a lot of text the match may not be found. This is to
|
||||||
avoid that Vim hangs while you are typing the pattern.
|
avoid that Vim hangs while you are typing the pattern.
|
||||||
The |hl-IncSearch| highlight group determines the highlighting.
|
The |hl-IncSearch| highlight group determines the highlighting.
|
||||||
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
|
||||||
|
autocmd!
|
||||||
|
autocmd CmdlineEnter [/\?] :set hlsearch
|
||||||
|
autocmd CmdlineLeave [/\?] :set nohlsearch
|
||||||
|
augroup END
|
||||||
|
<
|
||||||
CTRL-L can be used to add one character from after the current match
|
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
|
to the command line. If 'ignorecase' and 'smartcase' are set and the
|
||||||
command line has no uppercase characters, the added character is
|
command line has no uppercase characters, the added character is
|
||||||
|
@@ -1019,13 +1019,18 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match)
|
|||||||
ui_flush();
|
ui_flush();
|
||||||
|
|
||||||
pos_T t;
|
pos_T t;
|
||||||
int search_flags = SEARCH_KEEP + SEARCH_NOOF + SEARCH_PEEK;
|
int search_flags = SEARCH_NOOF;
|
||||||
|
save_last_search_pattern();
|
||||||
|
|
||||||
if (next_match) {
|
if (next_match) {
|
||||||
t = s->match_end;
|
t = s->match_end;
|
||||||
search_flags += SEARCH_COL;
|
search_flags += SEARCH_COL;
|
||||||
} else {
|
} else {
|
||||||
t = s->match_start;
|
t = s->match_start;
|
||||||
}
|
}
|
||||||
|
if (!p_hls) {
|
||||||
|
search_flags += SEARCH_KEEP;
|
||||||
|
}
|
||||||
emsg_off++;
|
emsg_off++;
|
||||||
s->i = searchit(curwin, curbuf, &t,
|
s->i = searchit(curwin, curbuf, &t,
|
||||||
next_match ? FORWARD : BACKWARD,
|
next_match ? FORWARD : BACKWARD,
|
||||||
@@ -1066,6 +1071,7 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match)
|
|||||||
s->old_topfill = curwin->w_topfill;
|
s->old_topfill = curwin->w_topfill;
|
||||||
s->old_botline = curwin->w_botline;
|
s->old_botline = curwin->w_botline;
|
||||||
update_screen(NOT_VALID);
|
update_screen(NOT_VALID);
|
||||||
|
restore_last_search_pattern();
|
||||||
redrawcmdline();
|
redrawcmdline();
|
||||||
} else {
|
} else {
|
||||||
vim_beep(BO_ERROR);
|
vim_beep(BO_ERROR);
|
||||||
@@ -1773,20 +1779,26 @@ static int command_line_changed(CommandLineState *s)
|
|||||||
}
|
}
|
||||||
s->incsearch_postponed = false;
|
s->incsearch_postponed = false;
|
||||||
curwin->w_cursor = s->search_start; // start at old position
|
curwin->w_cursor = s->search_start; // start at old position
|
||||||
|
save_last_search_pattern();
|
||||||
|
|
||||||
// If there is no command line, don't do anything
|
// If there is no command line, don't do anything
|
||||||
if (ccline.cmdlen == 0) {
|
if (ccline.cmdlen == 0) {
|
||||||
s->i = 0;
|
s->i = 0;
|
||||||
|
SET_NO_HLSEARCH(true); // turn off previous highlight
|
||||||
} else {
|
} else {
|
||||||
|
int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK;
|
||||||
ui_busy_start();
|
ui_busy_start();
|
||||||
ui_flush();
|
ui_flush();
|
||||||
++emsg_off; // So it doesn't beep if bad expr
|
++emsg_off; // So it doesn't beep if bad expr
|
||||||
// Set the time limit to half a second.
|
// Set the time limit to half a second.
|
||||||
tm = profile_setlimit(500L);
|
tm = profile_setlimit(500L);
|
||||||
|
if (!p_hls) {
|
||||||
|
search_flags += SEARCH_KEEP;
|
||||||
|
}
|
||||||
s->i = do_search(NULL, s->firstc, ccline.cmdbuff, s->count,
|
s->i = do_search(NULL, s->firstc, ccline.cmdbuff, s->count,
|
||||||
SEARCH_KEEP + SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK,
|
search_flags,
|
||||||
&tm);
|
&tm);
|
||||||
--emsg_off;
|
emsg_off--;
|
||||||
// if interrupted while searching, behave like it failed
|
// if interrupted while searching, behave like it failed
|
||||||
if (got_int) {
|
if (got_int) {
|
||||||
(void)vpeekc(); // remove <C-C> from input stream
|
(void)vpeekc(); // remove <C-C> from input stream
|
||||||
@@ -1836,6 +1848,7 @@ static int command_line_changed(CommandLineState *s)
|
|||||||
save_cmdline(&s->save_ccline);
|
save_cmdline(&s->save_ccline);
|
||||||
update_screen(SOME_VALID);
|
update_screen(SOME_VALID);
|
||||||
restore_cmdline(&s->save_ccline);
|
restore_cmdline(&s->save_ccline);
|
||||||
|
restore_last_search_pattern();
|
||||||
|
|
||||||
// Leave it at the end to make CTRL-R CTRL-W work.
|
// Leave it at the end to make CTRL-R CTRL-W work.
|
||||||
if (s->i != 0) {
|
if (s->i != 0) {
|
||||||
|
@@ -96,6 +96,9 @@ static int lastc_bytelen = 1; /* >1 for multi-byte char */
|
|||||||
|
|
||||||
/* copy of spats[], for keeping the search patterns while executing autocmds */
|
/* copy of spats[], for keeping the search patterns while executing autocmds */
|
||||||
static struct spat saved_spats[2];
|
static struct spat saved_spats[2];
|
||||||
|
// 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_last_idx = 0;
|
||||||
static int saved_no_hlsearch = 0;
|
static int saved_no_hlsearch = 0;
|
||||||
|
|
||||||
@@ -305,6 +308,33 @@ void free_search_patterns(void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// Save and restore the search pattern for incremental highlight search
|
||||||
|
/// feature.
|
||||||
|
///
|
||||||
|
/// It's similar but different from save_search_patterns() and
|
||||||
|
/// restore_search_patterns(), because the search pattern must be restored when
|
||||||
|
/// cancelling 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)
|
||||||
|
{
|
||||||
|
xfree(spats[RE_SEARCH].pat);
|
||||||
|
spats[RE_SEARCH] = saved_last_search_spat;
|
||||||
|
set_vv_searchforward();
|
||||||
|
last_idx = saved_last_idx;
|
||||||
|
SET_NO_HLSEARCH(saved_no_hlsearch);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return TRUE when case should be ignored for search pattern "pat".
|
* Return TRUE when case should be ignored for search pattern "pat".
|
||||||
* Uses the 'ignorecase' and 'smartcase' options.
|
* Uses the 'ignorecase' and 'smartcase' options.
|
||||||
|
@@ -99,7 +99,7 @@ describe('search highlighting', function()
|
|||||||
feed("gg/li")
|
feed("gg/li")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
the first {3:li}ne |
|
the first {3:li}ne |
|
||||||
in a little file |
|
in a {2:li}ttle file |
|
||||||
|
|
|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
@@ -132,7 +132,7 @@ describe('search highlighting', function()
|
|||||||
feed("/fir")
|
feed("/fir")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
the {3:fir}st line |
|
the {3:fir}st line |
|
||||||
in a {2:lit}tle file |
|
in a little file |
|
||||||
|
|
|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
@@ -144,13 +144,25 @@ describe('search highlighting', function()
|
|||||||
feed("<esc>/ttle")
|
feed("<esc>/ttle")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
the first line |
|
the first line |
|
||||||
in a {2:li}{3:ttle} file |
|
in a li{3:ttle} file |
|
||||||
|
|
|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
/ttle^ |
|
/ttle^ |
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
-- cancelling search resets to the old search term
|
||||||
|
feed('<esc>')
|
||||||
|
screen:expect([[
|
||||||
|
the first line |
|
||||||
|
in a {2:^lit}tle file |
|
||||||
|
|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with incsearch and offset', function()
|
it('works with incsearch and offset', function()
|
||||||
@@ -163,7 +175,7 @@ describe('search highlighting', function()
|
|||||||
feed("gg/mat/e")
|
feed("gg/mat/e")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
not the {3:mat}ch you're looking for |
|
not the {3:mat}ch you're looking for |
|
||||||
the match is here |
|
the {2:mat}ch is here |
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
@@ -174,7 +186,7 @@ describe('search highlighting', function()
|
|||||||
-- Search with count and /e offset fixed in Vim patch 7.4.532.
|
-- Search with count and /e offset fixed in Vim patch 7.4.532.
|
||||||
feed("<esc>2/mat/e")
|
feed("<esc>2/mat/e")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
not the match you're looking for |
|
not the {2:mat}ch you're looking for |
|
||||||
the {3:mat}ch is here |
|
the {3:mat}ch is here |
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
|
Reference in New Issue
Block a user