mirror of
				https://github.com/vim/vim.git
				synced 2025-10-26 09:14:23 -04:00 
			
		
		
		
	patch 9.1.0677: :keepp does not retain the substitute pattern
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>
			
			
This commit is contained in:
		
				
					committed by
					
						 Christian Brabandt
						Christian Brabandt
					
				
			
			
				
	
			
			
			
						parent
						
							12cb1d1326
						
					
				
				
					commit
					3b59be4ed8
				
			| @@ -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 | 		  VIM REFERENCE MANUAL    by Bram Moolenaar | ||||||
| @@ -379,7 +379,7 @@ terminals) | |||||||
|  |  | ||||||
| :keepp[atterns] {command}			*:keepp* *:keeppatterns* | :keepp[atterns] {command}			*:keepp* *:keeppatterns* | ||||||
| 		Execute {command}, without adding anything to the search | 		Execute {command}, without adding anything to the search | ||||||
| 		history | 		history or modifying the last substitute pattern. | ||||||
|  |  | ||||||
| ============================================================================== | ============================================================================== | ||||||
| 2. Command-line completion				*cmdline-completion* | 2. Command-line completion				*cmdline-completion* | ||||||
|   | |||||||
| @@ -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 | 		  VIM REFERENCE MANUAL    by Bram Moolenaar | ||||||
| @@ -41592,6 +41592,7 @@ Changed~ | |||||||
|   mark deprecated attributes from LSP server) |complete-items| |   mark deprecated attributes from LSP server) |complete-items| | ||||||
| - the regex engines match correctly case-insensitive multi-byte characters | - the regex engines match correctly case-insensitive multi-byte characters | ||||||
|   (and apply proper case folding) |   (and apply proper case folding) | ||||||
|  | - |:keeppatterns| preserves the last substitute pattern when used with |:s| | ||||||
| 
 | 
 | ||||||
| 							*added-9.2* | 							*added-9.2* | ||||||
| Added ~ | Added ~ | ||||||
|   | |||||||
| @@ -3777,6 +3777,7 @@ ex_substitute(exarg_T *eap) | |||||||
|     int		endcolumn = FALSE;	// cursor in last column when done |     int		endcolumn = FALSE;	// cursor in last column when done | ||||||
|     pos_T	old_cursor = curwin->w_cursor; |     pos_T	old_cursor = curwin->w_cursor; | ||||||
|     int		start_nsubs; |     int		start_nsubs; | ||||||
|  |     int		keeppatterns = cmdmod.cmod_flags & CMOD_KEEPPATTERNS; | ||||||
| #ifdef FEAT_EVAL | #ifdef FEAT_EVAL | ||||||
|     int		save_ma = 0; |     int		save_ma = 0; | ||||||
|     int		save_sandbox = 0; |     int		save_sandbox = 0; | ||||||
| @@ -3876,7 +3877,7 @@ ex_substitute(exarg_T *eap) | |||||||
| 		    // out of memory | 		    // out of memory | ||||||
| 		    return; | 		    return; | ||||||
| 	    } | 	    } | ||||||
| 	    else | 	    else if (!keeppatterns) | ||||||
| 	    { | 	    { | ||||||
| 		vim_free(old_sub); | 		vim_free(old_sub); | ||||||
| 		old_sub = vim_strsave(sub); | 		old_sub = vim_strsave(sub); | ||||||
| @@ -3940,7 +3941,7 @@ ex_substitute(exarg_T *eap) | |||||||
| 	    ex_may_print(eap); | 	    ex_may_print(eap); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0) | 	if (!keeppatterns) | ||||||
| 	    save_re_pat(RE_SUBST, pat, patlen, magic_isset()); | 	    save_re_pat(RE_SUBST, pat, patlen, magic_isset()); | ||||||
| 	// put pattern in history | 	// put pattern in history | ||||||
| 	add_to_history(HIST_SEARCH, pat, patlen, TRUE, NUL); | 	add_to_history(HIST_SEARCH, pat, patlen, TRUE, NUL); | ||||||
|   | |||||||
| @@ -806,7 +806,7 @@ func Test_replace_keeppatterns() | |||||||
|   a |   a | ||||||
| foobar | foobar | ||||||
|  |  | ||||||
| substitute foo asdf | substitute foo asdf foo | ||||||
|  |  | ||||||
| one two | one two | ||||||
| . | . | ||||||
| @@ -815,21 +815,26 @@ one two | |||||||
|   /^substitute |   /^substitute | ||||||
|   s/foo/bar/ |   s/foo/bar/ | ||||||
|   call assert_equal('foo', @/) |   call assert_equal('foo', @/) | ||||||
|   call assert_equal('substitute bar asdf', getline('.')) |   call assert_equal('substitute bar asdf foo', getline('.')) | ||||||
|  |  | ||||||
|   /^substitute |   /^substitute | ||||||
|   keeppatterns s/asdf/xyz/ |   keeppatterns s/asdf/xyz/ | ||||||
|   call assert_equal('^substitute', @/) |   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>" |   exe "normal /bar /e\<CR>" | ||||||
|   call assert_equal(15, col('.')) |   call assert_equal(15, col('.')) | ||||||
|   normal - |   normal - | ||||||
|   keeppatterns /xyz |   keeppatterns /xyz | ||||||
|   call assert_equal('bar ', @/) |   call assert_equal('bar ', @/) | ||||||
|   call assert_equal('substitute bar xyz', getline('.')) |   call assert_equal('substitute bar xyz bar', getline('.')) | ||||||
|   exe "normal 0dn" |   exe "normal 0dn" | ||||||
|   call assert_equal('xyz', getline('.')) |   call assert_equal('xyz bar', getline('.')) | ||||||
|  |  | ||||||
|   close! |   close! | ||||||
| endfunc | endfunc | ||||||
|   | |||||||
| @@ -704,6 +704,8 @@ static char *(features[]) = | |||||||
|  |  | ||||||
| static int included_patches[] = | static int included_patches[] = | ||||||
| {   /* Add new patch number below this line */ | {   /* Add new patch number below this line */ | ||||||
|  | /**/ | ||||||
|  |     677, | ||||||
| /**/ | /**/ | ||||||
|     676, |     676, | ||||||
| /**/ | /**/ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user