plugins/tmux-navigator: add keymaps option

Enable users to more easily create keymaps for tmux-navigator's
directional motions.
This commit is contained in:
Matt Sturgeon 2024-03-17 15:44:44 +00:00
parent 4634c3781b
commit 94a452074f
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 96 additions and 29 deletions

View file

@ -121,38 +121,72 @@ helpers.vim-plugin.mkVimPlugin config {
''; '';
no_mappings = helpers.defaultNullOpts.mkBool false '' no_mappings = helpers.defaultNullOpts.mkBool false ''
By default `<C-h>`, `<C-j>`, `<C-k>`, `<C-l>`, & `<C-\\>` are mapped to navigating left, down, up, right, & previous, respectively. By default `<C-h>`, `<C-j>`, `<C-k>`, `<C-l>`, & `<C-\\>`
are mapped to navigating left, down, up, right, & previous, respectively.
This option disables those default mappings being created. This option disables those default mappings being created.
You can use the plugin's five commands to define your own custom mappings: You can use `plugins.tmux-navigator.keymaps` to define your own custom mappings.
You will also need to **update your tmux bindings** separately,
if you want them to match.
'';
};
```nix extraOptions = {
keymaps = [ keymaps = mkOption {
description = ''
Keymaps for the `:TmuxNavigate*` commands.
Note: by default, tmux-navigator adds its own keymaps.
If you wish to disable that behaviour, use `settings.no_mappings`.
You will also need to **update your tmux bindings** separately,
if you want them to match.
'';
example = [
{ {
key = "<C-w>h"; key = "<C-w>h";
action = "<cmd>TmuxNavigateLeft<cr>"; action = "left";
} }
{ {
key = "<C-w>j"; key = "<C-w>j";
action = "<cmd>TmuxNavigateDown<cr>"; action = "down";
} }
{ {
key = "<C-w>k"; key = "<C-w>k";
action = "<cmd>TmuxNavigateUp<cr>"; action = "up";
} }
{ {
key = "<C-w>l"; key = "<C-w>l";
action = "<cmd>TmuxNavigateRight<cr>"; action = "right";
} }
{ {
key = "<C-w>\\"; key = "<C-w>\\";
action = "<cmd>TmuxNavigatePrevious<cr>"; action = "previous";
} }
]; ];
``` default = [ ];
type = types.listOf (
You will also need to update your tmux bindings to match. helpers.keymaps.mkMapOptionSubmodule {
''; action = {
description = "The direction in which to navigate.";
type = types.enum [
"left"
"down"
"up"
"right"
"previous"
];
example = "left";
};
}
);
};
};
extraConfig = cfg: {
keymaps = map (
mapping: mapping // { action = "<cmd>TmuxNavigate${helpers.upperFirstChar mapping.action}<cr>"; }
) cfg.keymaps;
}; };
} }

View file

@ -9,6 +9,8 @@
plugins.tmux-navigator = { plugins.tmux-navigator = {
enable = true; enable = true;
keymaps = [ ];
settings = { settings = {
save_on_switch = 2; save_on_switch = 2;
disable_when_zoomed = true; disable_when_zoomed = true;
@ -18,4 +20,35 @@
}; };
}; };
}; };
with-keymap = {
plugins.tmux-navigator = {
enable = true;
keymaps = [
{
key = "<C-w>h";
action = "left";
}
{
key = "<C-w>j";
action = "down";
}
{
key = "<C-w>k";
action = "up";
}
{
key = "<C-w>l";
action = "right";
}
{
key = "<C-w>\\";
action = "previous";
}
];
settings.no_mappings = true;
};
};
} }