diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-15 03:43:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-15 03:43:33 +0800 |
commit | aa1d0ac095dcc08b6069d716222739e83cbe051f (patch) | |
tree | 03b80415d539a8b601505a4bd8426bcd596b332b | |
parent | f6a3fdd6848d67dc54cebb6c297f8ebdc109c3a3 (diff) | |
download | rneovim-aa1d0ac095dcc08b6069d716222739e83cbe051f.tar.gz rneovim-aa1d0ac095dcc08b6069d716222739e83cbe051f.tar.bz2 rneovim-aa1d0ac095dcc08b6069d716222739e83cbe051f.zip |
fix(defaults): only repeat macro for each selected line if linewise (#28289)
As mentioned in #28287, repeating a macro for each selected line doesn't
really make sense in non-linewise Visual mode.
Fix #28287
-rw-r--r-- | runtime/doc/news.txt | 4 | ||||
-rw-r--r-- | runtime/doc/repeat.txt | 8 | ||||
-rw-r--r-- | runtime/doc/visual.txt | 8 | ||||
-rw-r--r-- | runtime/lua/vim/_defaults.lua | 9 | ||||
-rw-r--r-- | test/functional/editor/macro_spec.lua | 37 |
5 files changed, 15 insertions, 51 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 066a076377..15bdfb52f6 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -317,8 +317,8 @@ The following new APIs and features were added. • |nvim_input_mouse()| supports mouse buttons "x1" and "x2". -• |v_Q-default| and |v_@-default| repeat a register for each line of a visual - selection. +• |v_Q-default| and |v_@-default| repeat a register for each line of a linewise + visual selection. • |vim.diagnostic.count()| returns the number of diagnostics for a given buffer and/or namespace, by severity. This is a faster alternative to diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index ae827fa06f..2263b20d1a 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -149,8 +149,8 @@ q Stops recording. @@ Repeat the previous @{0-9a-z":*} [count] times. *v_@-default* -{Visual}@{0-9a-z".=*+} In Visual mode, execute the contents of the register -{Visual}@@ but for each selected line. +{Visual}@{0-9a-z".=*+} In linewise Visual mode, execute the contents of the +{Visual}@@ register for each selected line. See |visual-repeat|, |default-mappings|. *Q* @@ -158,8 +158,8 @@ Q Repeat the last recorded register [count] times. See |reg_recorded()|. *v_Q-default* -{Visual}Q In Visual mode, repeat the last recorded register for - each selected line. +{Visual}Q In linewise Visual mode, repeat the last recorded + register for each selected line. See |visual-repeat|, |default-mappings|. *:@* diff --git a/runtime/doc/visual.txt b/runtime/doc/visual.txt index a20fb6d31e..6d3aaa62dd 100644 --- a/runtime/doc/visual.txt +++ b/runtime/doc/visual.txt @@ -366,15 +366,15 @@ one of the last commands to extend the highlighted text, the repeating will be applied up to the rightmost column of the longest line. Any count passed to the `.` command is not used. -Visual mode |default-mappings| "@" and "Q" can repeat commands in a register -for all selected lines. See |v_@-default| and |v_Q-default| for details. For -example, given the text: +Visual mode |default-mappings| "@" and "Q" repeat a register for all selected +lines if the selection is linewise. See |v_@-default| and |v_Q-default| for +details. For example, given the text: 123(hello)321 456(world)654 456(NOT THIS)654 -With register "x" containing the commands `yi(VP`, Visually selecting the +With register "x" containing the commands `yi(VP`, visually selecting the first two lines and typing `@x` produces: hello diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 2afcc185e5..533ebbc7c3 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -78,19 +78,20 @@ do --- See |&-default| vim.keymap.set('n', '&', ':&&<CR>', { desc = ':help &-default' }) - --- Use Q in visual mode to execute a macro on each line of the selection. #21422 + --- Use Q in Visual mode to execute a macro on each line of the selection. #21422 + --- This only make sense in linewise Visual mode. #28287 --- --- Applies to @x and includes @@ too. vim.keymap.set( 'x', 'Q', - ':normal! @<C-R>=reg_recorded()<CR><CR>', - { silent = true, desc = ':help v_Q-default' } + "mode() == 'V' ? ':normal! @<C-R>=reg_recorded()<CR><CR>' : 'Q'", + { silent = true, expr = true, desc = ':help v_Q-default' } ) vim.keymap.set( 'x', '@', - "':normal! @'.getcharstr().'<CR>'", + "mode() == 'V' ? ':normal! @'.getcharstr().'<CR>' : '@'", { silent = true, expr = true, desc = ':help v_@-default' } ) diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua index a2a165ab0f..4e32e5b3af 100644 --- a/test/functional/editor/macro_spec.lua +++ b/test/functional/editor/macro_spec.lua @@ -131,43 +131,6 @@ helloFOO123 helloFOO]] end) - -- XXX: does this really make sense? - it('can be replayed with @ in blockwise Visual mode', function() - insert [[ -hello -hello -hello]] - feed [[gg]] - - feed [[qqAFOO<esc>qu]] - expect [[ -hello -hello -hello]] - - feed [[qwA123<esc>qu]] - expect [[ -hello -hello -hello]] - - feed [[<C-v>3j@q]] - expect [[ -helloFOO -helloFOO -helloFOO]] - - feed [[gg<C-v>j@w]] - expect [[ -helloFOO123 -helloFOO123 -helloFOO]] - end) -end) - -describe('macros without default mappings', function() - before_each(clear) - it('can be recorded and replayed in Visual mode', function() insert('foo BAR BAR foo BAR foo BAR BAR BAR foo BAR BAR') feed('0vqifofRq') |