Skip to content

Instantly share code, notes, and snippets.

@gsinclair
Created December 23, 2024 04:53
Show Gist options
  • Save gsinclair/6ae25f47df4770d3941c174d05eab6b8 to your computer and use it in GitHub Desktop.
Save gsinclair/6ae25f47df4770d3941c174d05eab6b8 to your computer and use it in GitHub Desktop.
A WezTerm config for Mac which is opinionated but has a small surface area.
local wezterm = require('wezterm')
local act = wezterm.action
local c = wezterm.config_builder()
--
-- General settings: reload config, close confirmation, key encoding
--
c.automatically_reload_config = true
c.window_close_confirmation = 'NeverPrompt'
-- c.enable_kitty_keyboard = true -- I had hopes for this but they didn't eventuate
c.enable_csi_u_key_encoding = true -- This finally got C-; working
if false then
-- Easily toggle this setting when inspection of keyboard events is necessary.
-- To see the log, start wezterm from another terminal (command: wezterm).
-- The debug information will appear in the terminal (standard error).
c.debug_key_events = true
end
--
-- General appearance: window details, color scheme, cursor
--
c.window_decorations = 'RESIZE'
c.initial_rows = 500
c.initial_cols = 500
c.font = wezterm.font("MesloLGL Nerd Font Mono", {
weight = "Regular", stretch = "Normal", style = "Normal"
})
c.window_padding = { left = 15, right = 15, top = 15, bottom = 15, }
c.enable_tab_bar = false
c.color_scheme = 'Tokyo Night Moon'
c.default_cursor_style = 'BlinkingBar'
--
-- Keybindings: I want to scrap the defaults and build just what I want, to avoid
-- clashes with tmux and neovim.
--
c.disable_default_key_bindings = true
-- Input: 'OPT LeftArrow ALT b'
-- Output: { mods = 'OPT', key = 'LeftArrow', action = ... (press ALT-b) ... }
local bindkey = function(text)
local mod1, key1, mod2, key2 = table.unpack(wezterm.shell_split(text))
return {
mods = mod1,
key = key1,
action = wezterm.action.SendKey { mods = mod2, key = key2 }
}
end
-- Input: 'CMD c', act.CopyTo 'Clipboard'
-- Output: { mods = 'CMD', key = 'c', action = act.CopyTo 'Clipboard' }
local bindaction = function(text, action)
local mod1, key1 = table.unpack(wezterm.shell_split(text))
return {
mods = mod1, key = key1, action = action
}
end
c.keys = {
-- CTRL-SHIFT-P to activate command palatte if I get in trouble.
-- CTRL-SHIFT-L to show debug overlay (again, if I get in trouble).
bindaction('CTRL P', act.ActivateCommandPalette),
bindaction('CTRL L', act.ShowDebugOverlay),
bindkey('OPT LeftArrow ALT b'), -- back one word
bindkey('OPT RightArrow ALT f'), -- forward one word
bindkey('CMD LeftArrow CTRL a'), -- beginning of line
bindkey('CMD RightArrow CTRL e'), -- end of line
bindkey('CMD Backspace CTRL u'), -- delete whole line
-- Tab next and previous: C-Tab and C-S-Tab, or (normal for Mac) CMD-{}
bindaction('CTRL Tab', act.ActivateTabRelative(1)),
bindaction('CTRL|SHIFT Tab', act.ActivateTabRelative(-1)),
bindaction('CMD }', act.ActivateTabRelative(1)),
bindaction('CMD {', act.ActivateTabRelative(-1)),
-- Clipboard
bindaction('CMD c', act.CopyTo 'Clipboard'),
bindaction('CMD v', act.PasteFrom 'Clipboard'),
-- Search
bindaction('CMD f', act.Search 'CurrentSelectionOrEmptyString'),
-- Normal stuff like quit, hide, minimise, new window, new tab, change font size, toggle full screen
bindaction('CMD q', act.QuitApplication),
bindaction('CMD h', act.HideApplication),
bindaction('CMD m', act.Hide),
bindaction('CMD n', act.SpawnWindow),
bindaction('CMD Enter', act.ToggleFullScreen),
bindaction('CMD -', act.DecreaseFontSize),
bindaction('CMD =', act.IncreaseFontSize),
bindaction('CMD t', act.SpawnTab 'CurrentPaneDomain'),
bindaction('CMD t', act.CloseCurrentTab { confirm = true }),
bindaction('CMD w', act.CloseCurrentTab { confirm = true }),
-- Clear scrollback
bindaction('CMD k', act.ClearScrollback 'ScrollbackOnly'),
-- Reload configuration (shouldn't be needed?)
bindaction('CMD r', act.ReloadConfiguration),
-- I don't have a PageUp/Down key, but may bind something later.
bindaction('SHIFT PageUp', act.ScrollByPage(-1)),
bindaction('SHIFT PageDown', act.ScrollByPage(1)),
-- Interesting, but clash with tmux or neovim, or just have awkward keys.
-- { key = 'DownArrow', mods = 'SHIFT|ALT|CTRL', action = act.AdjustPaneSize{ 'Down', 1 } },
-- { key = 'DownArrow', mods = 'SHIFT|CTRL', action = act.ActivatePaneDirection 'Down' },
-- { key = 'UpArrow', mods = 'SHIFT|ALT|CTRL', action = act.AdjustPaneSize{ 'Up', 1 } },
-- { key = 'UpArrow', mods = 'SHIFT|CTRL', action = act.ActivatePaneDirection 'Up' },
-- { key = 'RightArrow', mods = 'SHIFT|ALT|CTRL', action = act.AdjustPaneSize{ 'Right', 1 } },
-- { key = 'RightArrow', mods = 'SHIFT|CTRL', action = act.ActivatePaneDirection 'Right' },
-- { key = 'LeftArrow', mods = 'SHIFT|ALT|CTRL', action = act.AdjustPaneSize{ 'Left', 1 } },
-- { key = 'LeftArrow', mods = 'SHIFT|CTRL', action = act.ActivatePaneDirection 'Left' },
-- { key = 'phys:Space', mods = 'SHIFT|CTRL', action = act.QuickSelect },
} -- </keys>
c.key_tables = {
-- TODO: review these when I explore copy mode
copy_mode = {
{ key = 'Tab', mods = 'NONE', action = act.CopyMode 'MoveForwardWord' },
{ key = 'Tab', mods = 'SHIFT', action = act.CopyMode 'MoveBackwardWord' },
{ key = 'Enter', mods = 'NONE', action = act.CopyMode 'MoveToStartOfNextLine' },
{ key = 'Escape', mods = 'NONE', action = act.CopyMode 'Close' },
{ key = 'Space', mods = 'NONE', action = act.CopyMode { SetSelectionMode = 'Cell' } },
{ key = '$', mods = 'NONE', action = act.CopyMode 'MoveToEndOfLineContent' },
{ key = '$', mods = 'SHIFT', action = act.CopyMode 'MoveToEndOfLineContent' },
{ key = ',', mods = 'NONE', action = act.CopyMode 'JumpReverse' },
{ key = '0', mods = 'NONE', action = act.CopyMode 'MoveToStartOfLine' },
{ key = ';', mods = 'NONE', action = act.CopyMode 'JumpAgain' },
{ key = 'F', mods = 'NONE', action = act.CopyMode { JumpBackward = { prev_char = false } } },
{ key = 'F', mods = 'SHIFT', action = act.CopyMode { JumpBackward = { prev_char = false } } },
{ key = 'G', mods = 'NONE', action = act.CopyMode 'MoveToScrollbackBottom' },
{ key = 'G', mods = 'SHIFT', action = act.CopyMode 'MoveToScrollbackBottom' },
{ key = 'H', mods = 'NONE', action = act.CopyMode 'MoveToViewportTop' },
{ key = 'H', mods = 'SHIFT', action = act.CopyMode 'MoveToViewportTop' },
{ key = 'L', mods = 'NONE', action = act.CopyMode 'MoveToViewportBottom' },
{ key = 'L', mods = 'SHIFT', action = act.CopyMode 'MoveToViewportBottom' },
{ key = 'M', mods = 'NONE', action = act.CopyMode 'MoveToViewportMiddle' },
{ key = 'M', mods = 'SHIFT', action = act.CopyMode 'MoveToViewportMiddle' },
{ key = 'O', mods = 'NONE', action = act.CopyMode 'MoveToSelectionOtherEndHoriz' },
{ key = 'O', mods = 'SHIFT', action = act.CopyMode 'MoveToSelectionOtherEndHoriz' },
{ key = 'T', mods = 'NONE', action = act.CopyMode { JumpBackward = { prev_char = true } } },
{ key = 'T', mods = 'SHIFT', action = act.CopyMode { JumpBackward = { prev_char = true } } },
{ key = 'V', mods = 'NONE', action = act.CopyMode { SetSelectionMode = 'Line' } },
{ key = 'V', mods = 'SHIFT', action = act.CopyMode { SetSelectionMode = 'Line' } },
{ key = '^', mods = 'NONE', action = act.CopyMode 'MoveToStartOfLineContent' },
{ key = '^', mods = 'SHIFT', action = act.CopyMode 'MoveToStartOfLineContent' },
{ key = 'b', mods = 'NONE', action = act.CopyMode 'MoveBackwardWord' },
{ key = 'b', mods = 'ALT', action = act.CopyMode 'MoveBackwardWord' },
{ key = 'b', mods = 'CTRL', action = act.CopyMode 'PageUp' },
{ key = 'c', mods = 'CTRL', action = act.CopyMode 'Close' },
{ key = 'd', mods = 'CTRL', action = act.CopyMode { MoveByPage = (0.5) } },
{ key = 'e', mods = 'NONE', action = act.CopyMode 'MoveForwardWordEnd' },
{ key = 'f', mods = 'NONE', action = act.CopyMode { JumpForward = { prev_char = false } } },
{ key = 'f', mods = 'ALT', action = act.CopyMode 'MoveForwardWord' },
{ key = 'f', mods = 'CTRL', action = act.CopyMode 'PageDown' },
{ key = 'g', mods = 'NONE', action = act.CopyMode 'MoveToScrollbackTop' },
{ key = 'g', mods = 'CTRL', action = act.CopyMode 'Close' },
{ key = 'h', mods = 'NONE', action = act.CopyMode 'MoveLeft' },
{ key = 'j', mods = 'NONE', action = act.CopyMode 'MoveDown' },
{ key = 'k', mods = 'NONE', action = act.CopyMode 'MoveUp' },
{ key = 'l', mods = 'NONE', action = act.CopyMode 'MoveRight' },
{ key = 'm', mods = 'ALT', action = act.CopyMode 'MoveToStartOfLineContent' },
{ key = 'o', mods = 'NONE', action = act.CopyMode 'MoveToSelectionOtherEnd' },
{ key = 'q', mods = 'NONE', action = act.CopyMode 'Close' },
{ key = 't', mods = 'NONE', action = act.CopyMode { JumpForward = { prev_char = true } } },
{ key = 'u', mods = 'CTRL', action = act.CopyMode { MoveByPage = (-0.5) } },
{ key = 'v', mods = 'NONE', action = act.CopyMode { SetSelectionMode = 'Cell' } },
{ key = 'v', mods = 'CTRL', action = act.CopyMode { SetSelectionMode = 'Block' } },
{ key = 'w', mods = 'NONE', action = act.CopyMode 'MoveForwardWord' },
{ key = 'y', mods = 'NONE', action = act.Multiple { { CopyTo = 'ClipboardAndPrimarySelection' }, { CopyMode = 'Close' } } },
{ key = 'PageUp', mods = 'NONE', action = act.CopyMode 'PageUp' },
{ key = 'PageDown', mods = 'NONE', action = act.CopyMode 'PageDown' },
{ key = 'End', mods = 'NONE', action = act.CopyMode 'MoveToEndOfLineContent' },
{ key = 'Home', mods = 'NONE', action = act.CopyMode 'MoveToStartOfLine' },
{ key = 'LeftArrow', mods = 'NONE', action = act.CopyMode 'MoveLeft' },
{ key = 'LeftArrow', mods = 'ALT', action = act.CopyMode 'MoveBackwardWord' },
{ key = 'RightArrow', mods = 'NONE', action = act.CopyMode 'MoveRight' },
{ key = 'RightArrow', mods = 'ALT', action = act.CopyMode 'MoveForwardWord' },
{ key = 'UpArrow', mods = 'NONE', action = act.CopyMode 'MoveUp' },
{ key = 'DownArrow', mods = 'NONE', action = act.CopyMode 'MoveDown' },
}, -- </copy_mode>
-- TODO: review these when I explore search mode
search_mode = {
{ key = 'Enter', mods = 'NONE', action = act.CopyMode 'PriorMatch' },
{ key = 'Escape', mods = 'NONE', action = act.CopyMode 'Close' },
{ key = 'n', mods = 'CTRL', action = act.CopyMode 'NextMatch' },
{ key = 'p', mods = 'CTRL', action = act.CopyMode 'PriorMatch' },
{ key = 'r', mods = 'CTRL', action = act.CopyMode 'CycleMatchType' },
{ key = 'u', mods = 'CTRL', action = act.CopyMode 'ClearPattern' },
{ key = 'PageUp', mods = 'NONE', action = act.CopyMode 'PriorMatchPage' },
{ key = 'PageDown', mods = 'NONE', action = act.CopyMode 'NextMatchPage' },
{ key = 'UpArrow', mods = 'NONE', action = act.CopyMode 'PriorMatch' },
{ key = 'DownArrow', mods = 'NONE', action = act.CopyMode 'NextMatch' },
}, -- </search_mode>
} -- </key_tables>
return c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment