diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-08-16 08:32:53 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2024-08-17 06:34:59 +0800 |
commit | a25dbeee10756a8f457d4632e8fda0c1cb509d61 (patch) | |
tree | 321260d40dec9db540d427bb2ce180e64aca64da /src/nvim/ex_cmds.c | |
parent | 4afd4061a23c60de26818bc3847e50c791a8f26c (diff) | |
download | rneovim-a25dbeee10756a8f457d4632e8fda0c1cb509d61.tar.gz rneovim-a25dbeee10756a8f457d4632e8fda0c1cb509d61.tar.bz2 rneovim-a25dbeee10756a8f457d4632e8fda0c1cb509d61.zip |
vim-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: vim/vim#15497
https://github.com/vim/vim/commit/3b59be4ed8a145d3188934f1a5cd85432bd2433d
Co-authored-by: Gregory Anders <greg@gpanders.com>
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r-- | src/nvim/ex_cmds.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 8c536d4838..5e87936be1 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3085,7 +3085,7 @@ void sub_set_replacement(SubReplacementString sub) /// /// @returns true if :substitute can be replaced with a join command static bool sub_joining_lines(exarg_T *eap, char *pat, size_t patlen, const char *sub, - const char *cmd, bool save) + const char *cmd, bool save, bool keeppatterns) FUNC_ATTR_NONNULL_ARG(1, 4, 5) { // TODO(vim): find a generic solution to make line-joining operations more @@ -3123,7 +3123,7 @@ static bool sub_joining_lines(exarg_T *eap, char *pat, size_t patlen, const char } if (save) { - if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0) { + if (!keeppatterns) { save_re_pat(RE_SUBST, pat, patlen, magic_isset()); } // put pattern in history @@ -3331,6 +3331,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n linenr_T old_line_count = curbuf->b_ml.ml_line_count; char *sub_firstline; // allocated copy of first sub line bool endcolumn = false; // cursor in last column when done + const bool keeppatterns = cmdmod.cmod_flags & CMOD_KEEPPATTERNS; PreviewLines preview_lines = { KV_INITIAL_VALUE, 0 }; static int pre_hl_id = 0; pos_T old_cursor = curwin->w_cursor; @@ -3391,7 +3392,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n cmd = skip_substitute(cmd, delimiter); sub = xstrdup(p); - if (!eap->skip && cmdpreview_ns <= 0) { + if (!eap->skip && !keeppatterns && cmdpreview_ns <= 0) { sub_set_replacement((SubReplacementString) { .sub = xstrdup(sub), .timestamp = os_time(), @@ -3412,7 +3413,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n endcolumn = (curwin->w_curswant == MAXCOL); } - if (sub != NULL && sub_joining_lines(eap, pat, patlen, sub, cmd, cmdpreview_ns <= 0)) { + if (sub != NULL && sub_joining_lines(eap, pat, patlen, sub, cmd, cmdpreview_ns <= 0, + keeppatterns)) { xfree(sub); return 0; } |