Skip to content

Commit

Permalink
lazy load on key
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishrb committed Jan 16, 2024
1 parent a9a381d commit dfc6b7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
require("lazy").setup({
{
"chrishrb/gx.nvim",
event = "VeryLazy",
keys = {
{ "gx", mode = {"n", "x" }, function () require("gx").open() end, desc = "Open" }
},
keys = { {"gx", mode = { "n", "x" }} },
cmd = { "Browse" },
init = function ()
vim.g.netrw_nogx = 1 -- disable netrw gx
Expand Down
9 changes: 8 additions & 1 deletion lua/gx/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function M.browse(mode, line)
end

-- search for url with handler
function M.open()
local function open()
local line = vim.api.nvim_get_current_line()
local mode = vim.api.nvim_get_mode().mode

Expand Down Expand Up @@ -78,9 +78,16 @@ local function with_defaults(options)
}
end

local function bind_keys()
vim.g.netrw_nogx = 1 -- disable netrw gx
local opts = { noremap = true, silent = true }
vim.keymap.set({ "n", "x" }, "gx", open, opts)
end

-- setup function
function M.setup(options)
M.options = with_defaults(options)
bind_keys()
vim.api.nvim_create_user_command("Browse", function(opts)
M.browse("n", opts.fargs[1])
end, { nargs = 1 })
Expand Down

0 comments on commit dfc6b7c

Please sign in to comment.