Closed phanorcoll closed 8 months ago
hi
that's normal
the "run" commands are expose as <Plug>...
commands that you need to bind to shortcuts
eg
// file: nvim/ftplugin/http.lua
vim.keymap.set('n', ',x', '<Plug>RestNvim', { desc = 'execute request' })
vim.keymap.set('n', ',p', '<Plug>RestNvimPreview', { desc = 'preview curl' })
vim.keymap.set('n', ',l', '<Plug>RestNvimLast', { desc = 'repeat last request' })
Hi @phanorcoll @eauc ,
Reading through the code I came up with a more "lua like" aproach to this.
local ok, rest = pcall(require, "rest-nvim")
if not ok then
vim.notify("RestNvim not loaded", 3)
return
end
local mappings = {
n = {
["<leader>hx"] = {
rest.run,
"Execute request",
},
["<leader>hp"] = {
function()
rest.run(true)
end,
"Preview curl request",
},
["<leader>hl"] = {
rest.last,
"Repeat last request",
},
},
}
require("aome.core.utils").map_keys(mappings)
NOTE: these keymaps are my way to do it You can check out my .config if you want to know how the mapping works
Another option that works for me:
plugin.lua
{
"rest-nvim/rest.nvim",
event = "VeryLazy",
dependencies = {
"nvim-lua/plenary.nvim",
},
config = function()
require "custom.configs.rest"
end
},
mappings.lua
M.rest = {
n = {
["<leader>rr"] = {
"<Plug>RestNvim",
"Run the request under the cursor"
},
["<leader>rp"] = {
"<Plug>RestNvimPreview",
"Preview the request under the cursor"
},
["<leader>rl"] = {
"<Plug>RestNvimLast",
"Re-run the last request"
},
}
}
custom/configs/rest.lua
require("rest-nvim").setup({
result_split_horizontal = false,
result_split_vertical = true,
skip_ssl_verification = true,
result = {
formatters = {
json = function(body)
return vim.fn.system({"jq", "."}, body)
end,
html = function(body)
return vim.fn.system({"tidy", "-i", "-q", "-"}, body)
end,
},
},
highlight = {
enabled = true,
timeout = 150,
},
jump_to_request = false,
})
My nvim config is with NvChad, you can check my dotfiles
I tried installing it using Lazy package manager, but the only two commands that I get are