'inccommand': rename 'incsubstitute'

'inccommand' allows us to expand the feature to other commands, such as:
    :cdo
    :cfdo
    :global

Also rename "IncSubstitute" highlight group to "Substitute".
This commit is contained in:
Justin M. Keyes
2016-11-07 00:59:32 +01:00
parent 1e0e301062
commit 6a3f8d48d0
10 changed files with 86 additions and 86 deletions

View File

@@ -3466,6 +3466,15 @@ A jump table for the options with a short description can be found at |Q_op|.
The value is set to 1 when it is not -1 and setting the 'keymap' The value is set to 1 when it is not -1 and setting the 'keymap'
option to a valid keymap name. option to a valid keymap name.
*'inccommand'* *'icm'*
'inccommand' 'icm' string (default "")
global
"nosplit" : Shows the effects of a command incrementally, as you type.
"split" : Also shows partial off-screen results in a preview window.
Currently only works for |:substitute|. |hl-Substitute|
*'include'* *'inc'* *'include'* *'inc'*
'include' 'inc' string (default "^\s*#\s*include") 'include' 'inc' string (default "^\s*#\s*include")
global or local to buffer |global-local| global or local to buffer |global-local|
@@ -3526,14 +3535,6 @@ A jump table for the options with a short description can be found at |Q_op|.
CTRL-R CTRL-W can be used to add the word at the end of the current CTRL-R CTRL-W can be used to add the word at the end of the current
match, excluding the characters that were already typed. match, excluding the characters that were already typed.
*'incsubstitute'* *'ics'*
'incsubstitute' 'ics' string (default "")
global
If "split" or "nosplit" then |:substitute| updates the buffer
as-you-type. If "split", also show partial off-screen results in
a window. Replacement text is hightlighted with |hl-IncSubstitute|.
*'indentexpr'* *'inde'* *'indentexpr'* *'inde'*
'indentexpr' 'inde' string (default "") 'indentexpr' 'inde' string (default "")
local to buffer local to buffer

View File

@@ -4852,8 +4852,9 @@ SignColumn column where |signs| are displayed
*hl-IncSearch* *hl-IncSearch*
IncSearch 'incsearch' highlighting; also used for the text replaced with IncSearch 'incsearch' highlighting; also used for the text replaced with
":s///c" ":s///c"
*hl-IncSubstitute* *hl-Substitute*
IncSubstitute 'incsubstitute' replacement text Substitute |:substitute| replacement text highlighting
*hl-LineNr* *hl-LineNr*
LineNr Line number for ":number" and ":#" commands, and when 'number' LineNr Line number for ":number" and ":#" commands, and when 'number'
or 'relativenumber' option is set. or 'relativenumber' option is set.

View File

@@ -107,7 +107,7 @@ Some `CTRL-SHIFT-...` key chords are distinguished from `CTRL-...` variants
<C-Tab>, <C-S-Tab>, <C-BS>, <C-S-BS>, <C-Enter>, <C-S-Enter> <C-Tab>, <C-S-Tab>, <C-BS>, <C-S-BS>, <C-Enter>, <C-S-Enter>
Options: Options:
'incsubstitute' shows results while typing a |:substitute| command 'inccommand' shows results while typing a |:substitute| command
'statusline' supports unlimited alignment sections 'statusline' supports unlimited alignment sections
'tabline' %@Func@foo%X can call any function on mouse-click 'tabline' %@Func@foo%X can call any function on mouse-click

View File

