aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarshmallow <marshycity@gmail.com>2023-07-25 01:35:19 +1000
committerGitHub <noreply@github.com>2023-07-24 08:35:19 -0700
commit6a486c44e66f05ae11137ad7a192b89989192566 (patch)
tree914a0d4d84ace2f2ef7d094ca19ce71a98c4ff87
parent48085e40bb0e4435ddb2eb7f14b4531b943e0c89 (diff)
downloadrneovim-6a486c44e66f05ae11137ad7a192b89989192566.tar.gz
rneovim-6a486c44e66f05ae11137ad7a192b89989192566.tar.bz2
rneovim-6a486c44e66f05ae11137ad7a192b89989192566.zip
fix(gx): move to to _init_default_mappings #24420
Problem: netrw may conflict with the Nvim default "gx" mapping. Solution: Initialize keymapping earlier by moving it to vim._init_default_mappings(). That also avoids needing to check maparg().
-rw-r--r--runtime/lua/vim/_editor.lua27
-rw-r--r--runtime/plugin/nvim.lua28
2 files changed, 27 insertions, 28 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index 4372aef7b3..87f6d6581c 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -1048,6 +1048,33 @@ function vim._init_default_mappings()
-- Use : instead of <Cmd> so that ranges are supported. #19365
map('n', '&', ':&&<CR>')
+ -- gx
+
+ -- 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 function do_open(uri)
+ local _, err = vim.ui.open(uri)
+ if err then
+ vim.notify(err, vim.log.levels.ERROR)
+ end
+ end
+
+ local gx_desc =
+ 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)'
+ 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 })
+
-- menus
-- TODO VimScript, no l10n
diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua
index e3d4625c3b..0a33826b82 100644
--- a/runtime/plugin/nvim.lua
+++ b/runtime/plugin/nvim.lua
@@ -18,31 +18,3 @@ 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
-if vim.fn.maparg('gx', 'n') == '' then
- vim.keymap.set({ 'n' }, 'gx', function()
- do_open(vim.fn.expand('<cfile>'))
- end, { desc = gx_desc })
-end
-if vim.fn.maparg('gx', 'x') == '' then
- vim.keymap.set({ 'x' }, 'gx', function()
- do_open(get_visual_selection())
- end, { desc = gx_desc })
-end