From 61063653b06bfccac083c0105ecd0c433b3bb8f7 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 28 Apr 2024 09:02:18 -0700 Subject: [PATCH] feat(defaults): visual CTRL-R for LSP mappings #28537 Problem: The new LSP "refactor menu" keybinding "crr" is also defined in visual mode, which overlaps with the builtin "c". Solution: Use CTRL-R instead of "crr" for visual mode. fix #28528 --- runtime/doc/diagnostic.txt | 2 +- runtime/doc/lsp.txt | 6 ++++-- runtime/doc/news.txt | 3 ++- runtime/doc/vim_diff.txt | 2 ++ runtime/lua/vim/_defaults.lua | 11 ++++++++--- runtime/lua/vim/diagnostic.lua | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt index b87de3e366..4958dcfe67 100644 --- a/runtime/doc/diagnostic.txt +++ b/runtime/doc/diagnostic.txt @@ -499,7 +499,7 @@ Lua module: vim.diagnostic *diagnostic-api* diagnostic instead of prepending it. Overrides the setting from |vim.diagnostic.config()|. • {focus_id}? (`string`) - • {border}? (`string`) see |vim.api.nvim_open_win()|. + • {border}? (`string`) see |nvim_open_win()|. *vim.diagnostic.Opts.Signs* diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 5a98d32628..3017329506 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -61,10 +61,12 @@ options are not restored when the LSP client is stopped or detached. - |K| is mapped to |vim.lsp.buf.hover()| unless |'keywordprg'| is customized or a custom keymap for `K` exists. - *crr* *v_crr* *crn* *i_CTRL-S* + *crr* *v_crr* *crn* *i_CTRL-S* *v_CTRL-R_CTRL-R* *v_CTRL-R_r* Some keymaps are created unconditionally when Nvim starts: - "crn" is mapped in Normal mode to |vim.lsp.buf.rename()| -- "crr" is mapped in Normal and Visual mode to |vim.lsp.buf.code_action()| +- "crr" is mapped in Normal mode to |vim.lsp.buf.code_action()| +- CTRL-R CTRL-R (also "CTRL-R r") is mapped in Visual mode to + |vim.lsp.buf.code_action()| - "gr" is mapped in Normal mode to |vim.lsp.buf.references()| |gr-default| - CTRL-S is mapped in Insert mode to |vim.lsp.buf.signature_help()| diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 1da81e3422..700aba31b9 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -410,7 +410,8 @@ The following changes to existing APIs or features add new behavior. • 'grepprg' uses the -H and -I flags for grep by default, and defaults to using ripgrep if available. • |crn| in Normal mode maps to |vim.lsp.buf.rename()|. - • |crr| in Normal and Visual mode maps to |vim.lsp.buf.code_action()|. + • |crr| in Normal mode maps to |vim.lsp.buf.code_action()|. + • |v_CTRL-R_CTRL-R| in Visual mode maps to |vim.lsp.buf.code_action()|. • "gr" in Normal mode maps to |vim.lsp.buf.references()| |gr-default| • |i_CTRL-S| in Insert mode maps to |vim.lsp.buf.signature_help()| • "]d" and "[d" in Normal mode map to |vim.diagnostic.goto_next()| and diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 97c25cc603..c30239057d 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -140,6 +140,8 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y". - gcc |gcc-default| - |crn| - |crr| +- |v_CTRL-R_CTRL-R| +- r |v_CTRL-R_r| - gr |gr-default| - |i_CTRL-S| - ]d |]d-default| diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 7166f7a23c..1094f22793 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -159,9 +159,14 @@ do vim.lsp.buf.rename() end, { desc = 'vim.lsp.buf.rename()' }) - vim.keymap.set({ 'n', 'v' }, 'crr', function() - vim.lsp.buf.code_action() - end, { desc = 'vim.lsp.buf.code_action()' }) + local function map_codeaction(mode, lhs) + vim.keymap.set(mode, lhs, function() + vim.lsp.buf.code_action() + end, { desc = 'vim.lsp.buf.code_action()' }) + end + map_codeaction('n', 'crr') + map_codeaction('x', 'r') + map_codeaction('x', '') vim.keymap.set('n', 'gr', function() vim.lsp.buf.references() diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 1ed09b51a5..b34541c72e 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -153,7 +153,7 @@ local M = {} --- --- @field focus_id? string --- ---- @field border? string see |vim.api.nvim_open_win()|. +--- @field border? string see |nvim_open_win()|. --- @class vim.diagnostic.Opts.Underline ---