neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit ccb5a76e5a2cc8627da6e3453697d2628ed0c6ac
parent 9b5f58185e1ff0597c7e95b7205d9ec11be1848c
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Tue,  1 Aug 2023 18:07:02 +0800

fix(defaults): don't use nvim_feedkeys in default mappings (#24520)

Problem:    Using nvim_feedkeys in default mappings makes it hard to use
            them as a part of another mapping.
Solution:   Use an expression mapping and stop Visual mode later.

Fix #24518.
Diffstat:
Mruntime/lua/vim/_editor.lua | 19++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua @@ -1016,8 +1016,13 @@ function vim._init_default_mappings() local function _visual_search(cmd) assert(cmd == '/' or cmd == '?') - vim.api.nvim_feedkeys('\27', 'nx', true) -- Escape visual mode. - local region = vim.region(0, "'<", "'>", vim.fn.visualmode(), vim.o.selection == 'inclusive') + local region = vim.region( + 0, + '.', + 'v', + vim.api.nvim_get_mode().mode:sub(1, 1), + vim.o.selection == 'inclusive' + ) local chunks = region_chunks(region) local esc_chunks = vim .iter(chunks) @@ -1027,7 +1032,7 @@ function vim._init_default_mappings() :totable() local esc_pat = table.concat(esc_chunks, [[\n]]) local search_cmd = ([[%s\V%s%s]]):format(cmd, esc_pat, '\n') - vim.api.nvim_feedkeys(search_cmd, 'nx', true) + return '\27' .. search_cmd end local function map(mode, lhs, rhs) @@ -1040,11 +1045,11 @@ function vim._init_default_mappings() map('i', '<C-U>', '<C-G>u<C-U>') map('i', '<C-W>', '<C-G>u<C-W>') vim.keymap.set('x', '*', function() - _visual_search('/') - end, { desc = ':help v_star-default', silent = true }) + return _visual_search('/') + end, { desc = ':help v_star-default', expr = true, silent = true }) vim.keymap.set('x', '#', function() - _visual_search('?') - end, { desc = ':help v_#-default', silent = true }) + return _visual_search('?') + end, { desc = ':help v_#-default', expr = true, silent = true }) -- Use : instead of <Cmd> so that ranges are supported. #19365 map('n', '&', ':&&<CR>')