I want to open links in chrome by gx or gf (to unify with how I open files currently)
How it could be done for neovim (lua config)?
I want to open links in chrome by gx or gf (to unify with how I open files currently)
How it could be done for neovim (lua config)?
Figured out a solution (with the help of https://stackoverflow.com/a/68694743/1427399, to make correct regexp)
M = {}
M.HandleURL = function()
local url = string.match(vim.fn.getline("."), "[a-z]*://[^ >,;]*")
if url ~= "" then
vim.cmd('exec "!open \'' .. url .. '\'"')
else
vim.cmd('echo "No URI found in line."')
end
end
vim.api.nvim_set_keymap("n", "gf", [[ <Cmd>lua M.HandleURL()<CR> ]], {})
local openUrl = function()
local file = vim.fn.expand("<cWORD>")
local result = ":!open " .. file
if
string.match(file, "https") == "https"
or string.match(file, "http") == "http"
then
vim.cmd(result)
else
return print(" Woops is not url gais ")
end
end
vim.keymap.set("n", "gx", openUrl, { desc = "OpenUrl Undercurword" })