]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0677: :keepp does not retain the substitute pattern v9.1.0677
authorGregory Anders <greg@gpanders.com>
Thu, 15 Aug 2024 20:04:22 +0000 (22:04 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 15 Aug 2024 20:09:28 +0000 (22:09 +0200)
Problem:  :keeppatterns does not retain the substitute pattern
          for a :s command
Solution: preserve the last substitute pattern when used with the
          :keeppatterns command modifier (Gregory Anders)

closes: #15497

Signed-off-by: Gregory Anders <greg@gpanders.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/cmdline.txt
runtime/doc/version9.txt
src/ex_cmds.c
src/testdir/test_substitute.vim
src/version.c

index 214571f2893d29566166d5ece2b824c3297552b7..404e54de8c57d6f6051c432b724fddc52bbc3cc2 100644 (file)
@@ -1,4 +1,4 @@
-*cmdline.txt*   For Vim version 9.1.  Last change: 2024 Apr 27
+*cmdline.txt*   For Vim version 9.1.  Last change: 2024 Aug 15
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -379,7 +379,7 @@ terminals)
 
 :keepp[atterns] {command}                      *:keepp* *:keeppatterns*
                Execute {command}, without adding anything to the search
-               history
+               history or modifying the last substitute pattern.
 
 ==============================================================================
 2. Command-line completion                             *cmdline-completion*
index 73e54a1cf3551eb5915e496823376ea1b68de3b9..3729590fae7fde49abeb95257c65ad5ec649dacc 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2024 Jul 30
+*version9.txt*  For Vim version 9.1.  Last change: 2024 Aug 15
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41592,6 +41592,7 @@ Changed~
   mark deprecated attributes from LSP server) |complete-items|
 - the regex engines match correctly case-insensitive multi-byte characters
   (and apply proper case folding)
+- |:keeppatterns| preserves the last substitute pattern when used with |:s|
 
                                                        *added-9.2*
 Added ~
index 4793737560b330aa8214c5e91ed7490210e03643..05778c8fd8b9c6f38ff3225cd9eb221a6a96c31c 100644 (file)
@@ -3777,6 +3777,7 @@ ex_substitute(exarg_T *eap)
     int                endcolumn = FALSE;      // cursor in last column when done
     pos_T      old_cursor = curwin->w_cursor;
     int                start_nsubs;
+    int                keeppatterns = cmdmod.cmod_flags & CMOD_KEEPPATTERNS;
 #ifdef FEAT_EVAL
     int                save_ma = 0;
     int                save_sandbox = 0;
@@ -3876,7 +3877,7 @@ ex_substitute(exarg_T *eap)
                    // out of memory
                    return;
            }
-           else
+           else if (!keeppatterns)
            {
                vim_free(old_sub);
                old_sub = vim_strsave(sub);
@@ -3940,7 +3941,7 @@ ex_substitute(exarg_T *eap)
            ex_may_print(eap);
        }
 
-       if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0)
+       if (!keeppatterns)
            save_re_pat(RE_SUBST, pat, patlen, magic_isset());
        // put pattern in history
        add_to_history(HIST_SEARCH, pat, patlen, TRUE, NUL);
index afdc104d7c58c5bb13a5c3c6f38d8029528256e6..b25cd60803c354b4ef38518595bdcd2773d2bf67 100644 (file)
@@ -806,7 +806,7 @@ func Test_replace_keeppatterns()
   a
 foobar
 
-substitute foo asdf
+substitute foo asdf foo
 
 one two
 .
@@ -815,21 +815,26 @@ one two
   /^substitute
   s/foo/bar/
   call assert_equal('foo', @/)
-  call assert_equal('substitute bar asdf', getline('.'))
+  call assert_equal('substitute bar asdf foo', getline('.'))
 
   /^substitute
   keeppatterns s/asdf/xyz/
   call assert_equal('^substitute', @/)
-  call assert_equal('substitute bar xyz', getline('.'))
+  call assert_equal('substitute bar xyz foo', getline('.'))
+
+  /^substitute
+  &
+  call assert_equal('^substitute', @/)
+  call assert_equal('substitute bar xyz bar', getline('.'))
 
   exe "normal /bar /e\<CR>"
   call assert_equal(15, col('.'))
   normal -
   keeppatterns /xyz
   call assert_equal('bar ', @/)
-  call assert_equal('substitute bar xyz', getline('.'))
+  call assert_equal('substitute bar xyz bar', getline('.'))
   exe "normal 0dn"
-  call assert_equal('xyz', getline('.'))
+  call assert_equal('xyz bar', getline('.'))
 
   close!
 endfunc
index e4fb2caa06bcc3e6b39ee6a3a4db0169cb811fd9..78ccd20e5a1aa602f9e9878b68cc90c60f7df4b1 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    677,
 /**/
     676,
 /**/