Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: allow vim lua commands along with functions as rhs #931

Open
1 task done
mamaraddio opened this issue Jan 15, 2025 · 0 comments
Open
1 task done

feature: allow vim lua commands along with functions as rhs #931

mamaraddio opened this issue Jan 15, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@mamaraddio
Copy link

mamaraddio commented Jan 15, 2025

Did you check the docs?

  • I have read all the which-key.nvim docs

Is your feature request related to a problem? Please describe.

I like using only Lua in my neovim conf, so a rhs like "<cmd>Lazy<cr>" or ":Lazy<cr>" could also be written as vim.cmd.Lazy or vim.cmd("Lazy") and so on. There are really a lot of ways to run the same command in Lua

Describe the solution you'd like

It would be great if we can write something similar to what vim.keymap.set() allows to.

For example:

local wk = require("which-key")
wk.add({
    { "n", "gd", vim.lsp.buf.definition, ... },
    ....
})

At the moment the most similar solution I found for which-key is to pass an anonymous function as rhs.
Like that:

local wk = require("which-key")
wk.add({
    { "n", "gd", function() vim.lsp.buf.definition() end,  ...  },
    ....
})

This is perfectly fine if the keymap involves a more tricky solution, I can think at a clean function to toggle inlay hints as:

local wk = require("which-key")
wk.add({
    { "n",
      "<leader>lh", 
      function()
          local bufnr = vim.api.nvim_get_current_buf()
          local hint = vim.lsp.inlay_hint
          hint.enable(not hint.is_enabled({ bufnr }), { bufnr })
       end,
    },
    ....
})

I think it is absolutely not necessary have to write any single time function() end without a real need. I think this could make the code cleaner

Describe alternatives you've considered

None

Additional context

No response

@mamaraddio mamaraddio added the enhancement New feature or request label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant