Collecting my attempts to improve at tech, art, and life

My WezTerm Config

Tags: config

WezTerm is my preferred terminal emulator these days. Partly because I am starting to enjoy configuring programs with Lua.

file:wezterm/wezterm.lua
local wezterm = require 'wezterm';

As always, my strongly preferred programming font is Fantasque Sans Mono. This may take a little fiddling to get it just so under all relevant operating systems.

local terminal_font = wezterm.font("Fantasque Sans Mono")

Keybindings

I use Control+SPC as my leader key, prefixing many WezTerm bindings. Someday I may adjust to WezTerm as my multiplexer instead of tmux. Then I’ll switch the leader binding to Control+Z maybe.

local leader_key = {
    key = ' ',
    mods = 'CTRL',
    timeout_milliseconds = 1000,
}
ℹ️ Note

I saved the default keybindings before I got carried away.

Write WezTerm default key table to disk
wezterm show-keys --lua | save --raw default_keys.lua

| save --raw keys.lua is how you redirect output in Nushell. In Bash that might look like wezterm show-keys --lua > default_keys.lua.

Anyways, you don’t have to do any of that. You can just check the default assignments online.

The keymap so far kind of reflects my current tmux keybindings. Keeps the muscle memory at close to relevant.

local keymap = {
    -- tab and pane management
    {
        key = 'c',
        mods = 'LEADER',
        action = wezterm.action.SpawnTab 'CurrentPaneDomain',
    },
    {
        key = 'C',
        mods = 'LEADER|SHIFT',
        action = wezterm.action.SpawnTab 'DefaultDomain',
    },
    {
        key = '|',
        mods = 'LEADER|SHIFT',
        action = wezterm.action.SplitHorizontal {
            domain = 'CurrentPaneDomain',
        },
    },
    {
        key = '-',
        mods = 'LEADER',
        action = wezterm.action.SplitVertical {
            domain = 'CurrentPaneDomain',
        },
    },
    -- tab and pane navigation
    {
        key = 'n',
        mods = 'LEADER',
        action = wezterm.action.ActivateTabRelative(1),
    },
    {
        key = 'p',
        mods = 'LEADER',
        action = wezterm.action.ActivateTabRelative(-1),
    },
    {
        key = 'l',
        mods = 'LEADER',
        action = wezterm.action.ActivatePaneDirection 'Right',
    },
    {
        key = 'h',
        mods = 'LEADER',
        action = wezterm.action.ActivatePaneDirection 'Left',
    },
    {
        key = 'j',
        mods = 'LEADER',
        action = wezterm.action.ActivatePaneDirection 'Down',
    },
    {
        key = 'k',
        mods = 'LEADER',
        action = wezterm.action.ActivatePaneDirection 'Up',
    },
    -- session controls
    {
        key = 'r',
        mods = 'LEADER',
        action = wezterm.action.ReloadConfiguration,
    },
}

config table

local config = {
    audible_bell = 'Disabled',
    color_scheme = 'Fairyfloss',
    colors = {
        visual_bell = '#602020',
    },
    font = terminal_font,
    font_size = 14.0,
    keys = keymap,
    leader = leader_key,
    set_environment_variables = {
        COLORTERM = 'truecolor',
    },
    term = "wezterm",
    visual_bell = {
        fade_in_function = 'EaseIn',
        fade_in_duration_ms = 150,
        fade_out_function = 'EaseOut',
        fade_out_duration_ms = 150,
    },
}

Just Windows

I fire up Nushell by default on Windows, but I also keep an entry handy for WSL.

if wezterm.target_triple == 'x86_64-pc-windows-msvc' then
  config["default_prog"] = {"C:/Program Files/nu/bin/nu.exe"}

  config.launch_menu = {	
  	{
    	label = 'Ubuntu',
    	args = { 'wsl.exe', '--shell-type', 'login', '--cd', '/home/random' },
  	}
  }
end

Wrap it up

Return the config table at the end of the file so WezTerm can process it.

return config