dotfiles/wezterm/config/keys.lua

198 lines
6.5 KiB
Lua
Raw Normal View History

2023-03-22 11:20:01 +00:00
local wezterm = require("wezterm")
local base = require("config/base")
local events = require("config/events")
2023-07-06 11:48:58 +00:00
local act = wezterm.action
2023-03-22 11:20:01 +00:00
local keymod = base.keymod
local module = {}
function module.apply_to_config(config)
-- I'm very used to setting <SPACE> as the leader so I'm continuing the tradition.
config.leader = { key = "Space", mods = keymod, timeout_milliseconds = 1000 }
-- I'm liking the workflow I have with Kitty so no thanks for the default
-- shortcuts. So this is what it feels like to be obnoxiously stubborn.
config.disable_default_key_bindings = true
2023-03-22 11:20:01 +00:00
config.mouse_bindings = {
{
event = { Down = { streak = 3, button = "Left" } },
action = { SelectTextAtMouseCursor = "SemanticZone" },
mods = keymod,
},
2023-07-06 11:48:58 +00:00
{
event = { Down = { streak = 1, button = "Left" } },
action = act.ExtendSelectionToMouseCursor "Word",
mods = keymod,
},
2023-03-22 11:20:01 +00:00
}
-- It also makes use of key tables which is defined after.
config.keys = {
-- Clipboard
2023-07-06 11:48:58 +00:00
{ key = "c", mods = keymod, action = act.CopyTo "Clipboard" },
{ key = "v", mods = keymod, action = act.PasteFrom "Clipboard" },
2023-03-22 11:20:01 +00:00
-- Font resize.
2023-07-06 11:48:58 +00:00
{ key = "+", mods = keymod, action = act.IncreaseFontSize },
{ key = "_", mods = keymod, action = act.DecreaseFontSize },
{ key = ")", mods = keymod, action = act.ResetFontSize },
2023-03-22 11:20:01 +00:00
-- Scrollback
2023-07-06 11:48:58 +00:00
{ key = "j", mods = keymod, action = act.ScrollByPage(1) },
{ key = "k", mods = keymod, action = act.ScrollByPage(-1) },
{ key = "j", mods = "CTRL|ALT", action = act.ScrollToPrompt(1) },
{ key = "k", mods = "CTRL|ALT", action = act.ScrollToPrompt(-1) },
{ key = "G", mods = keymod, action = act.ScrollToBottom },
{ key = "g", mods = "CTRL|ALT", action = act.ScrollToTop },
2023-03-22 11:20:01 +00:00
-- Pane navigation.
{
key = "p",
mods = "LEADER",
2023-07-06 11:48:58 +00:00
action = act.ActivateKeyTable {
2023-03-22 11:20:01 +00:00
name = "pane_navigation",
timeout_milliseconds = 1000,
replace_current = true,
one_shot = true,
2023-07-06 11:48:58 +00:00
},
2023-03-22 11:20:01 +00:00
},
2023-07-06 11:48:58 +00:00
2023-03-22 11:20:01 +00:00
{
key = "r",
mods = "LEADER",
2023-07-06 11:48:58 +00:00
action = act.ActivateKeyTable {
name = "resize_pane",
replace_current = true,
one_shot = false,
},
2023-03-22 11:20:01 +00:00
},
2023-07-06 11:48:58 +00:00
{ key = "h", mods = keymod, action = act.ActivatePaneDirection("Left") },
{ key = "l", mods = keymod, action = act.ActivatePaneDirection("Right") },
{ key = "LeftArrow", mods = keymod, action = act.ActivatePaneDirection("Left") },
{ key = "DownArrow", mods = keymod, action = act.ActivatePaneDirection("Down") },
{ key = "UpArrow", mods = keymod, action = act.ActivatePaneDirection("Up") },
{ key = "RightArrow", mods = keymod, action = act.ActivatePaneDirection("Right") },
2023-03-22 11:20:01 +00:00
-- More pane-related niceties.
2023-07-06 11:48:58 +00:00
{ key = "f", mods = "LEADER", action = act.TogglePaneZoomState },
{ key = "f", mods = keymod, action = act.TogglePaneZoomState },
{ key = "n", mods = "LEADER", action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
{ key = "n", mods = keymod, action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
{ key = "d", mods = keymod, action = act.CloseCurrentPane({ confirm = false }) },
2023-03-22 11:20:01 +00:00
-- Tab navigation
{
key = "t",
mods = "LEADER",
2023-07-06 11:48:58 +00:00
action = act.ActivateKeyTable({
name = "tab_navigation",
timeout_milliseconds = 1000,
replace_current = true,
one_shot = true,
2023-03-22 11:20:01 +00:00
}),
},
-- Hints and quick selections
{
key = "h",
mods = "LEADER",
2023-07-06 11:48:58 +00:00
action = act.ActivateKeyTable({
name = "hints",
timeout_milliseconds = 1000,
replace_current = true,
one_shot = true
2023-03-22 11:20:01 +00:00
}),
},
2023-07-06 11:48:58 +00:00
{ key = "r", mods = keymod, action = act.ReloadConfiguration },
{ key = "t", mods = keymod, action = act.ShowDebugOverlay },
2023-03-22 11:20:01 +00:00
-- Selection
2023-07-06 11:48:58 +00:00
{ key = "Space", mods = "LEADER", action = act.QuickSelect },
{ key = "a", mods = keymod, action = act.QuickSelect },
{ key = "s", mods = keymod, action = act.Search { CaseSensitiveString = "" } },
2023-03-22 11:20:01 +00:00
}
config.key_tables = {
hints = {
2023-07-06 11:48:58 +00:00
{ key = "g", action = act.Search { Regex = "[0-9a-f]{6,}" } },
2023-03-22 11:20:01 +00:00
{
key = "h",
2023-07-06 11:48:58 +00:00
action = act.QuickSelectArgs {
patterns = {
"[0-9a-f]{7,40}", -- SHA1 hashes, usually used for Git.
"[0-9a-f]{7,64}", -- SHA256 hashes, used often for getting hashes for Guix packaging.
"sha256-[[:alpha:][:digit:]-=+/?]{44}", -- SHA256 hashes in Base64, used often in getting hashes for Nix packaging.
"[[:alpha:][:digit:]-=+/?]{44,64}",
2023-03-22 11:20:01 +00:00
},
2023-07-06 11:48:58 +00:00
},
2023-03-22 11:20:01 +00:00
},
-- Basically the equivalent of `kitty hints word`.
{
key = "w",
2023-07-06 11:48:58 +00:00
action = act.QuickSelectArgs {
patterns = {
"\\S+",
2023-03-22 11:20:01 +00:00
},
2023-07-06 11:48:58 +00:00
},
2023-03-22 11:20:01 +00:00
},
-- The equivalent to `kitty hints line`.
{
key = "l",
2023-07-06 11:48:58 +00:00
action = act.QuickSelectArgs {
patterns = {
".+",
2023-03-22 11:20:01 +00:00
},
2023-07-06 11:48:58 +00:00
},
2023-03-22 11:20:01 +00:00
},
2023-07-06 11:48:58 +00:00
{
key = "p",
action = act.Search {
Regex = "legacyPackages[[:alpha:][:digit:]]+"
},
},
2023-03-22 11:20:01 +00:00
2023-07-06 11:48:58 +00:00
{ key = "Space", action = act.QuickSelect },
{ key = "s", action = act.QuickSelect },
{ key = "f", action = act.Search { CaseSensitiveString = "" } },
2023-03-22 11:20:01 +00:00
},
pane_navigation = {
2023-07-06 11:48:58 +00:00
{ key = "d", action = act.CloseCurrentPane { confirm = false } },
{ key = "h", action = act.ActivatePaneDirection("Left") },
{ key = "j", action = act.ActivatePaneDirection("Down") },
{ key = "k", action = act.ActivatePaneDirection("Up") },
{ key = "l", action = act.ActivatePaneDirection("Right") },
{ key = "n", action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
2023-03-22 11:20:01 +00:00
},
tab_navigation = {
2023-07-06 11:48:58 +00:00
{ key = "d", action = act.CloseCurrentTab({ confirm = false }) },
{ key = "h", action = act.ActivateTabRelative(-1) },
{ key = "j", action = act.ActivateTab(-1) },
{ key = "k", action = act.ActivateTab(0) },
{ key = "l", action = act.ActivateTabRelative(1) },
{ key = "n", action = act.SpawnTab("CurrentPaneDomain") },
2023-03-22 11:20:01 +00:00
},
resize_pane = {
2023-07-06 11:48:58 +00:00
{ key = "h", action = act.AdjustPaneSize({ "Left", 1 }) },
{ key = "j", action = act.AdjustPaneSize({ "Down", 1 }) },
{ key = "k", action = act.AdjustPaneSize({ "Up", 1 }) },
{ key = "l", action = act.AdjustPaneSize({ "Right", 1 }) },
{ key = "q", action = act.PopKeyTable },
{ key = "Escape", action = act.PopKeyTable },
{ key = "Enter", action = act.PopKeyTable },
2023-03-22 11:20:01 +00:00
},
}
return config
end
return module