Problem: Highlighting for :s wrong when using different separator.
Solution: Use separat argument for search direction and separator. (Rob
Pilling, closes #5665)
curwin->w_cursor.col = 0;
searchcmdlen = 0;
flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG;
- if (!do_search(NULL, c, cmd, 1L, flags, NULL))
+ if (!do_search(NULL, c, c, cmd, 1L, flags, NULL))
{
curwin->w_cursor = pos;
cmd = NULL;
* May change the last search pattern.
*/
static int
-do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
+do_incsearch_highlighting(int firstc, int *search_delim, incsearch_state_T *is_state,
int *skiplen, int *patlen)
{
char_u *cmd;
search_last_line = MAXLNUM;
if (firstc == '/' || firstc == '?')
+ {
+ *search_delim = firstc;
return TRUE;
+ }
if (firstc != ':')
return FALSE;
p = skipwhite(p);
delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
+ *search_delim = delim;
end = skip_regexp(p, delim, p_magic, NULL);
use_last_pat = end == p && *end == delim;
int next_char;
int use_last_pat;
int did_do_incsearch = is_state->did_incsearch;
+ int search_delim;
// Parsing range may already set the last search pattern.
// NOTE: must call restore_last_search_pattern() before returning!
save_last_search_pattern();
- if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
+ if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen))
{
restore_last_search_pattern();
finish_incsearch_highlighting(FALSE, is_state, TRUE);
vim_memset(&sia, 0, sizeof(sia));
sia.sa_tm = &tm;
#endif
- found = do_search(NULL, firstc == ':' ? '/' : firstc,
+ found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim,
ccline.cmdbuff + skiplen, count, search_flags,
#ifdef FEAT_RELTIME
&sia
int search_flags = SEARCH_NOOF;
int i;
int save;
+ int search_delim;
// Parsing range may already set the last search pattern.
// NOTE: must call restore_last_search_pattern() before returning!
save_last_search_pattern();
- if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
+ if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen))
{
restore_last_search_pattern();
return OK;
return FAIL;
}
- if (firstc == ccline.cmdbuff[skiplen])
+ if (search_delim == ccline.cmdbuff[skiplen])
{
pat = last_search_pattern();
skiplen = 0;
static int
may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state)
{
- int skiplen, patlen;
+ int skiplen, patlen, search_delim;
// Parsing range may already set the last search pattern.
// NOTE: must call restore_last_search_pattern() before returning!
save_last_search_pattern();
- if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
+ if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen))
{
restore_last_search_pattern();
return FAIL;
// the character to lowercase.
if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen))
*c = MB_TOLOWER(*c);
- if (*c == firstc || vim_strchr((char_u *)(
+ if (*c == search_delim || vim_strchr((char_u *)(
p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL)
{
// put a backslash before special characters
i = msg_scroll;
if (down)
{
- (void)do_search(NULL, '/', ga.ga_data, 1L, searchflags, NULL);
+ (void)do_search(NULL, '/', '/', ga.ga_data, 1L, searchflags, NULL);
}
else
{
// direction
p = vim_strsave_escaped(ga.ga_data, (char_u *)"?");
if (p != NULL)
- (void)do_search(NULL, '?', p, 1L, searchflags, NULL);
+ (void)do_search(NULL, '?', '?', p, 1L, searchflags, NULL);
vim_free(p);
}
curwin->w_set_curswant = TRUE;
vim_memset(&sia, 0, sizeof(sia));
- i = do_search(cap->oap, dir, pat, cap->count1,
+ i = do_search(cap->oap, dir, dir, pat, cap->count1,
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia);
if (wrapped != NULL)
*wrapped = sia.sa_wrapped;
void last_pat_prog(regmmatch_T *regmatch);
int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, int dir, char_u *pat, long count, int options, int pat_use, searchit_arg_T *extra_arg);
void set_search_direction(int cdir);
-int do_search(oparg_T *oap, int dirc, char_u *pat, long count, int options, searchit_arg_T *sia);
+int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, int options, searchit_arg_T *sia);
int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat);
int searchc(cmdarg_T *cap, int t_cmd);
pos_T *findmatch(oparg_T *oap, int initc);
// Move the cursor to the first line in the buffer
save_cursor = curwin->w_cursor;
curwin->w_cursor.lnum = 0;
- if (!do_search(NULL, '/', qf_pattern, (long)1, SEARCH_KEEP, NULL))
+ if (!do_search(NULL, '/', '/', qf_pattern, (long)1, SEARCH_KEEP, NULL))
curwin->w_cursor = save_cursor;
}
}
do_search(
oparg_T *oap, // can be NULL
int dirc, // '/' or '?'
+ int search_delim, // the delimiter for the search, e.g. '%' in s%regex%replacement%
char_u *pat,
long count,
int options,
searchstr = pat;
dircp = NULL;
// use previous pattern
- if (pat == NULL || *pat == NUL || *pat == dirc)
+ if (pat == NULL || *pat == NUL || *pat == search_delim)
{
if (spats[RE_SEARCH].pat == NULL) // no previous pattern
{
* If there is a matching '/' or '?', toss it.
*/
ps = strcopy;
- p = skip_regexp(pat, dirc, (int)p_magic, &strcopy);
+ p = skip_regexp(pat, search_delim, (int)p_magic, &strcopy);
if (strcopy != ps)
{
// made a copy of "pat" to change "\?" to "?"
pat = strcopy;
searchstr = strcopy;
}
- if (*p == dirc)
+ if (*p == search_delim)
{
dircp = p; // remember where we put the NUL
*p++ = NUL;
RE_LAST, sia);
if (dircp != NULL)
- *dircp = dirc; // restore second '/' or '?' for normal_cmd()
+ *dircp = search_delim; // restore second '/' or '?' for normal_cmd()
if (!shortmess(SHM_SEARCH)
&& ((dirc == '/' && LT_POS(pos, curwin->w_cursor))
break;
dirc = *++pat;
+ search_delim = dirc;
if (dirc != '?' && dirc != '/')
{
retval = 0;
curwin->w_cursor.lnum = 0;
while (!got_int)
{
- if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL) == 0
+ if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0
|| u_save_cursor() == FAIL)
break;
else
// start search before first line
curwin->w_cursor.lnum = 0;
- if (do_search(NULL, pbuf[0], pbuf + 1, (long)1,
+ if (do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1,
search_options, NULL))
retval = OK;
else
* try again, ignore case now
*/
p_ic = TRUE;
- if (!do_search(NULL, pbuf[0], pbuf + 1, (long)1,
+ if (!do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1,
search_options, NULL))
{
/*
cc = *tagp.tagname_end;
*tagp.tagname_end = NUL;
sprintf((char *)pbuf, "^%s\\s\\*(", tagp.tagname);
- if (!do_search(NULL, '/', pbuf, (long)1,
+ if (!do_search(NULL, '/', '/', pbuf, (long)1,
search_options, NULL))
{
// Guess again: "^char * \<func ("
sprintf((char *)pbuf, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(",
tagp.tagname);
- if (!do_search(NULL, '/', pbuf, (long)1,
+ if (!do_search(NULL, '/', '/', pbuf, (long)1,
search_options, NULL))
found = 0;
}
--- /dev/null
+|h+0&#ffffff0|e+1&&|l@1|o|/|t|h|e|r+0&&|e| @8
+|~+0#4040ff13&| @18
+|~| @18
+|:+0#0000000&|%|s|;|e|l@1|o|/|t|h|e> @7
call delete('Xis_subst_script')
endfunc
+func Test_incsearch_highlighting()
+ if !exists('+incsearch')
+ return
+ endif
+ if !CanRunVimInTerminal()
+ throw 'Skipped: cannot make screendumps'
+ endif
+
+ call writefile([
+ \ 'set incsearch hlsearch',
+ \ 'call setline(1, "hello/there")',
+ \ ], 'Xis_subst_hl_script')
+ let buf = RunVimInTerminal('-S Xis_subst_hl_script', {'rows': 4, 'cols': 20})
+ " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by
+ " the 'ambiwidth' check.
+ sleep 300m
+
+ " Using a different search delimiter should still highlight matches
+ " that contain a '/'.
+ call term_sendkeys(buf, ":%s;ello/the")
+ call VerifyScreenDump(buf, 'Test_incsearch_substitute_15', {})
+ call term_sendkeys(buf, "<Esc>")
+endfunc
+
func Test_incsearch_with_change()
if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing'
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 295,
/**/
294,
/**/