diff options
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r-- | src/ex_cmds.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 6cd54d20ce..96ff6ecba6 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -3604,6 +3604,29 @@ typedef struct { } subflags_T; /* + * Skip over the "sub" part in :s/pat/sub/ where "delimiter" is the separating + * character. + */ + char_u * +skip_substitute(char_u *start, int delimiter) +{ + char_u *p = start; + + while (p[0]) + { + if (p[0] == delimiter) // end delimiter found + { + *p++ = NUL; // replace it with a NUL + break; + } + if (p[0] == '\\' && p[1] != 0) // skip escaped characters + ++p; + MB_PTR_ADV(p); + } + return p; +} + +/* * Perform a substitution from line eap->line1 to line eap->line2 using the * command pointed to by eap->arg which should be of the form: * @@ -3704,18 +3727,7 @@ ex_substitute(exarg_T *eap) * Vim we want to use '\n' to find/substitute a NUL. */ sub = cmd; // remember the start of the substitution - - while (cmd[0]) - { - if (cmd[0] == delimiter) // end delimiter found - { - *cmd++ = NUL; // replace it with a NUL - break; - } - if (cmd[0] == '\\' && cmd[1] != 0) // skip escaped characters - ++cmd; - MB_PTR_ADV(cmd); - } + cmd = skip_substitute(cmd, delimiter); if (!eap->skip) { |