Skip to content

Commit d452633

Browse files
authored
Include visual mode in LSP code action keymap (#1060) (#1064)
1 parent ac78e7d commit d452633

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

init.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ require('lazy').setup({
316316

317317
-- Document existing key chains
318318
require('which-key').add {
319-
{ '<leader>c', group = '[C]ode' },
319+
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
320320
{ '<leader>d', group = '[D]ocument' },
321321
{ '<leader>r', group = '[R]ename' },
322322
{ '<leader>s', group = '[S]earch' },
@@ -507,8 +507,9 @@ require('lazy').setup({
507507
--
508508
-- In this case, we create a function that lets us more easily define mappings specific
509509
-- for LSP related items. It sets the mode, buffer and description for us each time.
510-
local map = function(keys, func, desc)
511-
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
510+
local map = function(keys, func, desc, mode)
511+
mode = mode or 'n'
512+
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
512513
end
513514

514515
-- Jump to the definition of the word under your cursor.
@@ -542,7 +543,7 @@ require('lazy').setup({
542543

543544
-- Execute a code action, usually your cursor needs to be on top of an error
544545
-- or a suggestion from your LSP for this to activate.
545-
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
546+
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
546547

547548
-- WARN: This is not Goto Definition, this is Goto Declaration.
548549
-- For example, in C this would take you to the header.

0 commit comments

Comments
 (0)