Skip to content

Commit c7ada78

Browse files
authored
feat(esupports.hop): Add tab drop as option for open_mode (#1580)
* feat(esupports.hop): Add tab drop as option for open_mode * docs(esupports.hop): Document keybinds for tab-drop * feat(esupports.hop): Add drop as option for open_mode
1 parent 488507b commit c7ada78

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lua/neorg/modules/core/esupports/hop/module.lua

+17-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ mapping them):
1717
1818
- `neorg.esupports.hop.hop-link` - Follow the link under the cursor, seeks forward
1919
- `neorg.esupports.hop.hop-link.vsplit` - Same, but open the link in a vertical split
20+
- `neorg.esupports.hop.hop-link.tab-drop` - Same as hop-link, but open the link in a new tab; if the destination is already
21+
open in an existing tab then just navigate to that tab (check :help :drop)
22+
- `neorg.esupports.hop.hop-link.drop` - Same as hop-link, but navigate to the buffer if the destination is already open
23+
in an existing buffer (check :help :drop)
2024
--]]
2125

2226
local neorg = require("neorg.core")
@@ -42,6 +46,8 @@ module.load = function()
4246
dirman_utils = module.required["core.dirman.utils"]
4347
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link)", module.public.hop_link)
4448
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.vsplit)", lib.wrap(module.public.hop_link, "vsplit"))
49+
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.drop)", lib.wrap(module.public.hop_link, "drop"))
50+
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.tab-drop)", lib.wrap(module.public.hop_link, "tab-drop"))
4551
end
4652

4753
module.config.public = {
@@ -216,11 +222,19 @@ module.public = {
216222
end,
217223

218224
buffer = function()
219-
open_split()
225+
if open_mode ~= "tab-drop" and open_mode ~= "drop" then
226+
open_split()
227+
end
220228

221229
if located_link_information.buffer ~= vim.api.nvim_get_current_buf() then
222-
vim.api.nvim_buf_set_option(located_link_information.buffer, "buflisted", true)
223-
vim.api.nvim_set_current_buf(located_link_information.buffer)
230+
if open_mode == "tab-drop" then
231+
vim.cmd("tab drop " .. vim.api.nvim_buf_get_name(located_link_information.buffer))
232+
elseif open_mode == "drop" then
233+
vim.cmd("drop " .. vim.api.nvim_buf_get_name(located_link_information.buffer))
234+
else
235+
vim.api.nvim_buf_set_option(located_link_information.buffer, "buflisted", true)
236+
vim.api.nvim_set_current_buf(located_link_information.buffer)
237+
end
224238
end
225239

226240
if located_link_information.line then

lua/neorg/modules/core/keybinds/module.lua

+8
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ module.private = {
298298
opts = { desc = "[neorg] Jump to Link (Vertical Split)" },
299299
},
300300

301+
-- Same as `<CR>`, except open the destination in a new tab
302+
-- If destination is already open in an existing tab, just navigate to it
303+
{
304+
"<M-t>",
305+
"<Plug>(neorg.esupports.hop.hop-link.tab-drop)",
306+
opts = { desc = "[neorg] Jump to Link (Tab Drop)" },
307+
},
308+
301309
-- Promote an object non-recursively
302310
{
303311
">.",

0 commit comments

Comments
 (0)