{
delim = *p++;
end = skip_regexp(p, delim, p_magic, NULL);
- if (end > p)
+ if (end > p || *end == delim)
{
char_u *dummy;
exarg_T ea;
return FALSE;
}
+ static void
+finish_incsearch_highlighting(
+ int gotesc,
+ incsearch_state_T *is_state,
+ int call_update_screen)
+{
+ if (is_state->did_incsearch)
+ {
+ is_state->did_incsearch = FALSE;
+ if (gotesc)
+ curwin->w_cursor = is_state->save_cursor;
+ else
+ {
+ if (!EQUAL_POS(is_state->save_cursor, is_state->search_start))
+ {
+ // put the '" mark at the original position
+ curwin->w_cursor = is_state->save_cursor;
+ setpcmark();
+ }
+ curwin->w_cursor = is_state->search_start;
+ }
+ restore_viewstate(&is_state->old_viewstate);
+ highlight_match = FALSE;
+ validate_cursor(); /* needed for TAB */
+ if (call_update_screen)
+ update_screen(SOME_VALID);
+ else
+ redraw_all_later(SOME_VALID);
+ }
+}
+
/*
* Do 'incsearch' highlighting if desired.
*/
#ifdef FEAT_RELTIME
proftime_T tm;
#endif
- int c;
+ int next_char;
+ int use_last_pat;
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
+ {
+ finish_incsearch_highlighting(FALSE, is_state, TRUE);
return;
+ }
// If there is a character waiting, search and redraw later.
if (char_avail())
}
save_last_search_pattern();
- // If there is no command line, don't do anything.
- if (patlen == 0)
+ // Use the previous pattern for ":s//".
+ next_char = ccline.cmdbuff[skiplen + patlen];
+ use_last_pat = patlen == 0 && skiplen > 0
+ && ccline.cmdbuff[skiplen - 1] == next_char;
+
+ // If there is no pattern, don't do anything.
+ if (patlen == 0 && !use_last_pat)
{
i = 0;
set_no_hlsearch(TRUE); // turn off previous highlight
search_flags += SEARCH_KEEP;
if (search_first_line != 0)
search_flags += SEARCH_START;
- c = ccline.cmdbuff[skiplen + patlen];
ccline.cmdbuff[skiplen + patlen] = NUL;
i = do_search(NULL, firstc == ':' ? '/' : firstc,
ccline.cmdbuff + skiplen, count, search_flags,
NULL, NULL
#endif
);
- ccline.cmdbuff[skiplen + patlen] = c;
+ ccline.cmdbuff[skiplen + patlen] = next_char;
--emsg_off;
if (curwin->w_cursor.lnum < search_first_line
// Disable 'hlsearch' highlighting if the pattern matches everything.
// Avoids a flash when typing "foo\|".
- c = ccline.cmdbuff[skiplen + patlen];
- ccline.cmdbuff[skiplen + patlen] = NUL;
- if (empty_pattern(ccline.cmdbuff))
- set_no_hlsearch(TRUE);
- ccline.cmdbuff[skiplen + patlen] = c;
+ if (!use_last_pat)
+ {
+ next_char = ccline.cmdbuff[skiplen + patlen];
+ ccline.cmdbuff[skiplen + patlen] = NUL;
+ if (empty_pattern(ccline.cmdbuff))
+ set_no_hlsearch(TRUE);
+ ccline.cmdbuff[skiplen + patlen] = next_char;
+ }
validate_cursor();
// May redraw the status line to show the cursor position.
}
return OK;
}
-
- static void
-finish_incsearch_highlighting(int gotesc, incsearch_state_T *is_state)
-{
- if (is_state->did_incsearch)
- {
- if (gotesc)
- curwin->w_cursor = is_state->save_cursor;
- else
- {
- if (!EQUAL_POS(is_state->save_cursor, is_state->search_start))
- {
- // put the '" mark at the original position
- curwin->w_cursor = is_state->save_cursor;
- setpcmark();
- }
- curwin->w_cursor = is_state->search_start;
- }
- restore_viewstate(&is_state->old_viewstate);
- highlight_match = FALSE;
- validate_cursor(); /* needed for TAB */
- redraw_all_later(SOME_VALID);
- }
-}
#endif
/*
ccline.xpc = NULL;
#ifdef FEAT_SEARCH_EXTRA
- finish_incsearch_highlighting(gotesc, &is_state);
+ finish_incsearch_highlighting(gotesc, &is_state, FALSE);
#endif
if (ccline.cmdbuff != NULL)
sleep 100m
" Need to send one key at a time to force a redraw.
+ " Select three lines at the cursor with typed pattern.
call term_sendkeys(buf, ':.,.+2s/')
sleep 100m
call term_sendkeys(buf, 'f')
call term_sendkeys(buf, 'o')
sleep 100m
call term_sendkeys(buf, 'o')
+ sleep 100m
call VerifyScreenDump(buf, 'Test_incsearch_substitute_01', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ " Select three lines at the cursor using previous pattern.
+ call term_sendkeys(buf, "/foo\<CR>")
+ sleep 100m
+ call term_sendkeys(buf, ':.,.+2s//')
+ sleep 100m
+ call VerifyScreenDump(buf, 'Test_incsearch_substitute_02', {})
+
+ " Deleting last slash should remove the match.
+ call term_sendkeys(buf, "\<BS>")
+ sleep 100m
+ call VerifyScreenDump(buf, 'Test_incsearch_substitute_03', {})
call term_sendkeys(buf, "\<Esc>")
call StopVimInTerminal(buf)