Replies: 2 comments 1 reply
-
Hi @synic, You would not need the Is there a reason to have all keymaps in one file? After all, you define them as Lazy Key Mappings. I would advise the simple approach, having the lazy keys in the spec of the plugin. Given your code examples, you could break the dependency by using callback functions. For example: module.neogit = function(action)
return {
"<leader>gs",
action,
desc = "git status",
}
end
{
"NeogitOrg/neogit",
opts = { kind = "vsplit" },
keys = {keymap.neogit(function module.neogit_open() end)},
dependencies = { "nvim-lua/plenary.nvim", "sindrets/diffview.nvim" },
},
|
Beta Was this translation helpful? Give feedback.
-
Nevermind, I gave up on trying to put it in one file so I moved it back to the plugins definitions. After I did that, however, I think I thought of what is probably the best solution, and that is to defined partial keys in the main keymap file and use identifiers. That way the keymap file describes what keys should be used, but the plugin decides what the key actually does (callback, etc). Something like this: -- keymap.lua
local keys = {
{ id = 'telescope_git_files', key='<space>f', desc='search git files', mode = { 'n' } }
} And, then in -- telescope.lua
local utils = require('someutils')
local keymap = require('keymap')
local keys = utils.parse_keymap(keymap)
return {
{
"nvim-telescope/telescope.nvim",
keys = {
keys.get('telescope_git_files', require('telescope.builtin').git_files()),
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've got it working, but I'm sure there's some jank. Wondering if there's a better way.
Here's what my
keymap.lua
file looks like:and here's what
sourcecontro.lua
looks like:I have to do the anonymous function as the callback in
keymap.lua
to avoid a circular dependeny. Also, the module has to have at least two plugins (or an empty table)at the end of the returned table), or lazy.nvim complains aboutfind
being called on a nil value. No idea why.I'm returning a module with plugin specs, but also with functions. Maybe that conflicts with lazy.nvim, I am not sure.
Is there a better way to do this?
Beta Was this translation helpful? Give feedback.
All reactions