summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-05 21:13:26 +0000
committerBram Moolenaar <Bram@vim.org>2022-03-05 21:13:26 +0000
commit9fb7b42935f13b5d3407eb82b151da1e9b4b6048 (patch)
treeee717c21805958cca820cfba8e4d4256e7730fed
parentb2175220dafc28349b275ac7f3080f89cce78a57 (diff)
downloadvim-git-9fb7b42935f13b5d3407eb82b151da1e9b4b6048.tar.gz
patch 8.2.4515: old subsitute syntax is still supportedv8.2.4515
Problem: Old subsitute syntax is still supported. Solution: Disallow using backslash after ":s" in Vim9 script.
-rw-r--r--src/errors.h2
-rw-r--r--src/ex_cmds.c5
-rw-r--r--src/testdir/test_substitute.vim4
-rw-r--r--src/version.c2
4 files changed, 13 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h
index e302ecc6e..6f275fa41 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -3246,4 +3246,6 @@ EXTERN char e_cannot_use_s_colon_in_vim9_script_str[]
INIT(= N_("E1268: Cannot use s: in Vim9 script: %s"));
EXTERN char e_cannot_create_vim9_script_variable_in_function_str[]
INIT(= N_("E1269: Cannot create a Vim9 script variable in a function: %s"));
+EXTERN char e_cannot_use_s_backslash_in_vim9_script[]
+ INIT(= N_("E1270: Cannot use :s\\/sub/ in Vim9 script"));
#endif
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index d926df536..13cde84fd 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3737,6 +3737,11 @@ ex_substitute(exarg_T *eap)
*/
if (*cmd == '\\')
{
+ if (in_vim9script())
+ {
+ emsg(_(e_cannot_use_s_backslash_in_vim9_script));
+ return;
+ }
++cmd;
if (vim_strchr((char_u *)"/?&", *cmd) == NULL)
{
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
index 35b6b8a02..262274928 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -811,6 +811,10 @@ func Test_sub_vi_compatibility()
s\&green&
call assert_equal('amber green yellow white green', getline(1))
close!
+
+ call assert_fails('vim9cmd s\/white/', 'E1270:')
+ call assert_fails('vim9cmd s\?white?', 'E1270:')
+ call assert_fails('vim9cmd s\&white&', 'E1270:')
endfunc
" Test for substitute with the new text longer than the original text
diff --git a/src/version.c b/src/version.c
index 238e6278e..4bbe08ce7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4515,
+/**/
4514,
/**/
4513,