Skip to content

Commit 56c917d

Browse files
committed
Include visual mode in LSP code action keymap (#1060)
1 parent 4e326fa commit 56c917d

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
@@ -279,7 +279,7 @@ require('lazy').setup({
279279

280280
-- Document existing key chains
281281
require('which-key').add {
282-
{ '<leader>c', group = '[C]ode' },
282+
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
283283
{ '<leader>d', group = '[D]ocument' },
284284
{ '<leader>r', group = '[R]ename' },
285285
{ '<leader>s', group = '[S]earch' },
@@ -470,8 +470,9 @@ require('lazy').setup({
470470
--
471471
-- In this case, we create a function that lets us more easily define mappings specific
472472
-- for LSP related items. It sets the mode, buffer and description for us each time.
473-
local map = function(keys, func, desc)
474-
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
473+
local map = function(keys, func, desc, mode)
474+
mode = mode or 'n'
475+
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
475476
end
476477

477478
-- Jump to the definition of the word under your cursor.
@@ -505,7 +506,7 @@ require('lazy').setup({
505506

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

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

0 commit comments

Comments
 (0)