To: vim_dev@googlegroups.com Subject: Patch 8.2.4881 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4881 Problem: "P" in Visual mode still changes some registers. Solution: Make "P" in Visual mode not change any register. (Shougo Matsushita, closes #10349) Files: runtime/doc/change.txt, runtime/doc/index.txt, runtime/doc/visual.txt, src/normal.c, src/testdir/test_visual.vim *** ../vim-8.2.4880/runtime/doc/change.txt 2021-06-10 18:39:07.273697695 +0100 --- runtime/doc/change.txt 2022-05-06 11:34:59.744449217 +0100 *************** *** 1162,1181 **** and whether the corners are on an existing character. (Implementation detail: it actually works by first putting the register after the selection and then deleting the selection.) ! The previously selected text is put in the unnamed register. If you want to ! put the same text into a Visual selection several times you need to use ! another register. E.g., yank the text to copy, Visually select the text to ! replace and use "0p . You can repeat this as many times as you like, the ! unnamed register will be changed each time. When you use a blockwise Visual mode command and yank only a single line into a register, a paste on a visual selected area will paste that single line on each of the selected lines (thus replacing the blockwise selected region by a block of the pasted line). - Use |zP|/|zp| to paste a blockwise yanked register without appending trailing - spaces. - *blockwise-register* If you use a blockwise Visual mode command to get the text into the register, the block of text will be inserted before ("P") or after ("p") the cursor --- 1177,1197 ---- and whether the corners are on an existing character. (Implementation detail: it actually works by first putting the register after the selection and then deleting the selection.) ! With |p| the previously selected text is put in the unnamed register (and ! possibly the selection and/or clipboard). This is useful if you want to put ! that text somewhere else. But you cannot repeat the same change. ! With |P| the unnamed register is not changed (and neither the selection or ! clipboard), you can repeat the same change. But the deleted text cannot be ! used. If you do need it you can use |p| with another register. E.g., yank ! the text to copy, Visually select the text to replace and use "0p . You can ! repeat this as many times as you like, and the unnamed register will be ! changed each time. When you use a blockwise Visual mode command and yank only a single line into a register, a paste on a visual selected area will paste that single line on each of the selected lines (thus replacing the blockwise selected region by a block of the pasted line). *blockwise-register* If you use a blockwise Visual mode command to get the text into the register, the block of text will be inserted before ("P") or after ("p") the cursor *** ../vim-8.2.4880/runtime/doc/index.txt 2021-12-24 20:27:58.029861532 +0000 --- runtime/doc/index.txt 2022-05-06 11:30:09.288695521 +0100 *************** *** 937,943 **** before the highlighted area |v_J| J 2 join the highlighted lines |v_K| K run 'keywordprg' on the highlighted area ! |v_O| O Move horizontally to other corner of area. Q does not start Ex mode |v_R| R 2 delete the highlighted lines and start insert --- 937,945 ---- before the highlighted area |v_J| J 2 join the highlighted lines |v_K| K run 'keywordprg' on the highlighted area ! |v_O| O move horizontally to other corner of area ! |v_P| P replace highlighted area with register ! contents; registers are unchanged Q does not start Ex mode |v_R| R 2 delete the highlighted lines and start insert *************** *** 1000,1005 **** --- 1002,1009 ---- |v_i{| i{ same as iB |v_i}| i} same as iB |v_o| o move cursor to other corner of area + |v_p| p replace highlighted area with register + contents; deleted text in unnamed register |v_r| r 2 replace highlighted area with a character |v_s| s 2 delete highlighted area and start insert |v_u| u 2 make highlighted area lowercase *** ../vim-8.2.4880/runtime/doc/visual.txt 2022-01-28 16:01:09.548028394 +0000 --- runtime/doc/visual.txt 2022-05-06 11:35:52.948402958 +0100 *************** *** 265,271 **** X delete (2) |v_X| Y yank (2) |v_Y| p put |v_p| ! P put without unnamed register overwrite |v_P| J join (1) |v_J| U make uppercase |v_U| u make lowercase |v_u| --- 265,271 ---- X delete (2) |v_X| Y yank (2) |v_Y| p put |v_p| ! P put without overwriting registers |v_P| J join (1) |v_J| U make uppercase |v_U| u make lowercase |v_u| *** ../vim-8.2.4880/src/normal.c 2022-04-22 21:20:22.825092774 +0100 --- src/normal.c 2022-05-06 11:30:09.288695521 +0100 *************** *** 7236,7243 **** int was_visual = FALSE; int dir; int flags = 0; ! int save_unnamed = FALSE; ! yankreg_T *old_y_current, *old_y_previous; if (cap->oap->op_type != OP_NOP) { --- 7236,7242 ---- int was_visual = FALSE; int dir; int flags = 0; ! int keep_registers = FALSE; if (cap->oap->op_type != OP_NOP) { *************** *** 7284,7290 **** // overwrites if the old contents is being put. was_visual = TRUE; regname = cap->oap->regname; ! save_unnamed = cap->cmdchar == 'P'; #ifdef FEAT_CLIPBOARD adjust_clip_reg(®name); #endif --- 7283,7289 ---- // overwrites if the old contents is being put. was_visual = TRUE; regname = cap->oap->regname; ! keep_registers = cap->cmdchar == 'P'; #ifdef FEAT_CLIPBOARD adjust_clip_reg(®name); #endif *************** *** 7302,7327 **** } // 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->nchar = NUL; ! cap->oap->regname = NUL; ++msg_silent; nv_operator(cap); do_pending_operator(cap, 0, FALSE); empty = (curbuf->b_ml.ml_flags & ML_EMPTY); --msg_silent; - if (save_unnamed) - { - set_y_current(old_y_current); - set_y_previous(old_y_previous); - } - // delete PUT_LINE_BACKWARD; cap->oap->regname = regname; --- 7301,7315 ---- } // Now delete the selected text. Avoid messages here. cap->cmdchar = 'd'; cap->nchar = NUL; ! cap->oap->regname = keep_registers ? '_' : NUL; ++msg_silent; nv_operator(cap); do_pending_operator(cap, 0, FALSE); empty = (curbuf->b_ml.ml_flags & ML_EMPTY); --msg_silent; // delete PUT_LINE_BACKWARD; cap->oap->regname = regname; *** ../vim-8.2.4880/src/testdir/test_visual.vim 2022-02-07 10:33:15.412898083 +0000 --- src/testdir/test_visual.vim 2022-05-06 11:30:09.292695517 +0100 *************** *** 1390,1423 **** call assert_equal('x', @-) call assert_equal('bazooxxf', getline(1)) ! if has('clipboard') ! " v_P does not overwrite unnamed register. call setline(1, ['xxxx']) call setreg('"', 'foo') call setreg('-', 'bar') normal gg0vP call assert_equal('foo', @") ! call assert_equal('x', @-) ! call assert_equal('fooxxx', getline(1)) ! normal $vP ! call assert_equal('foo', @") ! call assert_equal('x', @-) ! call assert_equal('fooxxfoo', getline(1)) ! " Test with a different register as unnamed register. ! call setline(2, ['baz']) ! normal 2gg0"rD ! call assert_equal('baz', @") ! normal gg0vP ! call assert_equal('baz', @") ! call assert_equal('f', @-) ! call assert_equal('bazooxxfoo', getline(1)) ! normal $vP ! call assert_equal('baz', @") ! call assert_equal('o', @-) ! call assert_equal('bazooxxfobaz', getline(1)) endif bwipe! endfunc " vim: shiftwidth=2 sts=2 expandtab --- 1390,1463 ---- call assert_equal('x', @-) call assert_equal('bazooxxf', getline(1)) ! bwipe! ! endfunc ! ! func Test_visual_paste_clipboard() ! CheckFeature clipboard_working ! ! if has('gui') ! " auto select feature breaks tests ! set guioptions-=a ! endif ! ! " v_P does not overwrite unnamed register. ! call setline(1, ['xxxx']) ! call setreg('"', 'foo') ! call setreg('-', 'bar') ! normal gg0vP ! call assert_equal('foo', @") ! call assert_equal('bar', @-) ! call assert_equal('fooxxx', getline(1)) ! normal $vP ! call assert_equal('foo', @") ! call assert_equal('bar', @-) ! call assert_equal('fooxxfoo', getline(1)) ! " Test with a different register as unnamed register. ! call setline(2, ['baz']) ! normal 2gg0"rD ! call assert_equal('baz', @") ! normal gg0vP ! call assert_equal('baz', @") ! call assert_equal('bar', @-) ! call assert_equal('bazooxxfoo', getline(1)) ! normal $vP ! call assert_equal('baz', @") ! call assert_equal('bar', @-) ! call assert_equal('bazooxxfobaz', getline(1)) ! ! " Test for unnamed clipboard ! set clipboard=unnamed ! call setline(1, ['xxxx']) ! call setreg('"', 'foo') ! call setreg('-', 'bar') ! call setreg('*', 'baz') ! normal gg0vP ! call assert_equal('foo', @") ! call assert_equal('bar', @-) ! call assert_equal('baz', @*) ! call assert_equal('bazxxx', getline(1)) ! ! " Test for unnamedplus clipboard ! if has('unnamedplus') ! set clipboard=unnamedplus call setline(1, ['xxxx']) call setreg('"', 'foo') call setreg('-', 'bar') + call setreg('+', 'baz') normal gg0vP call assert_equal('foo', @") ! call assert_equal('bar', @-) ! call assert_equal('baz', @+) ! call assert_equal('bazxxx', getline(1)) endif + set clipboard& + if has('gui') + set guioptions& + endif bwipe! endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.4880/src/version.c 2022-05-06 11:27:48.264809846 +0100 --- src/version.c 2022-05-06 11:32:25.396581569 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4881, /**/ -- hundred-and-one symptoms of being an internet addict: 112. You are amazed that anyone uses a phone without data...let alone hear actual voices. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///