@@ -87,7 +87,7 @@ typedef struct {
SubIgnoreType do_ic; ///< ignore case flag SubIgnoreType do_ic; ///< ignore case flag
} subflags_T; } subflags_T;
/// Lines matched during 'incsubstitute'. /// Lines matched during :substitute.
typedef struct { typedef struct {
linenr_T lnum; linenr_T lnum;
long nmatch; long nmatch;
@@ -3110,7 +3110,7 @@ static char_u *sub_parse_flags(char_u *cmd, subflags_T *subflags,
/// ///
/// The usual escapes are supported as described in the regexp docs. /// The usual escapes are supported as described in the regexp docs.
/// ///
/// @return buffer used for 'incsubstitute' /// @return buffer used for 'inccommand' preview
buf_T *do_sub(exarg_T *eap) buf_T *do_sub(exarg_T *eap)
{ {
long i = 0; long i = 0;
@@ -3627,8 +3627,8 @@ buf_T *do_sub(exarg_T *eap)
* use "\=col("."). */ * use "\=col("."). */
curwin->w_cursor.col = regmatch.startpos[0].col; curwin->w_cursor.col = regmatch.startpos[0].col;
// 3. Substitute the string. During 'incsubstitute' only do this if // 3. Substitute the string. During 'inccommand' only do this if there
// there is a replace pattern. // is a replace pattern.
if (!eap->is_live || has_second_delim) { if (!eap->is_live || has_second_delim) {
if (subflags.do_count) { if (subflags.do_count) {
// prevent accidentally changing the buffer by a function // prevent accidentally changing the buffer by a function
@@ -3944,9 +3944,9 @@ skip:
subflags.do_all = save_do_all; subflags.do_all = save_do_all;
subflags.do_ask = save_do_ask; subflags.do_ask = save_do_ask;
// Show 'incsubstitute' preview if there are matched lines. // Show 'inccommand' preview if there are matched lines.
buf_T *incsub_buf = NULL; buf_T *preview_buf = NULL;
if (eap->is_live && matched_lines.size != 0 && pat != NULL && *p_ics != NUL) { if (eap->is_live && matched_lines.size != 0 && pat != NULL && *p_icm != NUL) {
// Place cursor on the first match after the cursor. (If all matches are // Place cursor on the first match after the cursor. (If all matches are
// above, then do_sub already placed cursor on the last match.) // above, then do_sub already placed cursor on the last match.)
colnr_T cur_col = -1; colnr_T cur_col = -1;
@@ -3971,10 +3971,9 @@ skip:
} }
} }
incsub_buf = incsub_display(pat, sub, eap->line1, eap->line2, preview_buf = show_sub(pat, sub, eap->line1, eap->line2, &matched_lines);
&matched_lines);
} else if (*p_ics != NUL && eap->is_live) { } else if (*p_icm != NUL && eap->is_live) {
curwin->w_cursor = old_cursor; // don't move the cursor curwin->w_cursor = old_cursor; // don't move the cursor
} }
@@ -3985,7 +3984,7 @@ skip:
} }
kv_destroy(matched_lines); kv_destroy(matched_lines);
return incsub_buf; return preview_buf;
} // NOLINT(readability/fn_size) } // NOLINT(readability/fn_size)
/* /*
@@ -6015,11 +6014,10 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
} }
} }
/// Shows a preview of :substitute (for 'incsubstitute'). /// Shows the effects of the current :substitute command being typed
/// With incsubstitute=split, shows a special buffer in a window, draws the /// ('inccommand'). If inccommand=split, shows a preview window then later
/// screen, then restores the layout. /// restores the layout.
static buf_T *incsub_display(char_u *pat, char_u *sub, static buf_T *show_sub(char_u *pat, char_u *sub, linenr_T line1, linenr_T line2,
linenr_T line1, linenr_T line2,
MatchedLineVec *matched_lines) MatchedLineVec *matched_lines)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
@@ -6033,27 +6031,27 @@ static buf_T *incsub_display(char_u *pat, char_u *sub,
size_t pat_size = mb_string2cells(pat); size_t pat_size = mb_string2cells(pat);
// We keep a special-purpose buffer around, but don't assume it exists. // We keep a special-purpose buffer around, but don't assume it exists.
buf_T *incsub_buf = bufnr ? buflist_findnr(bufnr) : 0; buf_T *preview_buf = bufnr ? buflist_findnr(bufnr) : 0;
win_size_save(&save_winsizes); // Save current window sizes. win_size_save(&save_winsizes); // Save current window sizes.
cmdmod.tab = 0; // disable :tab modifier cmdmod.tab = 0; // disable :tab modifier
cmdmod.noswapfile = true; // disable swap for 'incsubstitute' buffer cmdmod.noswapfile = true; // disable swap for preview buffer
// disable file info message // disable file info message
set_option_value((char_u *)"shm", 0L, (char_u *)"F", 0); set_option_value((char_u *)"shm", 0L, (char_u *)"F", 0);
bool outside_curline = (line1 != curwin->w_cursor.lnum bool outside_curline = (line1 != curwin->w_cursor.lnum
|| line2 != curwin->w_cursor.lnum); || line2 != curwin->w_cursor.lnum);
bool split = outside_curline && (*p_ics != 'n') && (sub_size || pat_size); bool split = outside_curline && (*p_icm != 'n') && (sub_size || pat_size);
if (incsub_buf == curbuf) { // Preview buffer cannot preview itself! if (preview_buf == curbuf) { // Preview buffer cannot preview itself!
split = false; split = false;
incsub_buf = NULL; preview_buf = NULL;
} }
if (split && win_split((int)p_cwh, WSP_BOT) != FAIL) { if (split && win_split((int)p_cwh, WSP_BOT) != FAIL) {
buf_open_special(incsub_buf ? bufnr : 0, "[Preview]", "incsub"); buf_open_special(preview_buf ? bufnr : 0, "[Preview]", "incsub");
buf_clear(); buf_clear();
incsub_buf = curbuf; preview_buf = curbuf;
set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL); set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL);
bufnr = incsub_buf->handle; bufnr = preview_buf->handle;
curbuf->b_p_bl = false; curbuf->b_p_bl = false;
curbuf->b_p_ma = true; curbuf->b_p_ma = true;
curbuf->b_p_ul = -1; curbuf->b_p_ul = -1;
@@ -6070,9 +6068,9 @@ static buf_T *incsub_display(char_u *pat, char_u *sub,
size_t old_line_size = 0; size_t old_line_size = 0;
size_t line_size; size_t line_size;
int src_id_highlight = 0; int src_id_highlight = 0;
int hl_id = syn_check_group((char_u *)"IncSubstitute", 13); int hl_id = syn_check_group((char_u *)"Substitute", 13);
// Dump the lines into the incsub buffer. // Dump the lines into the preview buffer.
for (size_t line = 0; line < matched_lines->size; line++) { for (size_t line = 0; line < matched_lines->size; line++) {
MatchedLine mat = matched_lines->items[line]; MatchedLine mat = matched_lines->items[line];
line_size = mb_string2cells(mat.line) + col_width + 1; line_size = mb_string2cells(mat.line) + col_width + 1;
@@ -6083,7 +6081,7 @@ static buf_T *incsub_display(char_u *pat, char_u *sub,
old_line_size = line_size; old_line_size = line_size;
} }
// put " | lnum|line" into str and append it to the incsubstitute buffer // put " | lnum|line" into str and append it to the preview buffer
snprintf(str, line_size, "|%*ld| %s", col_width - 3, mat.lnum, mat.line); snprintf(str, line_size, "|%*ld| %s", col_width - 3, mat.lnum, mat.line);
ml_append(line, (char_u *)str, (colnr_T)line_size, false); ml_append(line, (char_u *)str, (colnr_T)line_size, false);
@@ -6118,17 +6116,17 @@ static buf_T *incsub_display(char_u *pat, char_u *sub,
cmdmod = save_cmdmod; cmdmod = save_cmdmod;
return incsub_buf; return preview_buf;
} }
/// :substitute command /// :substitute command
/// ///
/// If 'incsubstitute' is empty, this just calls do_sub(). /// If 'inccommand' is empty this just calls do_sub().
/// If 'incsubstitute' is set, substitutes as-you-type ("live"). /// If 'inccommand' is set, shows a "live" preview then removes the changes
/// If the command is cancelled the changes are removed from undo history. /// from undo history.
void ex_substitute(exarg_T *eap) void ex_substitute(exarg_T *eap)
{ {
if (*p_ics == NUL || !eap->is_live) { // 'incsubstitute' is disabled if (*p_icm == NUL || !eap->is_live) { // 'inccommand' is disabled
(void)do_sub(eap); (void)do_sub(eap);
return; return;
} }
@@ -6138,18 +6136,18 @@ void ex_substitute(exarg_T *eap)
int save_changedtick = curbuf->b_changedtick; int save_changedtick = curbuf->b_changedtick;
long save_b_p_ul = curbuf->b_p_ul; long save_b_p_ul = curbuf->b_p_ul;
curbuf->b_p_ul = LONG_MAX; // make sure we can undo all changes curbuf->b_p_ul = LONG_MAX; // make sure we can undo all changes
block_autocmds(); // disable events before incsub opening window/buffer block_autocmds(); // disable events before show_sub() opens window/buffer
emsg_off++; // No error messages for live commands emsg_off++; // No error messages for live commands
buf_T *incsub_buf = do_sub(eap); buf_T *preview_buf = do_sub(eap);
if (save_changedtick != curbuf->b_changedtick if (save_changedtick != curbuf->b_changedtick
&& !u_undo_and_forget(1)) { && !u_undo_and_forget(1)) {
abort(); abort();
} }
if (buf_valid(incsub_buf)) { if (buf_valid(preview_buf)) {
// XXX: Must do this *after* u_undo_and_forget(), why? // XXX: Must do this *after* u_undo_and_forget(), why?
close_windows(incsub_buf, false); close_windows(preview_buf, false);
} }
curbuf->b_changedtick = save_changedtick; curbuf->b_changedtick = save_changedtick;
curbuf->b_p_ul = save_b_p_ul; curbuf->b_p_ul = save_b_p_ul;

View File

@@ -1592,7 +1592,7 @@ static int command_line_changed(CommandLineState *s)
redrawcmdline(); redrawcmdline();
s->did_incsearch = true; s->did_incsearch = true;
} else if (s->firstc == ':' } else if (s->firstc == ':'
&& *p_ics != NUL // 'incsubstitute' is set && *p_icm != NUL // 'inccommand' is set
&& cmdline_star == 0 // not typing a password && cmdline_star == 0 // not typing a password
&& cmd_is_live(ccline.cmdbuff)) { && cmd_is_live(ccline.cmdbuff)) {
// process a "live" command // process a "live" command

View File

@@ -288,7 +288,7 @@ static char *(p_fdm_values[]) = { "manual", "expr", "marker", "indent",
static char *(p_fcl_values[]) = { "all", NULL }; static char *(p_fcl_values[]) = { "all", NULL };
static char *(p_cot_values[]) = { "menu", "menuone", "longest", "preview", static char *(p_cot_values[]) = { "menu", "menuone", "longest", "preview",
"noinsert", "noselect", NULL }; "noinsert", "noselect", NULL };
static char *(p_ics_values[]) = { "nosplit", "split", NULL }; static char *(p_icm_values[]) = { "nosplit", "split", NULL };
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "option.c.generated.h" # include "option.c.generated.h"
@@ -3111,9 +3111,9 @@ did_set_string_option (
else if (gvarp == &p_cino) { else if (gvarp == &p_cino) {
/* TODO: recognize errors */ /* TODO: recognize errors */
parse_cino(curbuf); parse_cino(curbuf);
// incsubstitute // inccommand
} else if (varp == &p_ics) { } else if (varp == &p_icm) {
if (check_opt_strings(p_ics, p_ics_values, false) != OK) { if (check_opt_strings(p_icm, p_icm_values, false) != OK) {
errmsg = e_invarg; errmsg = e_invarg;
} }
// Options that are a list of flags. // Options that are a list of flags.

View File

@@ -470,6 +470,7 @@ EXTERN int p_icon; // 'icon'
EXTERN char_u *p_iconstring; // 'iconstring' EXTERN char_u *p_iconstring; // 'iconstring'
EXTERN int p_ic; // 'ignorecase' EXTERN int p_ic; // 'ignorecase'
EXTERN int p_is; // 'incsearch' EXTERN int p_is; // 'incsearch'
EXTERN char_u *p_icm; // 'inccommand'
EXTERN int p_im; // 'insertmode' EXTERN int p_im; // 'insertmode'
EXTERN char_u *p_isf; // 'isfname' EXTERN char_u *p_isf; // 'isfname'
EXTERN char_u *p_isi; // 'isident' EXTERN char_u *p_isi; // 'isident'
@@ -589,7 +590,6 @@ EXTERN int p_spr; // 'splitright'
EXTERN int p_sol; // 'startofline' EXTERN int p_sol; // 'startofline'
EXTERN char_u *p_su; // 'suffixes' EXTERN char_u *p_su; // 'suffixes'
EXTERN char_u *p_swb; // 'switchbuf' EXTERN char_u *p_swb; // 'switchbuf'
EXTERN char_u *p_ics; // 'incsubstitute'
EXTERN unsigned swb_flags; EXTERN unsigned swb_flags;
#ifdef IN_OPTION_C #ifdef IN_OPTION_C
static char *(p_swb_values[]) = static char *(p_swb_values[]) =

View File

@@ -1187,6 +1187,14 @@ return {
if_false={vi=macros('B_IMODE_NONE')}, if_false={vi=macros('B_IMODE_NONE')},
} }
}, },
{
full_name='inccommand', abbreviation='icm',
type='string', scope={'global'},
vi_def=true,
redraw={'everything'},
varname='p_icm',
defaults={if_true={vi=""}}
},
{ {
full_name='include', abbreviation='inc', full_name='include', abbreviation='inc',
type='string', scope={'global', 'buffer'}, type='string', scope={'global', 'buffer'},
@@ -1210,14 +1218,6 @@ return {
varname='p_is', varname='p_is',
defaults={if_true={vi=false, vim=true}} defaults={if_true={vi=false, vim=true}}
}, },
{
full_name='incsubstitute', abbreviation='ics',
type='string', scope={'global'},
vi_def=true,
redraw={'everything'},
varname='p_ics',
defaults={if_true={vi=""}}
},
{ {
full_name='indentexpr', abbreviation='inde', full_name='indentexpr', abbreviation='inde',
type='string', scope={'buffer'}, type='string', scope={'buffer'},

View File

@@ -5902,7 +5902,7 @@ static char *highlight_init_both[] =
"WildMenu ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black", "WildMenu ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black",
"default link EndOfBuffer NonText", "default link EndOfBuffer NonText",
"default link QuickFixLine Search", "default link QuickFixLine Search",
"default link IncSubstitute Search", "default link Substitute Search",
NULL NULL
}; };

View File

@@ -19,11 +19,11 @@ local default_text = [[
two lines two lines
]] ]]
local function common_setup(screen, incsub, text) local function common_setup(screen, inccommand, text)
if screen then if screen then
execute("syntax on") execute("syntax on")
execute("set nohlsearch") execute("set nohlsearch")
execute("hi IncSubstitute guifg=red guibg=yellow") execute("hi Substitute guifg=red guibg=yellow")
screen:attach() screen:attach()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {foreground = Screen.colors.Fuchsia}, [1] = {foreground = Screen.colors.Fuchsia},
@@ -45,14 +45,14 @@ local function common_setup(screen, incsub, text)
}) })
end end
execute("set incsubstitute=" .. (incsub and incsub or "")) execute("set inccommand=" .. (inccommand and inccommand or ""))
if text then if text then
insert(text) insert(text)
end end
end end
describe("'incsubstitute' preserves", function() describe(":substitute, 'inccommand' preserves", function()
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end
before_each(clear) before_each(clear)
@@ -82,7 +82,7 @@ describe("'incsubstitute' preserves", function()
for _, case in pairs{"", "split", "nosplit"} do for _, case in pairs{"", "split", "nosplit"} do
clear() clear()
insert(default_text) insert(default_text)
execute("set incsubstitute=" .. case) execute("set inccommand=" .. case)
local delims = { '/', '#', ';', '%', ',', '@', '!', ''} local delims = { '/', '#', ';', '%', ',', '@', '!', ''}
for _,delim in pairs(delims) do for _,delim in pairs(delims) do
@@ -101,7 +101,7 @@ describe("'incsubstitute' preserves", function()
clear() clear()
execute("set undolevels=139") execute("set undolevels=139")
execute("setlocal undolevels=34") execute("setlocal undolevels=34")
execute("set incsubstitute=" .. case) execute("set inccommand=" .. case)
insert("as") insert("as")
feed(":%s/as/glork/<enter>") feed(":%s/as/glork/<enter>")
eq(meths.get_option('undolevels'), 139) eq(meths.get_option('undolevels'), 139)
@@ -112,7 +112,7 @@ describe("'incsubstitute' preserves", function()
it("b:changedtick", function() it("b:changedtick", function()
for _, case in pairs{"", "split", "nosplit"} do for _, case in pairs{"", "split", "nosplit"} do
clear() clear()
execute("set incsubstitute=" .. case) execute("set inccommand=" .. case)
feed([[isome text 1<C-\><C-N>]]) feed([[isome text 1<C-\><C-N>]])
feed([[osome text 2<C-\><C-N>]]) feed([[osome text 2<C-\><C-N>]])
local expected_tick = eval("b:changedtick") local expected_tick = eval("b:changedtick")
@@ -130,7 +130,7 @@ describe("'incsubstitute' preserves", function()
end) end)
describe("'incsubstitute' preserves undo", function() describe(":substitute, 'inccommand' preserves undo", function()
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end
local cases = { "", "split", "nosplit" } local cases = { "", "split", "nosplit" }
@@ -155,7 +155,7 @@ describe("'incsubstitute' preserves undo", function()
local function test_sub(substring, split, redoable) local function test_sub(substring, split, redoable)
clear() clear()
execute("set incsubstitute=" .. split) execute("set inccommand=" .. split)
insert("1") insert("1")
feed("o2<esc>") feed("o2<esc>")
@@ -181,7 +181,7 @@ describe("'incsubstitute' preserves undo", function()
local function test_notsub(substring, split, redoable) local function test_notsub(substring, split, redoable)
clear() clear()
execute("set incsubstitute=" .. split) execute("set inccommand=" .. split)
insert("1") insert("1")
feed("o2<esc>") feed("o2<esc>")
@@ -215,7 +215,7 @@ describe("'incsubstitute' preserves undo", function()
local function test_threetree(substring, split) local function test_threetree(substring, split)
clear() clear()
execute("set incsubstitute=" .. split) execute("set inccommand=" .. split)
insert("1") insert("1")
feed("o2<esc>") feed("o2<esc>")
@@ -567,7 +567,7 @@ describe("'incsubstitute' preserves undo", function()
end) end)
describe("incsubstitute=split", function() describe(":substitute, inccommand=split", function()
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end
local screen = Screen.new(30,15) local screen = Screen.new(30,15)
@@ -841,7 +841,7 @@ describe("incsubstitute=split", function()
end) end)
describe("incsubstitute=nosplit", function() describe(":substitute, inccommand=nosplit", function()
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end
local screen = Screen.new(20,10) local screen = Screen.new(20,10)
@@ -917,7 +917,7 @@ describe("incsubstitute=nosplit", function()
end) end)
describe("'incsubstitute' with a failing expression", function() describe(":substitute, 'inccommand' with a failing expression", function()
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end
local screen = Screen.new(20,10) local screen = Screen.new(20,10)
@@ -931,7 +931,7 @@ describe("'incsubstitute' with a failing expression", function()
it('in the pattern does nothing for', function() it('in the pattern does nothing for', function()
for _, case in pairs(cases) do for _, case in pairs(cases) do
refresh(case) refresh(case)
execute("set incsubstitute=" .. case) execute("set inccommand=" .. case)
feed(":silent! %s/tw\\(/LARD/<enter>") feed(":silent! %s/tw\\(/LARD/<enter>")
expect(default_text) expect(default_text)
end end
@@ -943,7 +943,7 @@ describe("'incsubstitute' with a failing expression", function()
local replacements = { "\\='LARD", "\\=xx_novar__xx" } local replacements = { "\\='LARD", "\\=xx_novar__xx" }
for _, repl in pairs(replacements) do for _, repl in pairs(replacements) do
execute("set incsubstitute=" .. case) execute("set inccommand=" .. case)
feed(":silent! %s/tw/" .. repl .. "/<enter>") feed(":silent! %s/tw/" .. repl .. "/<enter>")
expect(default_text:gsub("tw", "")) expect(default_text:gsub("tw", ""))
execute("undo") execute("undo")
@@ -953,7 +953,7 @@ describe("'incsubstitute' with a failing expression", function()
end) end)
describe("'incsubstitute' and :cnoremap", function() describe("'inccommand' and :cnoremap", function()
local cases = { "", "split", "nosplit" } local cases = { "", "split", "nosplit" }
local function refresh(case) local function refresh(case)
@@ -1043,10 +1043,10 @@ describe("'incsubstitute' and :cnoremap", function()
end end
end) end)
it('work when a mapping disables incsub', function() it("work when a mapping disables 'inccommand'", function()
for _, case in pairs(cases) do for _, case in pairs(cases) do
refresh(case) refresh(case)
execute("cnoremap <expr> x execute('set incsubstitute=')[-1]") execute("cnoremap <expr> x execute('set inccommand=')[-1]")
feed(":%s/tw/toxa/g<enter>") feed(":%s/tw/toxa/g<enter>")
expect(default_text:gsub("tw", "toa")) expect(default_text:gsub("tw", "toa"))
@@ -1067,15 +1067,15 @@ describe("'incsubstitute' and :cnoremap", function()
end) end)
describe("'incsubstitute': autocommands", function() describe("'inccommand': autocommands", function()
before_each(clear) before_each(clear)
-- keys are events to be tested -- keys are events to be tested
-- values are arrays like -- values are arrays like
-- { open = { 1 }, close = { 2, 3} } -- { open = { 1 }, close = { 2, 3} }
-- which would mean that during the test below the event fires for -- which would mean that during the test below the event fires for
-- buffer 1 when opening an incsub window, and for buffers 2 and 3 -- buffer 1 when opening the preview window, and for buffers 2 and 3
-- when closing an incsub window -- when closing the preview window
local eventsExpected = { local eventsExpected = {
BufAdd = {}, BufAdd = {},
BufDelete = {}, BufDelete = {},
@@ -1155,7 +1155,7 @@ describe("'incsubstitute': autocommands", function()
end) end)
describe("'incsubstitute': split windows", function() describe("'inccommand': split windows", function()
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end
local screen local screen