diff options
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r-- | src/nvim/ex_cmds.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 7f929eec3e..a1f0a123b1 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3468,7 +3468,6 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T static int pre_hl_id = 0; pos_T old_cursor = curwin->w_cursor; int start_nsubs; - int save_ma = 0; bool did_save = false; @@ -4060,7 +4059,8 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // there is a replace pattern. if (!cmdpreview || has_second_delim) { long lnum_start = lnum; // save the start lnum - save_ma = curbuf->b_p_ma; + int save_ma = curbuf->b_p_ma; + int save_sandbox = sandbox; if (subflags.do_count) { // prevent accidentally changing the buffer by a function curbuf->b_p_ma = false; @@ -4072,7 +4072,8 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // Disallow changing text or switching window in an expression. textlock++; - // get length of substitution part + // Get length of substitution part, including the NUL. + // When it fails sublen is zero. sublen = vim_regsub_multi(®match, sub_firstlnum - regmatch.startpos[0].lnum, (char_u *)sub, (char_u *)sub_firstline, 0, @@ -4083,11 +4084,9 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // the replacement. // Don't keep flags set by a recursive call subflags = subflags_save; - if (aborting() || subflags.do_count) { + if (sublen == 0 || aborting() || subflags.do_count) { curbuf->b_p_ma = save_ma; - if (sandbox > 0) { - sandbox--; - } + sandbox = save_sandbox; goto skip; } |