Skip to content

Commit 8f62a29

Browse files
Daniil RozanovNTBBloodbath
Daniil Rozanov
authored andcommitted
feat: custom mappings for result window
Added new table in `result` table named `keybinds`. With this table you can redefine mapping for `cycle_result_pane` action. To do this, in config you need to add ```lua result = { keybinds = { prev = "J", -- or any next = "K", -- or any } } ``` Other feature is ability to choose does these mappings attach to request result buffer or not. If you want to make mappings locally in buffer, add ```lua result = { keybinds = { -- ... buffer_local = true } } ``` This feature is useful if you already have other actions mapped with `H` or `L`
1 parent 21a9ae3 commit 8f62a29

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

lua/rest-nvim/autocmds.lua

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local result_help = require("rest-nvim.result.help")
1515
---Set up Rest autocommands group and set `:Rest` command on `*.http` files
1616
function autocmds.setup()
1717
local rest_nvim_augroup = vim.api.nvim_create_augroup("Rest", {})
18+
local keybinds = _G._rest_nvim.result.keybinds
1819
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
1920
group = rest_nvim_augroup,
2021
pattern = "*.http",
@@ -28,17 +29,17 @@ function autocmds.setup()
2829
group = rest_nvim_augroup,
2930
pattern = "rest_nvim_results",
3031
callback = function(args)
31-
vim.keymap.set("n", "H", function()
32+
vim.keymap.set("n", keybinds.prev, function()
3233
functions.cycle_result_pane("prev")
3334
end, {
3435
desc = "Go to previous winbar pane",
35-
buffer = args.buf,
36+
buffer = keybinds.buffer_local and args.buf or nil,
3637
})
37-
vim.keymap.set("n", "L", function()
38+
vim.keymap.set("n", keybinds.next, function()
3839
functions.cycle_result_pane("next")
3940
end, {
4041
desc = "Go to next winbar pane",
41-
buffer = args.buf,
42+
buffer = keybinds.buffer_local and args.buf or nil,
4243
})
4344
vim.keymap.set("n", "?", result_help.open, {
4445
desc = "Open rest.nvim request results help window",

lua/rest-nvim/config/check.lua

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ function check.validate(cfg)
5858
formatters = { cfg.result.behavior.formatters, "table" },
5959
json = { cfg.result.behavior.formatters.json, { "string", "function" } },
6060
html = { cfg.result.behavior.formatters.html, { "string", "function" } },
61+
-- RestConfigResultKeybinds
62+
result_keybinds = { cfg.result.keybinds, "table" },
63+
prev = { cfg.result.keybinds.prev, "string" },
64+
next = { cfg.result.keybinds.next, "string" },
65+
buffer_local = { cfg.result.keybinds.buffer_local, "boolean" },
6166
-- RestConfigHighlight
6267
highlight_enable = { cfg.highlight.enable, "boolean" },
6368
timeout = { cfg.highlight.timeout, "number" },

lua/rest-nvim/config/init.lua

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ local default_config = {
126126
end,
127127
},
128128
},
129+
keybinds = {
130+
buffer_local = false,
131+
prev = "H",
132+
next = "L",
133+
},
129134
},
130135
highlight = {
131136
enable = true,

lua/rest-nvim/result/help.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ local function get_or_create_buf()
2626
if not existing_buf then
2727
-- Create a new buffer
2828
local new_bufnr = vim.api.nvim_create_buf(false, true)
29+
local keybinds = _G._rest_nvim.result.keybinds
2930
vim.api.nvim_buf_set_name(new_bufnr, tmp_name)
3031
vim.api.nvim_set_option_value("ft", "markdown", { buf = new_bufnr })
3132
vim.api.nvim_set_option_value("buftype", "nofile", { buf = new_bufnr })
@@ -35,8 +36,8 @@ local function get_or_create_buf()
3536
"**`rest.nvim` results window help**",
3637
"",
3738
"**Keybinds**:",
38-
" - `H`: go to previous pane",
39-
" - `L`: go to next pane",
39+
" - `" .. keybinds.prev .. "`: go to previous pane",
40+
" - `" .. keybinds.next .. "`: go to next pane",
4041
" - `q`: close results window",
4142
"",
4243
"**Press `q` to close this help window**",

0 commit comments

Comments
 (0)