hydra.nvim icon indicating copy to clipboard operation
hydra.nvim copied to clipboard

`hydra:activate(head)` to activate a hydra and trigger one of the heads

Open IndianBoy42 opened this issue 2 years ago • 3 comments

Basically the same thing that would be mapped to all the non private heads if body is given

IndianBoy42 avatar Apr 06 '23 09:04 IndianBoy42

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 avatar Dec 11 '23 05:12 kohane27

@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 avatar Dec 29 '23 09:12 JustinHoyt

@JustinHoyt It works perfectly. You just made my day! Thank you!

kohane27 avatar Dec 30 '23 06:12 kohane27