Files
nixvim/tests/test-sources/modules/commands.nix
T
Austin Horstman 0f6b022322 modules/commands: support command preview
Expose nvim_create_user_command preview callbacks through userCommands so command previews can be configured declaratively instead of requiring raw setup Lua.
2026-04-24 21:59:51 +00:00

45 lines
1.0 KiB
Nix

{ lib }:
{
example =
{ config, ... }:
{
userCommands = {
"W" = {
command = ":w<CR>";
desc = "Write file";
nargs = 0;
};
"Z" = {
command = ":echo fooo<CR>";
};
"InsertHere" = {
command.__raw = ''
function(opts)
vim.api.nvim_put({opts.args}, 'c', true, true)
end
'';
nargs = 1;
};
"PreviewHere" = {
command = ":echo fooo<CR>";
nargs = 1;
preview = ''
function(opts, ns, buf)
if buf then
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { opts.args })
end
return 2
end
'';
};
};
assertions = [
{
assertion = lib.hasInfix "preview = function(opts, ns, buf)" config.extraConfigLua;
message = "`userCommands.PreviewHere.preview` should be emitted as a lua function.";
}
];
};
}