refactor(wezterm): organize keybindings with key table namespaces
Implemented key tables to create clean, organized namespaces for tab and pane management. This refactoring improves keybinding discoverability and reduces cognitive load by grouping related operations. Key changes: - LEADER + t enters tab mode (n/q/r for new/quit/rename) - LEADER + p enters pane mode (s/v/q/m for split/vsplit/quit/maximize) - LEADER + Escape enters copy mode (vim-like pseudo-normal mode) - CTRL + SHIFT + v for paste (standard terminal convention) - Removed smart-splits plugin in favor of simpler native navigation - Navigation keys remain at top level for quick access
This commit is contained in:
parent
f7de9e3c05
commit
3fe607d310
1 changed files with 91 additions and 88 deletions
|
|
@ -4,9 +4,6 @@ local wezterm = require("wezterm")
|
|||
-- Log warnings or generate errors if we define an invalid configuration option
|
||||
local config = wezterm.config_builder()
|
||||
|
||||
-- Install plugins
|
||||
local smart_splits = wezterm.plugin.require("https://github.com/mrjones2014/smart-splits.nvim")
|
||||
|
||||
--
|
||||
-- General configuration options.
|
||||
--
|
||||
|
|
@ -92,36 +89,111 @@ config.leader = { key = "a", mods = "ALT", timeout_milliseconds = 2000 }
|
|||
-- General keymaps
|
||||
config.keys = {
|
||||
--
|
||||
-- Tab management
|
||||
-- Enter key table modes
|
||||
--
|
||||
|
||||
{ -- Spawn new tab
|
||||
{ -- Enter tab management mode
|
||||
key = "t",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.SpawnTab("CurrentPaneDomain"),
|
||||
action = wezterm.action.ActivateKeyTable({
|
||||
name = "tab_mode",
|
||||
one_shot = true,
|
||||
}),
|
||||
},
|
||||
|
||||
{ -- Enter pane management mode
|
||||
key = "p",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.ActivateKeyTable({
|
||||
name = "pane_mode",
|
||||
one_shot = true,
|
||||
}),
|
||||
},
|
||||
|
||||
--
|
||||
-- Navigation
|
||||
--
|
||||
|
||||
{ -- Focus previous tab
|
||||
key = "Home",
|
||||
key = "LeftArrow",
|
||||
mods = "ALT",
|
||||
action = wezterm.action.ActivateTabRelative(-1),
|
||||
},
|
||||
|
||||
{ -- Focus next tab
|
||||
key = "End",
|
||||
key = "RightArrow",
|
||||
mods = "ALT",
|
||||
action = wezterm.action.ActivateTabRelative(1),
|
||||
},
|
||||
|
||||
{ -- Quit/close tab
|
||||
key = "Q",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.CloseCurrentTab({ confirm = false }),
|
||||
{ -- Focus previous pane
|
||||
key = "UpArrow",
|
||||
mods = "ALT",
|
||||
action = wezterm.action.ActivatePaneDirection("Prev"),
|
||||
},
|
||||
|
||||
{ -- Rename current tab
|
||||
key = ",",
|
||||
{ -- Focus next pane
|
||||
key = "DownArrow",
|
||||
mods = "ALT",
|
||||
action = wezterm.action.ActivatePaneDirection("Next"),
|
||||
},
|
||||
|
||||
{ -- Rotate panes counter-clockwise
|
||||
key = "PageUp",
|
||||
mods = "ALT",
|
||||
action = wezterm.action.RotatePanes("CounterClockwise"),
|
||||
},
|
||||
|
||||
{ -- Rotate panes clockwise
|
||||
key = "PageDown",
|
||||
mods = "ALT",
|
||||
action = wezterm.action.RotatePanes("Clockwise"),
|
||||
},
|
||||
|
||||
--
|
||||
-- Copy / Paste
|
||||
--
|
||||
|
||||
{ -- Enter copy mode
|
||||
key = "Escape",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.ActivateCopyMode,
|
||||
},
|
||||
|
||||
{ -- Paste from clipboard
|
||||
key = "v",
|
||||
mods = "CTRL|SHIFT",
|
||||
action = wezterm.action.PasteFrom("Clipboard"),
|
||||
},
|
||||
|
||||
--
|
||||
-- Miscellaneous
|
||||
--
|
||||
|
||||
{ -- This lets us unify delete word across programs
|
||||
key = "Backspace",
|
||||
mods = "CTRL",
|
||||
action = wezterm.action.SendKey({ key = "w", mods = "CTRL" }),
|
||||
},
|
||||
}
|
||||
|
||||
--
|
||||
-- Key table definitions for modal keybinding namespaces
|
||||
--
|
||||
|
||||
config.key_tables = {
|
||||
-- Tab management mode (LEADER + t)
|
||||
tab_mode = {
|
||||
{ -- Create new tab
|
||||
key = "n",
|
||||
action = wezterm.action.SpawnTab("CurrentPaneDomain"),
|
||||
},
|
||||
{ -- Close current tab
|
||||
key = "q",
|
||||
action = wezterm.action.CloseCurrentTab({ confirm = false }),
|
||||
},
|
||||
{ -- Rename current tab
|
||||
key = "r",
|
||||
action = wezterm.action_callback(function(window, pane)
|
||||
local success, stdout, stderr = wezterm.run_child_process({
|
||||
"dmenu",
|
||||
|
|
@ -138,89 +210,32 @@ config.keys = {
|
|||
end
|
||||
end),
|
||||
},
|
||||
},
|
||||
|
||||
--
|
||||
-- Pane management
|
||||
--
|
||||
|
||||
-- Pane management mode (LEADER + p)
|
||||
pane_mode = {
|
||||
{ -- Split pane vertically (bottom, 30%)
|
||||
key = "s",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.SplitPane({
|
||||
direction = "Down",
|
||||
size = { Percent = 30 },
|
||||
}),
|
||||
},
|
||||
|
||||
{ -- Split pane horizontally (left, 28%)
|
||||
key = "v",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.SplitPane({
|
||||
direction = "Left",
|
||||
size = { Percent = 28 },
|
||||
}),
|
||||
},
|
||||
|
||||
{ -- Focus previous pane
|
||||
key = "PageUp",
|
||||
mods = "ALT",
|
||||
action = wezterm.action.ActivatePaneDirection("Prev"),
|
||||
},
|
||||
|
||||
{ -- Focus next pane
|
||||
key = "PageDown",
|
||||
mods = "ALT",
|
||||
action = wezterm.action.ActivatePaneDirection("Next"),
|
||||
},
|
||||
|
||||
{ -- Rotate panes counter-clockwise
|
||||
key = "PageUp",
|
||||
mods = "ALT|CTRL",
|
||||
action = wezterm.action.RotatePanes("CounterClockwise"),
|
||||
},
|
||||
|
||||
{ -- Rotate panes clockwise
|
||||
key = "PageDown",
|
||||
mods = "ALT|CTRL",
|
||||
action = wezterm.action.RotatePanes("Clockwise"),
|
||||
},
|
||||
|
||||
{ -- Maximize/zoom pane
|
||||
key = "m",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.TogglePaneZoomState,
|
||||
},
|
||||
|
||||
{ -- Quit/close pane
|
||||
{ -- Close current pane
|
||||
key = "q",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.CloseCurrentPane({ confirm = false }),
|
||||
},
|
||||
|
||||
--
|
||||
-- Copy / Paste
|
||||
--
|
||||
|
||||
{ -- Activate vi copy mode
|
||||
key = "x",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.ActivateCopyMode,
|
||||
{ -- Maximize/zoom pane
|
||||
key = "m",
|
||||
action = wezterm.action.TogglePaneZoomState,
|
||||
},
|
||||
|
||||
{ -- Paste from clipboard
|
||||
key = "p",
|
||||
mods = "LEADER",
|
||||
action = wezterm.action.PasteFrom("Clipboard"),
|
||||
},
|
||||
|
||||
--
|
||||
-- Miscellaneous
|
||||
--
|
||||
|
||||
{ -- This lets us unify delete word across programs
|
||||
key = "Backspace",
|
||||
mods = "CTRL",
|
||||
action = wezterm.action.SendKey({ key = "w", mods = "CTRL" }),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -233,16 +248,4 @@ for i = 1, 9 do
|
|||
})
|
||||
end
|
||||
|
||||
--
|
||||
-- Enable neovim integration
|
||||
--
|
||||
|
||||
smart_splits.apply_to_config(config, {
|
||||
direction_keys = { "LeftArrow", "DownArrow", "UpArrow", "RightArrow" },
|
||||
modifiers = {
|
||||
move = "ALT",
|
||||
resize = "ALT|CTRL",
|
||||
},
|
||||
})
|
||||
|
||||
return config
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue