Skip to content

Commit

Permalink
feat: define multiple keybindings for the same action (better for def…
Browse files Browse the repository at this point in the history
…aults)
  • Loading branch information
folke committed Apr 24, 2021
1 parent ecb9c09 commit bf8e8ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ Trouble comes with the following defaults:
fold_closed = "", -- icon used for closed folds
action_keys = { -- key mappings for actions in the trouble list
close = "q", -- close the list
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
refresh = "r", -- manually refresh
jump = "<cr>", -- jump to the diagnostic or open / close folds
jump = {"<cr>", "<tab>"}, -- jump to the diagnostic or open / close folds
toggle_mode = "m", -- toggle between "workspace" and "document" mode
toggle_preview = "P", -- toggle auto_preview
preview = "p", -- preview the diagnostic location
close_folds = "zM", -- close all folds
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
open_folds = "zR", -- open all folds
close_folds = {"zM", "zm"}, -- close all folds
open_folds = {"zR", "zr"}, -- open all folds
previous = "k", -- preview item
next = "j" -- next item
},
Expand Down
8 changes: 4 additions & 4 deletions lua/trouble/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ local defaults = {
fold_closed = "", -- icon used for closed folds
action_keys = { -- key mappings for actions in the trouble list
close = "q", -- close the list
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
refresh = "r", -- manually refresh
jump = "<cr>", -- jump to the diagnostic or open / close folds
jump = {"<cr>", "<tab>"}, -- jump to the diagnostic or open / close folds
toggle_mode = "m", -- toggle between "workspace" and "document" mode
toggle_preview = "P", -- toggle auto_preview
preview = "p", -- preview the diagnostic location
close_folds = "zM", -- close all folds
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
open_folds = "zR", -- open all folds
close_folds = {"zM", "zm"}, -- close all folds
open_folds = {"zR", "zr"}, -- open all folds
previous = "k", -- preview item
next = "j" -- next item
},
Expand Down
13 changes: 8 additions & 5 deletions lua/trouble/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@ function View:setup(opts)
self:set_option("foldenable", false, true)
self:set_option("winhighlight", "Normal:LspTroubleNormal", true)

for action, key in pairs(config.options.action_keys) do
vim.api.nvim_buf_set_keymap(self.buf, "n", key,
[[<cmd>lua require("trouble").action("]] ..
action .. [[")<cr>]],
{silent = true, noremap = true})
for action, keys in pairs(config.options.action_keys) do
if type(keys) == "string" then keys = {keys} end
for _, key in pairs(keys) do
vim.api.nvim_buf_set_keymap(self.buf, "n", key,
[[<cmd>lua require("trouble").action("]] ..
action .. [[")<cr>]],
{silent = true, noremap = true})
end
end

vim.api.nvim_win_set_height(self.win, config.options.height)
Expand Down

0 comments on commit bf8e8ee

Please sign in to comment.