nvimtools / hydra.nvim

Create custom submodes and menus
MIT License
145 stars 8 forks source link

Remove "[Hydra]" from name options #43

Closed nhattruongNeoVim closed 1 month ago

nhattruongNeoVim commented 2 months ago

When i set name = "Options" and this is the result

Thiết kế chưa có tên (2)

I dont want the word [Hydra] in front of it, how can i fix this?

miversen33 commented 2 months ago

It would be much more helpful if you could provide us your configuration you used to generate that hydra. Until then, nobody will be able to answer your question.

nhattruongNeoVim commented 2 months ago
return {
    "nvimtools/hydra.nvim",
    keys = {
        {
            "<leader>o",
            desc = "Options",
        },
    },
    config = function()
        local M = require("hydra.hint.vim-options")

        M.transparent = function()
            if vim.g.is_transparent then
                return "[x]"
            else
                return "[ ]"
            end
        end
        M.tpr = M.transparent

        -- Vim option menu
        require("hydra")({
            name = "Options",
            hint = [[
  ^ ^         Options
  ^
  _v_ %{ve} virtual edit
  _i_ %{list} invisible characters  
  _s_ %{spell} spell
  _w_ %{wrap} wrap
  _l_ %{cul} cursor line
  _c_ %{cuc} cursor column 
  _n_ %{nu} number
  _r_ %{rnu} relative number
  _t_ %{tpr} transparent
  ^
       ^^^^                _o_ [Quit] ^
]],
            config = {
                invoke_on_body = true,
                color = "pink",
                hint = {
                    show_name = false,
                    position = "middle",
                    offset = 0,
                    float_opts = {
                        border = "rounded",
                    },
                },
            },
            body = "<leader>o",
            mode = { "n", "x" },
            heads = {
                {
                    "n",
                    function()
                        if vim.o.number == true then
                            vim.o.number = false
                        else
                            vim.o.number = true
                        end
                    end,
                    { desc = "number" },
                },
                {
                    "r",
                    function()
                        if vim.o.relativenumber == true then
                            vim.o.relativenumber = false
                        else
                            vim.o.number = true
                            vim.o.relativenumber = true
                        end
                    end,
                    { desc = "relativenumber" },
                },
                {
                    "v",
                    function()
                        if vim.o.virtualedit == "all" then
                            vim.o.virtualedit = "block"
                        else
                            vim.o.virtualedit = "all"
                        end
                    end,
                    { desc = "virtualedit" },
                },
                {
                    "i",
                    function()
                        if vim.o.list == true then
                            vim.o.list = false
                        else
                            vim.o.list = true
                        end
                    end,
                    { desc = "show invisible" },
                },
                {
                    "s",
                    function()
                        if vim.o.spell == true then
                            vim.o.spell = false
                        else
                            vim.o.spell = true
                        end
                    end,
                    { exit = true, desc = "spell" },
                },
                {
                    "w",
                    function()
                        if vim.o.wrap ~= true then
                            vim.o.wrap = true
                            vim.keymap.set("n", "k", function()
                                return vim.v.count > 0 and "k" or "gk"
                            end, { expr = true, desc = "k or gk" })
                            vim.keymap.set("n", "j", function()
                                return vim.v.count > 0 and "j" or "gj"
                            end, { expr = true, desc = "j or gj" })
                        else
                            vim.o.wrap = false
                            if vim.fn.maparg("k", "n") ~= "" then
                                vim.keymap.del("n", "k")
                            end
                            if vim.fn.maparg("j", "n") ~= "" then
                                vim.keymap.del("n", "j")
                            end
                        end
                    end,
                    { desc = "wrap" },
                },
                {
                    "l",
                    function()
                        if vim.o.cursorline == true then
                            vim.o.cursorline = false
                        else
                            vim.o.cursorline = true
                        end
                    end,
                    { desc = "cursor line" },
                },
                {
                    "c",
                    function()
                        if vim.o.cursorcolumn == true then
                            vim.o.cursorcolumn = false
                        else
                            vim.o.cursorcolumn = true
                        end
                    end,
                    { desc = "cursor cursorcolumn" },
                },
                {
                    "t",
                    "<cmd>lua _TOGGLE_TRANSPARENT()<cr>",
                    {
                        desc = "transparent",
                    },
                },
                { "o", nil, { exit = true } },
            },
        })
    end,
}
nhattruongNeoVim commented 2 months ago

I found this part in the plugin's source code lua/hydra/init.lua and I think it's the reason:

      if not self.config.desc then
         if self.name then
            self.config.desc = '[Hydra] '..self.name
         else
            self.config.desc = '[Hydra]'
         end
      end

can you change it to:

      if not self.config.desc then
         if self.name then
            self.config.desc = self.name
         else
            self.config.desc = '[Hydra]'
         end
      end

This way, it will only set self.config.desc = '[Hydra]' when self.name is not present

benlubas commented 2 months ago

Submit a pr. I agree that the change you suggest is better