diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/ex_cmds.c | 25 | ||||
| -rw-r--r-- | src/nvim/testdir/test_global.vim | 4 | 
2 files changed, 21 insertions, 8 deletions
| diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 23383abc57..c399d47b7e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3344,6 +3344,15 @@ static char_u *sub_parse_flags(char_u *cmd, subflags_T *subflags,    return cmd;  } +static int check_regexp_delim(int c) +  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT +{ +  if (isalpha(c)) { +    EMSG(_("E146: Regular expressions can't be delimited by letters")); +    return FAIL; +  } +  return OK; +}  /// 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: @@ -3408,16 +3417,14 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,    /* new pattern and substitution */    if (eap->cmd[0] == 's' && *cmd != NUL && !ascii_iswhite(*cmd)        && vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL) { -    /* don't accept alphanumeric for separator */ -    if (isalpha(*cmd)) { -      EMSG(_("E146: Regular expressions can't be delimited by letters")); +    // don't accept alphanumeric for separator +    if (check_regexp_delim(*cmd) == FAIL) {        return NULL;      } -    /* -     * undocumented vi feature: -     *  "\/sub/" and "\?sub?" use last used search pattern (almost like -     *  //sub/r).  "\&sub&" use last substitute pattern (like //sub/). -     */ + +    // undocumented vi feature: +    //  "\/sub/" and "\?sub?" use last used search pattern (almost like +    //  //sub/r).  "\&sub&" use last substitute pattern (like //sub/).      if (*cmd == '\\') {        ++cmd;        if (vim_strchr((char_u *)"/?&", *cmd) == NULL) { @@ -4455,6 +4462,8 @@ void ex_global(exarg_T *eap)    } else if (*cmd == NUL) {      EMSG(_("E148: Regular expression missing from global"));      return; +  } else if (check_regexp_delim(*cmd) == FAIL) { +    return;    } else {      delim = *cmd;               /* get the delimiter */      if (delim) diff --git a/src/nvim/testdir/test_global.vim b/src/nvim/testdir/test_global.vim index 2de2c412de..8edc9c2608 100644 --- a/src/nvim/testdir/test_global.vim +++ b/src/nvim/testdir/test_global.vim @@ -36,4 +36,8 @@ func Test_global_error()    call assert_fails('g/\(/y', 'E476:')  endfunc +func Test_wrong_delimiter() +  call assert_fails('g x^bxd', 'E146:') +endfunc +  " vim: shiftwidth=2 sts=2 expandtab | 
