From 7ca0408a1fe9c4cd33f2d05f7b1868e808ed9689 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 5 Dec 2024 19:03:58 +0800 Subject: [PATCH] fix(defaults): don't replace keycodes in Visual search mappings (#31460) Also remove "silent" to be more consistent with Normal mode search. --- runtime/lua/vim/_defaults.lua | 4 +- test/functional/editor/defaults_spec.lua | 81 ++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 test/functional/editor/defaults_spec.lua diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index dacf0ceee2..6bd83e3861 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -49,10 +49,10 @@ do vim.keymap.set('x', '*', function() return _visual_search('/') - end, { desc = ':help v_star-default', expr = true, silent = true }) + end, { desc = ':help v_star-default', expr = true, replace_keycodes = false }) vim.keymap.set('x', '#', function() return _visual_search('?') - end, { desc = ':help v_#-default', expr = true, silent = true }) + end, { desc = ':help v_#-default', expr = true, replace_keycodes = false }) end --- Map Y to y$. This mimics the behavior of D and C. See |Y-default| diff --git a/test/functional/editor/defaults_spec.lua b/test/functional/editor/defaults_spec.lua new file mode 100644 index 0000000000..6f3e4b2c23 --- /dev/null +++ b/test/functional/editor/defaults_spec.lua @@ -0,0 +1,81 @@ +-- +-- Tests for default autocmds, mappings, commands, and menus. +-- +-- See options/defaults_spec.lua for default options and environment decisions. +-- + +local n = require('test.functional.testnvim')() +local Screen = require('test.functional.ui.screen') + +describe('default', function() + describe('key mappings', function() + describe('Visual mode search mappings', function() + it('handle various chars properly', function() + n.clear({ args_rm = { '--cmd' } }) + local screen = Screen.new(60, 8) + screen:attach() + screen:set_default_attr_ids({ + [1] = { foreground = Screen.colors.NvimDarkGray4 }, + [2] = { + foreground = Screen.colors.NvimDarkGray3, + background = Screen.colors.NvimLightGray3, + }, + [3] = { + foreground = Screen.colors.NvimLightGrey1, + background = Screen.colors.NvimDarkYellow, + }, + [4] = { + foreground = Screen.colors.NvimDarkGrey1, + background = Screen.colors.NvimLightYellow, + }, + }) + n.api.nvim_buf_set_lines(0, 0, -1, true, { + [[testing /?\!1]], + [[testing /?\!2]], + [[testing /?\!3]], + [[testing /?\!4]], + }) + n.feed('gg0vf!o*') + screen:expect([[ + {3:testing /?\!}1 | + {4:^testing /?\!}2 | + {3:testing /?\!}3 | + {3:testing /?\!}4 | + {1:~ }|*2 + {2:[No Name] [+] 2,1 All}| + /\Vtesting \/?\\! [2/4] | + ]]) + n.feed('n') + screen:expect([[ + {3:testing /?\!}1 | + {3:testing /?\!}2 | + {4:^testing /?\!}3 | + {3:testing /?\!}4 | + {1:~ }|*2 + {2:[No Name] [+] 3,1 All}| + /\Vtesting \/?\\! [3/4] | + ]]) + n.feed('G0vf!o#') + screen:expect([[ + {3:testing /?\!}1 | + {3:testing /?\!}2 | + {4:^testing /?\!}3 | + {3:testing /?\!}4 | + {1:~ }|*2 + {2:[No Name] [+] 3,1 All}| + ?\Vtesting /?\\! [3/4] | + ]]) + n.feed('n') + screen:expect([[ + {3:testing /?\!}1 | + {4:^testing /?\!}2 | + {3:testing /?\!}3 | + {3:testing /?\!}4 | + {1:~ }|*2 + {2:[No Name] [+] 2,1 All}| + ?\Vtesting /?\\! [2/4] | + ]]) + end) + end) + end) +end)