diff --git a/keymaps.lua b/keymaps.lua index 6b67992..4969fe3 100644 --- a/keymaps.lua +++ b/keymaps.lua @@ -1,102 +1,113 @@ local wezterm = require("wezterm") local act = wezterm.action -local gui = wezterm.gui local M = {} local direction_keys = { - Left = "h", - Down = "j", - Up = "k", - Right = "l", - -- reverse lookup - h = "Left", - j = "Down", - k = "Up", - l = "Right", + Left = "h", + Down = "j", + Up = "k", + Right = "l", + -- reverse lookup + h = "Left", + j = "Down", + k = "Up", + l = "Right", } -- if you are *NOT* lazy-loading smart-splits.nvim (recommended) local function is_vim(pane) - -- this is set by the plugin, and unset on ExitPre in Neovim - return pane:get_user_vars().IS_NVIM == "true" + -- this is set by the plugin, and unset on ExitPre in Neovim + return pane:get_user_vars().IS_NVIM == "true" end local function split_nav(resize_or_move, key) - return { - key = key, - mods = resize_or_move == "resize" and "META" or "CTRL", - action = wezterm.action_callback(function(win, pane) - if is_vim(pane) then - -- pass the keys through to vim/nvim - win:perform_action({ - SendKey = { key = key, mods = resize_or_move == "resize" and "META" or "CTRL" }, - }, pane) - else - if resize_or_move == "resize" then - win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane) - else - win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane) - end - end - end), - } + return { + key = key, + mods = resize_or_move == "resize" and "META" or "CTRL", + action = wezterm.action_callback(function(win, pane) + if is_vim(pane) then + -- pass the keys through to vim/nvim + win:perform_action({ + SendKey = { key = key, mods = resize_or_move == "resize" and "META" or "CTRL" }, + }, pane) + else + if resize_or_move == "resize" then + win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane) + else + win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane) + end + end + end), + } end function M.options(config) - -- - config.leader = { key = "a", mods = "CTRL" } + -- + config.leader = { key = "a", mods = "CTRL" } - config.keys = { - { key = "a", mods = "LEADER|CTRL", action = wezterm.action({ SendString = "\x01" }) }, - { key = "-", mods = "LEADER", action = wezterm.action({ SplitPane = { direction = "Down", size = { Percent = 25 } } }) }, - { - key = "\\", - mods = "LEADER", - action = wezterm.action({ SplitPane = { direction = "Right", size = { Percent = 25 } } }) - }, - { key = "z", mods = "LEADER", action = "TogglePaneZoomState" }, - { key = "c", mods = "LEADER", action = wezterm.action({ SpawnTab = "CurrentPaneDomain" }) }, - { key = "x", mods = "LEADER", action = wezterm.action.CloseCurrentPane({ confirm = true }) }, - { key = "n", mods = "LEADER", action = wezterm.action.ToggleFullScreen }, - { key = "p", mods = "CTRL|SHIFT", action = wezterm.action.ActivateCommandPalette }, - { key = "c", mods = "CTRL|SHIFT", action = wezterm.action.CopyTo("ClipboardAndPrimarySelection") }, - { key = "v", mods = "CTRL|SHIFT", action = wezterm.action.PasteFrom("Clipboard") }, - -- move between split panes - split_nav("move", "h"), - split_nav("move", "j"), - split_nav("move", "k"), - split_nav("move", "l"), - -- resize panes - split_nav("resize", "h"), - split_nav("resize", "j"), - split_nav("resize", "k"), - { - key = ",", - mods = "LEADER", - action = act.PromptInputLine({ - description = "Enter new name for tab", - action = wezterm.action_callback(function(window, pane, line) - -- line will be `nil` if they hit escape without entering anything - -- An empty string if they just hit enter - -- Or the actual line of text they wrote - if line then - window:active_tab():set_title(line) - end - end), - }), - }, - split_nav("resize", "l"), - } + config.keys = { + { + key = "s", + mods = "LEADER", + action = wezterm.action_callback(function(win, pane) + wezterm.log_info("Hello from callback!") + wezterm.log_info("WindowID:", win:window_id(), "PaneID:", pane:pane_id()) + end), + }, + { key = "a", mods = "LEADER|CTRL", action = wezterm.action({ SendString = "\x01" }) }, + { + key = "-", + mods = "LEADER", + action = wezterm.action({ SplitPane = { direction = "Down", size = { Percent = 25 } } }), + }, + { + key = "\\", + mods = "LEADER", + action = wezterm.action({ SplitPane = { direction = "Right", size = { Percent = 25 } } }), + }, + { key = "z", mods = "LEADER", action = "TogglePaneZoomState" }, + { key = "c", mods = "LEADER", action = wezterm.action({ SpawnTab = "CurrentPaneDomain" }) }, + { key = "x", mods = "LEADER", action = wezterm.action.CloseCurrentPane({ confirm = true }) }, + { key = "n", mods = "LEADER", action = wezterm.action.ToggleFullScreen }, + { key = "p", mods = "CTRL|SHIFT", action = wezterm.action.ActivateCommandPalette }, + { key = "c", mods = "CTRL|SHIFT", action = wezterm.action.CopyTo("ClipboardAndPrimarySelection") }, + { key = "v", mods = "CTRL|SHIFT", action = wezterm.action.PasteFrom("Clipboard") }, + -- move between split panes + split_nav("move", "h"), + split_nav("move", "j"), + split_nav("move", "k"), + split_nav("move", "l"), + -- resize panes + split_nav("resize", "h"), + split_nav("resize", "j"), + split_nav("resize", "k"), + { + key = ",", + mods = "LEADER", + action = act.PromptInputLine({ + description = "Enter new name for tab", + action = wezterm.action_callback(function(window, pane, line) + -- line will be `nil` if they hit escape without entering anything + -- An empty string if they just hit enter + -- Or the actual line of text they wrote + if line then + window:active_tab():set_title(line) + end + end), + }), + }, + split_nav("resize", "l"), + } - for i = 1, 8 do - -- CTRL+ALT + number to activate that tab - table.insert(config.keys, { - key = tostring(i), - mods = "LEADER", - action = wezterm.action.ActivateTab(i - 1), - }) - end + for i = 1, 8 do + -- CTRL+ALT + number to activate that tab + table.insert(config.keys, { + key = tostring(i), + mods = "LEADER", + action = wezterm.action.ActivateTab(i - 1), + }) + end end return M