aboutsummaryrefslogtreecommitdiff
path: root/runtime/plugin/nvim.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-07-05 00:30:05 -0700
committerGitHub <noreply@github.com>2023-07-05 00:30:05 -0700
commit5936a88f181e52e17484d4ae6dfaea7d50d43935 (patch)
treeef727393e94037e5a675f566b59b1014f8fe2a29 /runtime/plugin/nvim.lua
parentb2e8c0df2062f765a4cf7d96379c5f0f19393dfd (diff)
parente644e7ce0b36dd5e75770f3faa0a84f15e2561e8 (diff)
downloadrneovim-5936a88f181e52e17484d4ae6dfaea7d50d43935.tar.gz
rneovim-5936a88f181e52e17484d4ae6dfaea7d50d43935.tar.bz2
rneovim-5936a88f181e52e17484d4ae6dfaea7d50d43935.zip
Merge #23401 vim.ui.open: "gx" without netrw
Diffstat (limited to 'runtime/plugin/nvim.lua')
-rw-r--r--runtime/plugin/nvim.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua
index 0a33826b82..33d399e577 100644
--- a/runtime/plugin/nvim.lua
+++ b/runtime/plugin/nvim.lua
@@ -18,3 +18,27 @@ vim.api.nvim_create_user_command('InspectTree', function(cmd)
vim.treesitter.inspect_tree()
end
end, { desc = 'Inspect treesitter language tree for buffer', count = true })
+
+-- TODO: use vim.region() when it lands... #13896 #16843
+local function get_visual_selection()
+ local save_a = vim.fn.getreginfo('a')
+ vim.cmd([[norm! "ay]])
+ local selection = vim.fn.getreg('a', 1)
+ vim.fn.setreg('a', save_a)
+ return selection
+end
+
+local gx_desc =
+ 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)'
+local function do_open(uri)
+ local _, err = vim.ui.open(uri)
+ if err then
+ vim.notify(err, vim.log.levels.ERROR)
+ end
+end
+vim.keymap.set({ 'n' }, 'gx', function()
+ do_open(vim.fn.expand('<cfile>'))
+end, { desc = gx_desc })
+vim.keymap.set({ 'x' }, 'gx', function()
+ do_open(get_visual_selection())
+end, { desc = gx_desc })