diff --git a/plugins/utils/tmux-navigator.nix b/plugins/utils/tmux-navigator.nix index fd9a4e70..1a13f6af 100644 --- a/plugins/utils/tmux-navigator.nix +++ b/plugins/utils/tmux-navigator.nix @@ -121,38 +121,72 @@ helpers.vim-plugin.mkVimPlugin config { ''; no_mappings = helpers.defaultNullOpts.mkBool false '' - By default ``, ``, ``, ``, & `` are mapped to navigating left, down, up, right, & previous, respectively. + By default ``, ``, ``, ``, & `` + are mapped to navigating left, down, up, right, & previous, respectively. This option disables those default mappings being created. - You can use the plugin's five commands to define your own custom mappings: - - ```nix - keymaps = [ - { - key = "h"; - action = "TmuxNavigateLeft"; - } - { - key = "j"; - action = "TmuxNavigateDown"; - } - { - key = "k"; - action = "TmuxNavigateUp"; - } - { - key = "l"; - action = "TmuxNavigateRight"; - } - { - key = "\\"; - action = "TmuxNavigatePrevious"; - } - ]; - ``` - - You will also need to update your tmux bindings to match. + 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. ''; }; + + extraOptions = { + 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 = "h"; + action = "left"; + } + { + key = "j"; + action = "down"; + } + { + key = "k"; + action = "up"; + } + { + key = "l"; + action = "right"; + } + { + key = "\\"; + action = "previous"; + } + ]; + default = [ ]; + type = types.listOf ( + 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 = "TmuxNavigate${helpers.upperFirstChar mapping.action}"; } + ) cfg.keymaps; + }; } diff --git a/tests/test-sources/plugins/utils/tmux-navigator.nix b/tests/test-sources/plugins/utils/tmux-navigator.nix index 23ebc974..abb66742 100644 --- a/tests/test-sources/plugins/utils/tmux-navigator.nix +++ b/tests/test-sources/plugins/utils/tmux-navigator.nix @@ -9,6 +9,8 @@ plugins.tmux-navigator = { enable = true; + keymaps = [ ]; + settings = { save_on_switch = 2; disable_when_zoomed = true; @@ -18,4 +20,35 @@ }; }; }; + + with-keymap = { + plugins.tmux-navigator = { + enable = true; + + keymaps = [ + { + key = "h"; + action = "left"; + } + { + key = "j"; + action = "down"; + } + { + key = "k"; + action = "up"; + } + { + key = "l"; + action = "right"; + } + { + key = "\\"; + action = "previous"; + } + ]; + + settings.no_mappings = true; + }; + }; }