`hydra:activate(head)` to activate a hydra and trigger one of the heads
Basically the same thing that would be mapped to all the non private heads if body is given
As a workaround I have the following:
hydra({
name = "TODO",
mode = "n",
body = ";t",
config = {
invoke_on_body = true,
on_enter = function()
require("todo-comments").jump_next()
end,
},
heads = {
{ "j", '<cmd>lua require("todo-comments").jump_next()<CR>' },
{ "k", '<cmd>lua require("todo-comments").jump_prev()<CR>' },
{ "<Esc>", nil, { exit = true, nowait = true } },
},
})
When I trigger it with ;t, it'll run the on_enter, and then I can continue with j or k inside the heads.
However, I still haven't yet figured out the same for <C-d> triggers. With the following:
hydra({
name = "Smooth scrolling",
mode = "n",
body = "<C-d>",
config = {
invoke_on_body = true,
on_enter = function()
vim.api.nvim_command("lua Scroll('<C-f>', 1, 1)")
end,
},
heads = {
{ "j", '<cmd>lua Scroll("<C-f>", 1, 1)<CR>' },
{ "k", '<cmd>lua Scroll("<C-b>", 1, 1)<CR>' },
{ "<Esc>", nil, { exit = true, nowait = true } },
},
})
I need to press <C-d> to trigger the heads, then j to do the scrolling down. What I'd like is to just press <C-d> and it'll trigger scrolling down once, and then I can just trigger the heads with just j or k.
Any input is much appreciated. Thank you.
@kohane27
MyScroll = Hydra({
name = "Scroll",
mode = 'n',
heads = {
{ 'u', '<C-u>', { private = true } },
{ 'd', '<C-d>', { private = true } },
},
})
vim.api.nvim_set_keymap('n', '<C-u>', '<C-u><cmd>lua require("hydra").activate(MyScroll)<CR>', { silent = true, noremap = true })
vim.api.nvim_set_keymap('n', '<C-d>', '<C-d><cmd>lua require("hydra").activate(MyScroll)<CR>', { silent = true, noremap = true })
@JustinHoyt It works perfectly. You just made my day! Thank you!