Skip to content

Commit

Permalink
feat(defaults): visual CTRL-R for LSP mappings #28537
Browse files Browse the repository at this point in the history
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
  • Loading branch information
justinmk committed Apr 28, 2024
1 parent 513fc46 commit 6106365
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion runtime/doc/diagnostic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
6 changes: 4 additions & 2 deletions runtime/doc/lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()|

Expand Down
3 changes: 2 additions & 1 deletion runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions runtime/doc/vim_diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y".
- gcc |gcc-default|
- |crn|
- |crr|
- <C-R><C-R> |v_CTRL-R_CTRL-R|
- <C-R>r |v_CTRL-R_r|
- gr |gr-default|
- <C-S> |i_CTRL-S|
- ]d |]d-default|
Expand Down
11 changes: 8 additions & 3 deletions runtime/lua/vim/_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<C-R>r')
map_codeaction('x', '<C-R><C-R>')

vim.keymap.set('n', 'gr', function()
vim.lsp.buf.references()
Expand Down
2 changes: 1 addition & 1 deletion runtime/lua/vim/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down

0 comments on commit 6106365

Please sign in to comment.