0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 8.2.4242: put in Visual mode cannot be repeated

Problem:    Put in Visual mode cannot be repeated.
Solution:   Use "P" to put without yanking the deleted text into the unnamed
            register. (Shougo Matsushita, closes #9591)
This commit is contained in:
Shougo Matsushita
2022-01-28 16:01:13 +00:00
committed by Bram Moolenaar
parent 420fabcd4f
commit fb55207ed1
5 changed files with 43 additions and 10 deletions

View File

@@ -265,6 +265,7 @@ Additionally the following commands can be used:
X delete (2) |v_X| X delete (2) |v_X|
Y yank (2) |v_Y| Y yank (2) |v_Y|
p put |v_p| p put |v_p|
P put without unnamed register overwrite |v_P|
J join (1) |v_J| J join (1) |v_J|
U make uppercase |v_U| U make uppercase |v_U|
u make lowercase |v_u| u make lowercase |v_u|

View File

@@ -7505,6 +7505,8 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
int was_visual = FALSE; int was_visual = FALSE;
int dir; int dir;
int flags = 0; int flags = 0;
int save_unnamed = FALSE;
yankreg_T *old_y_current, *old_y_previous;
if (cap->oap->op_type != OP_NOP) if (cap->oap->op_type != OP_NOP)
{ {
@@ -7551,6 +7553,7 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
// overwrites if the old contents is being put. // overwrites if the old contents is being put.
was_visual = TRUE; was_visual = TRUE;
regname = cap->oap->regname; regname = cap->oap->regname;
save_unnamed = cap->cmdchar == 'P';
#ifdef FEAT_CLIPBOARD #ifdef FEAT_CLIPBOARD
adjust_clip_reg(&regname); adjust_clip_reg(&regname);
#endif #endif
@@ -7568,6 +7571,11 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
} }
// Now delete the selected text. Avoid messages here. // Now delete the selected text. Avoid messages here.
if (save_unnamed)
{
old_y_current = get_y_current();
old_y_previous = get_y_previous();
}
cap->cmdchar = 'd'; cap->cmdchar = 'd';
cap->nchar = NUL; cap->nchar = NUL;
cap->oap->regname = NUL; cap->oap->regname = NUL;
@@ -7577,6 +7585,12 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
empty = (curbuf->b_ml.ml_flags & ML_EMPTY); empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
--msg_silent; --msg_silent;
if (save_unnamed)
{
set_y_current(old_y_current);
set_y_previous(old_y_previous);
}
// delete PUT_LINE_BACKWARD; // delete PUT_LINE_BACKWARD;
cap->oap->regname = regname; cap->oap->regname = regname;

View File

@@ -54,37 +54,29 @@ get_y_register(int reg)
} }
#endif #endif
#if defined(FEAT_CLIPBOARD) || defined(FEAT_VIMINFO) || defined(FEAT_EVAL) || defined(PROTO)
yankreg_T * yankreg_T *
get_y_current(void) get_y_current(void)
{ {
return y_current; return y_current;
} }
#endif
#if defined(FEAT_CLIPBOARD) || defined(FEAT_VIMINFO) || defined(PROTO)
yankreg_T * yankreg_T *
get_y_previous(void) get_y_previous(void)
{ {
return y_previous; return y_previous;
} }
#endif
#if defined(FEAT_CLIPBOARD) || defined(PROTO)
void void
set_y_current(yankreg_T *yreg) set_y_current(yankreg_T *yreg)
{ {
y_current = yreg; y_current = yreg;
} }
#endif
#if defined(FEAT_CLIPBOARD) || defined(FEAT_VIMINFO) || defined(PROTO)
void void
set_y_previous(yankreg_T *yreg) set_y_previous(yankreg_T *yreg)
{ {
y_previous = yreg; y_previous = yreg;
} }
#endif
void void
reset_y_append(void) reset_y_append(void)

View File

@@ -1358,8 +1358,32 @@ func Test_visual_undo_deletes_last_line()
exe "normal ggvjfxO" exe "normal ggvjfxO"
undo undo
normal gNU normal gNU
bwipe! bwipe!
endfunc endfunc
func Test_visual_paste()
new
" v_p overwrites unnamed register.
call setline(1, ['xxxx'])
call setreg('"', 'foo')
call setreg('-', 'bar')
normal 1Gvp
call assert_equal(@", 'x')
call assert_equal(@-, 'x')
if has('clipboard')
" v_P does not overwrite unnamed register.
call setline(1, ['xxxx'])
call setreg('"', 'foo')
call setreg('-', 'bar')
normal 1GvP
call assert_equal(@", 'foo')
call assert_equal(@-, 'x')
endif
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -750,6 +750,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 */
/**/
4242,
/**/ /**/
4241, 4241,
/**/ /**/