From 7b730d6b7b016d5cd602f280f879602ab44f59bd Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 18 Mar 2023 23:00:44 +0200 Subject: Add URL handling mapping with system awareness --- lua/user/keys.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lua') diff --git a/lua/user/keys.lua b/lua/user/keys.lua index fe9e3af..e007260 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -177,6 +177,17 @@ map("n", "cd", ":cd %:p:h:pwd") -- Open the current file in the default program (on Mac this should just be just `open`) map('n', 'o', ':!xdg-open %') +-- URL handling +if vim.fn.has("mac") == 1 then + map("", "gx", 'call jobstart(["open", expand("")], {"detach": v:true})', {}) +elseif vim.fn.has("unix") == 1 then + map("", "gx", 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', {}) +elseif vim.fn.has("wsl") == 1 then + map("", "gx", 'call jobstart(["wslview", expand("")], {"detach": v:true})', {}) +else + map[''].gx = {'lua print("Error: gx is not supported on this OS!")'} +end + -- Toggle completion map("n", "tc", ":lua require('user.mods').toggle_completion()") -- cgit v1.2.3