nixvim
nixvim copied to clipboard
Feature Request: keymapsOnEvent with event pattern
Description
To my understanding, Currently keymapsOnEvent does not support event pattern, even though it is based on autoCmd.
It would be very convenient for setting up some keymaps only for certain filetypes, or for certain situations.
autoCmd = lib.mapAttrsToList (event: mappings: {
inherit event;
pattern = mappings.pattern; ## ADDED LINE
group = "nixvim_binds_${event}";
callback = helpers.mkRaw ''
function()
do
local __nixvim_binds = ${helpers.toLuaObject (map helpers.keymaps.removeDeprecatedMapAttrs mappings)}
for i, map in ipairs(__nixvim_binds) do
vim.keymap.set(map.mode, map.key, map.action, map.options)
end
end
end
'';
desc = "Load keymaps for ${event}";
}) config.keymapsOnEvents;
This version would need a separate helpers.keymapsOnEvent.deprecatedMapOptionSubmodule
type, but I reckon it wouldn't break existing configurations, if keymapsOnEvents
could accept both current one and the one I suggested.
Alternative
Instead (or along with) of event pattern option, it could have custom condition
option.
autoCmd = lib.mapAttrsToList (event: mappings: {
inherit event;
group = "nixvim_binds_${event}";
callback = helpers.mkRaw ''
function()
do
local __nixvim_binds = ${helpers.toLuaObject (map helpers.keymaps.removeDeprecatedMapAttrs mappings)}
for i, map in ipairs(__nixvim_binds) do
if (map.condition == nil or map.condition()) then -- ADDED IF STATEMENT
vim.keymap.set(map.mode, map.key, map.action, map.options)
end
end
end
end
'';
desc = "Load keymaps for ${event}";
}) config.keymapsOnEvents;