深化解析 WezTerm 快捷键装备:键绑定和鼠标绑定
深化解析 WezTerm 的快捷键装备:键绑定和鼠标绑定
WezTerm 是一个高性能的跨渠道终端模拟器,它供给了广泛的自界说选项,包含键绑定和鼠标绑定,使得用户能够依据自己的需求优化操作界面。本文将具体介绍几个要害的自界说功用,解说它们的用处,并展现怎么装备这些功用来提高终端运用体会。
创立一个键绑定
WezTerm 的键绑定功用答应用户为特定的操作界说快捷键。需求留意的是假如想要绑定大写或许特别字符,需求设置key的一起设置mods,例如:
{ key = 'H', mods = 'SHIFT|LEADER', action = act.AdjustPaneSize { 'Left', 10 } },
这样装备的快捷键能够经过按下 Leader
后,再按下 Shift + h
(H)
来调整面板巨细。
详见:https://wezfurlong.org/wezterm/config/keys.html
装备 LEADER 键
首要,界说一个 LEADER 键,作为其他快捷键的前缀。在 WezTerm 中,LEADER 键的设置如下:
local leader = {
key = 'Space',
mods = 'SUPER|ALT',
timeout_milliseconds = math.maxinteger
}
这个设置答应用户经过一起按下 Win + Alt + Space
来激活领导键形式,完成相似 tmux 的操作方法。
根本的操作:
{ key = "c", mods = "LEADER", action = act { SpawnTab = "CurrentPaneDomain" } },
{ key = "&", mods = "LEADER", action = act { CloseCurrentTab = { confirm = false } } },
{ key = "q", mods = "LEADER", action = act { CloseCurrentTab = { confirm = false } } },
{ key = "x", mods = "LEADER", action = act { CloseCurrentPane = { confirm = false } } },
{ key = 's', mods = 'LEADER', action = act.PaneSelect },
{ key = 'S', mods = 'SHIFT|LEADER', action = act.PaneSelect { mode = 'SwapWithActive' } },
{ key = 'w', mods = 'LEADER', action = act.ShowTabNavigator },
{ key = "k", mods = "LEADER", action = act.RotatePanes "Clockwise" },
{ key = "T", mods = "SHIFT|CTRL", action = act { SpawnTab = "CurrentPaneDomain" } },
{ key = "W", mods = "SHIFT|CTRL", action = act { CloseCurrentTab = { confirm = true } } },
{ key = "V", mods = "SHIFT|CTRL", action = act { PasteFrom = "Clipboard" } },
{ key = "C", mods = "SHIFT|CTRL", action = act { CopyTo = "Clipboard" } },
{ key = "Tab", mods = "CTRL", action = act.ActivateTabRelative(1) },
{ key = "Tab", mods = "SHIFT|CTRL", action = act.ActivateTabRelative(-1) },
{ key = "Return", mods = "ALT", action = "ToggleFullScreen" },
{ key = "F11", mods = "", action = "ToggleFullScreen" },
键绑定表格
操作 | 快捷键 | LEADER (大写字母代表 Shift + 字母) |
---|---|---|
根本操作 | ||
新建标签 | CTRL + SHIFT + t 或 ALT + t | c |
新建面板 | CTRL + SHIFT(ALT) + Enter 或 ALT + n | Enter |
封闭标签 | CTRL + SHIFT + w 或 ALT + q | & 或 q |
封闭面板 | ALT + x | x |
全屏 | ALT + Enter | |
全屏 | F11 | |
仿制 | CTRL + SHIFT + c | |
张贴 | CTRL + SHIFT + v | |
智能仿制 | CTRL + c | |
面板操作 | ||
智能切割 | CTRL + (SHIFT)ALT + Enter | Enter |
水平切割 | CTRL + ALT + - | - |
笔直切割 | CTRL + ALT + \ | \ |
面板挑选 | CTRL + ALT + hjkl\Arrow | hjkl 或 ArrowKey |
面板挑选 | ALT + [ ] | |
面板挑选 | ALT + hjkl | |
面板挑选 | ALT + s | s |
交流面板 | S | |
旋转面板 | k | |
面板调整 | ALT + Arrow | HJKL 或 SHIFT + ArrowKey 或 r 进入 resize_pane 形式(timeout 5s) |
面板调整 | CTRL + SHIFT + ALT + HJKL\Arrow | |
标签操作 | ||
标签切换 | CTRL + TAB 或 CTRL + SHIFT + TAB | |
标签切换 | (CTRL) + ALT + 1-0 | 1-0 |
标签切换 | CTRL + SHIFT + LEFT RIGHT | |
标签切换 | CTRL + Alt + [ ] | n p |
标签移动 | CTRL + SHIFT + UP DOWN | |
标签移动 | SHIFT + ALT + [ ] | N P 或 R 进入 move_tab 形式(timeout 5s) |
字体 | ||
扩大字体 | CTRL + SHIFT + = | |
缩小字体 | CTRL + SHIFT + - | |
重置字体 | CTRL + SHIFT + 0 |
面板操作:激活与调整
ALT 风格的装备:
一些程序比方 tmux zellij 等会运用这些快捷键,所以这儿自界说 create_keybind
函数来完成辨认当时面板是否在这些程序中,假如是则不履行对应的操作,而是直接传递给程序。create_keybind
函数的完成见完好装备文件。
create_keybind("SpawnTab", "ALT", "t", "CurrentPaneDomain"),
create_keybind("smart_split", "ALT", "n"),
create_keybind("CloseCurrentTab", "ALT", "q"),
create_keybind("CloseCurrentPane", "ALT", "x"),
create_keybind("ActivatePaneDirection", "ALT", "h", "Left"),
create_keybind("ActivatePaneDirection", "ALT", "j", "Down"),
create_keybind("ActivatePaneDirection", "ALT", "k", "Up"),
create_keybind("ActivatePaneDirection", "ALT", "l", "Right")
create_keybind("ActivatePaneDirection", "ALT", "[", "Prev"),
create_keybind("ActivatePaneDirection", "ALT", "]", "Next"),
create_keybind("AdjustPaneSize", "ALT", "LeftArrow", "Left"),
create_keybind("AdjustPaneSize", "ALT", "RightArrow", "Right"),
create_keybind("AdjustPaneSize", "ALT", "UpArrow", "Up"),
create_keybind("AdjustPaneSize", "ALT", "DownArrow", "Down")
WezTerm Leader 键的缺陷在于每个 action 都需求按下 Leader 键,这样会导致操作繁琐。例如,咱们假如直接运用
{ key = 'h', mods = 'LEADER', action = act.ActivatePaneDirection 'Left' },
{ key = 'j', mods = 'LEADER', action = act.ActivatePaneDirection 'Down' },
{ key = 'k', mods = 'LEADER', action = act.ActivatePaneDirection 'Up' },
{ key = 'l', mods = 'LEADER', action = act.ActivatePaneDirection 'Right' }
这样装备的问题在于,用户每切换一次都需求按下一次 Leader 键。为了处理这个问题,咱们能够创立一个函数 activate_pane_with_dir 来激活指定方向的面板,并经过 resize_pane_with_dir 来调整面板巨细。这两个函数会调用对应action后,再调用 ActivateKeyTable 来激活对应的快捷键表。这样就能够像 tmux 相同,按下一次 Leader 键,然后接连按下 hjkl 来切换面板。
key_table 部分装备如下:
local key_tables = {
resize_pane = {
{ key = 'LeftArrow', action = act.AdjustPaneSize { 'Left', 1 } },
{ key = 'h', action = act.AdjustPaneSize { 'Left', 1 } },
{ key = 'LeftArrow', action = act.AdjustPaneSize { 'Left', 10 }, mods = 'SHIFT' },
{ key = 'H', action = act.AdjustPaneSize { 'Left', 10 }, mods = 'SHIFT' },
{ key = 'RightArrow', action = act.AdjustPaneSize { 'Right', 1 } },
{ key = 'l', action = act.AdjustPaneSize { 'Right', 1 } },
{ key = 'RightArrow', action = act.AdjustPaneSize { 'Right', 10 }, mods = 'SHIFT' },
{ key = 'L', action = act.AdjustPaneSize { 'Right', 10 }, mods = 'SHIFT' },
{ key = 'UpArrow', action = act.AdjustPaneSize { 'Up', 1 } },
{ key = 'k', action = act.AdjustPaneSize { 'Up', 1 } },
{ key = 'UpArrow', action = act.AdjustPaneSize { 'Up', 10 }, mods = 'SHIFT' },
{ key = 'K', action = act.AdjustPaneSize { 'Up', 10 }, mods = 'SHIFT' },
{ key = 'DownArrow', action = act.AdjustPaneSize { 'Down', 1 } },
{ key = 'j', action = act.AdjustPaneSize { 'Down', 1 } },
{ key = 'DownArrow', action = act.AdjustPaneSize { 'Down', 10 }, mods = 'SHIFT' },
{ key = 'J', action = act.AdjustPaneSize { 'Down', 10 }, mods = 'SHIFT' },
{ key = 'Escape', action = 'PopKeyTable' },
{ key = 'q', action = 'PopKeyTable' },
{ key = 'Q', action = 'PopKeyTable' }
},
......
activate_tab = {
{ key = 'N', action = act.ActivateTab(0) },
{ key = 'P', action = act.ActivateTab(-1) },
{ key = 'n', action = act.ActivateTabRelative(1) },
{ key = 'p', action = act.ActivateTabRelative(-1) },
{ key = 'h', action = act.ActivateTabRelative(-1) },
{ key = 'j', action = act.ActivateTabRelative(1) },
{ key = 'k', action = act.ActivateTabRelative(-1) },
{ key = 'l', action = act.ActivateTabRelative(1) },
{ key = 'LeftArrow', action = act.ActivateTabRelative(-1) },
{ key = 'RightArrow', action = act.ActivateTabRelative(1) },
{ key = 'UpArrow', action = act.ActivateTabRelative(-1) },
{ key = 'DownArrow', action = act.ActivateTabRelative(1) },
{ key = 'Escape', action = 'PopKeyTable' },
}
local function activate_pane_with_dir(dir)
return function(win, pane)
win:perform_action(wezterm.action.ActivatePaneDirection(dir), pane)
win:perform_action(wezterm.action.ActivateKeyTable { name = 'activate_pane', one_shot = false, timeout_milliseconds = 600 }, pane)
end
end
local function resize_pane_with_dir(dir)
return function(win, pane)
win:perform_action(wezterm.action.AdjustPaneSize { dir, 10 }, pane)
win:perform_action(wezterm.action.ActivateKeyTable { name = 'resize_pane', one_shot = false, timeout_milliseconds = 600 }, pane)
end
end
local function activate_tab_with_dir(dir)
return function(win, pane)
win:perform_action(act.ActivateTabRelative(dir), pane)
win:perform_action(act.ActivateKeyTable { name = 'activate_tab', one_shot = false, timeout_milliseconds = 600 },
pane)
end
end
local function move_tab_with_dir(dir)
return function(win, pane)
win:perform_action(act.MoveTabRelative(dir), pane)
win:perform_action(act.ActivateKeyTable { name = 'move_tab', one_shot = false, timeout_milliseconds = 600 },
pane)
end
end
装备如下:
{ key = "a", mods = "LEADER", action = act.ActivateKeyTable { name = 'activate_pane', one_shot = false, timeout_milliseconds = 5000 } },
{ key = 'h', mods = 'LEADER', action = wezterm.action_callback(activate_pane_with_dir("Left")) },
{ key = 'j', mods = 'LEADER', action = wezterm.action_callback(activate_pane_with_dir("Down")) },
{ key = 'k', mods = 'LEADER', action = wezterm.action_callback(activate_pane_with_dir("Up")) },
{ key = 'l', mods = 'LEADER', action = wezterm.action_callback(activate_pane_with_dir("Right")) },
{ key = "UpArrow", mods = "LEADER", action = wezterm.action_callback(activate_pane_with_dir("Up")) },
{ key = "DownArrow", mods = "LEADER", action = wezterm.action_callback(activate_pane_with_dir("Down")) },
{ key = "LeftArrow", mods = "LEADER", action = wezterm.action_callback(activate_pane_with_dir("Left")) },
{ key = "RightArrow", mods = "LEADER", action = wezterm.action_callback(activate_pane_with_dir("Right")) },
{ key = "h", mods = "ALT|CTRL", action = act { ActivatePaneDirection = "Left" } },
{ key = "j", mods = "ALT|CTRL", action = act { ActivatePaneDirection = "Down" } },
{ key = "k", mods = "ALT|CTRL", action = act { ActivatePaneDirection = "Up" } },
{ key = "l", mods = "ALT|CTRL", action = act { ActivatePaneDirection = "Right" } },
{ key = "UpArrow", mods = "ALT|CTRL", action = act { ActivatePaneDirection = "Up" } },
{ key = "DownArrow", mods = "ALT|CTRL", action = act { ActivatePaneDirection = "Down" } },
{ key = "LeftArrow", mods = "ALT|CTRL", action = act { ActivatePaneDirection = "Left" } },
{ key = "RightArrow", mods = "ALT|CTRL", action = act { ActivatePaneDirection = "Right" } },
{ key = 'r', mods = 'LEADER', action = act.ActivateKeyTable { name = 'resize_pane', one_shot = false, timeout_milliseconds = 5000 } },
-- use Multiple keybinds fails because of async, so use action_callback
{ key = 'H', mods = 'SHIFT|LEADER', action = wezterm.action_callback(resize_pane_with_dir("Left")) },
{ key = 'J', mods = 'SHIFT|LEADER', action = wezterm.action_callback(resize_pane_with_dir("Down")) },
{ key = 'K', mods = 'SHIFT|LEADER', action = wezterm.action_callback(resize_pane_with_dir("Up")) },
{ key = 'L', mods = 'SHIFT|LEADER', action = wezterm.action_callback(resize_pane_with_dir("Right")) },
{ key = "UpArrow", mods = "SHIFT|LEADER", action = wezterm.action_callback(resize_pane_with_dir("Up")) },
{ key = "DownArrow", mods = "SHIFT|LEADER", action = wezterm.action_callback(resize_pane_with_dir("Down")) },
{ key = "LeftArrow", mods = "SHIFT|LEADER", action = wezterm.action_callback(resize_pane_with_dir("Left")) },
{ key = "RightArrow", mods = "SHIFT|LEADER", action = wezterm.action_callback(resize_pane_with_dir("Right")) },
{ key = "h", mods = "SHIFT|ALT|CTRL", action = act { AdjustPaneSize = { "Left", 1 } } },
{ key = "l", mods = "SHIFT|ALT|CTRL", action = act { AdjustPaneSize = { "Right", 1 } } },
{ key = "k", mods = "SHIFT|ALT|CTRL", action = act { AdjustPaneSize = { "Up", 1 } } },
{ key = "j", mods = "SHIFT|ALT|CTRL", action = act { AdjustPaneSize = { "Down", 1 } } },
{ key = "UpArrow", mods = "SHIFT|ALT|CTRL", action = act { AdjustPaneSize = { "Up", 1 } } },
{ key = "DownArrow", mods = "SHIFT|ALT|CTRL", action = act { AdjustPaneSize = { "Down", 1 } } },
{ key = "LeftArrow", mods = "SHIFT|ALT|CTRL", action = act { AdjustPaneSize = { "Left", 1 } } },
{ key = "RightArrow", mods = "SHIFT|ALT|CTRL", action = act { AdjustPaneSize = { "Right", 1 } } },
面板切割
面板切割功用答应用户在一个窗口(window)中一起翻开多个面板(pane),然后能够并行处理多个使命。装备如下:
{ key = "-", mods = "LEADER", action = act { SplitVertical = { domain = "CurrentPaneDomain" } } },
{ key = "\\", mods = "LEADER", action = act { SplitHorizontal = { domain = "CurrentPaneDomain" } } },
{ key = "-", mods = "ALT|CTRL", action = act { SplitVertical = { domain = "CurrentPaneDomain" } } },
{ key = "\\", mods = "ALT|CTRL", action = act { SplitHorizontal = { domain = "CurrentPaneDomain" } } },
{ key = "_", mods = "SHIFT|CTRL", action = act { SplitVertical = { domain = "CurrentPaneDomain" } } },
{ key = "|", mods = "SHIFT|CTRL", action = act { SplitHorizontal = { domain = "CurrentPaneDomain" } } },
经过运用 LEADER
,ALT+CTRL
,SHIFT+CTRL
+ -
和 \
来别离进行笔直和水平切割。
装备智能切割功用
依据当时面板的尺度来决定是进行笔直切割仍是水平切割。
local function smart_split_callback(window, pane)
local dim = pane:get_dimensions()
if dim.pixel_height > dim.pixel_width then
window:perform_action(wezterm.action.SplitVertical({ domain = "CurrentPaneDomain" }), pane)
else
window:perform_action(wezterm.action.SplitHorizontal({ domain = "CurrentPaneDomain" }), pane)
end
end
local smart_split = wezterm.action_callback(smart_split_callback)
keys = {
{ key = "Enter", mods = "LEADER", action = smart_split },
{ key = "Enter", mods = "ALT|CTRL", action = smart_split },
{ key = "Enter", mods = "SHIFT|CTRL", action = smart_split }
}
标签导航
create_keybind("ActivateTabRelative", "ALT|CTRL", "[", -1),
create_keybind("ActivateTabRelative", "ALT|CTRL", "]", 1),
{ key = "A", mods = "SHIFT|LEADER", action = act.ActivateKeyTable { name = "activate_tab", one_shot = false, timeout_milliseconds = 5000 } },
{ key = "LeftArrow", mods = "SHIFT|CTRL", action = act.ActivateTabRelative(-1) },
{ key = "RightArrow", mods = "SHIFT|CTRL", action = act.ActivateTabRelative(1) },
{ key = "n", mods = "LEADER", action = act.ActivateTabRelative(1) },
{ key = "p", mods = "LEADER", action = act.ActivateTabRelative(-1) },
{ key = "1", mods = "LEADER", action = act { ActivateTab = 0 } },
{ key = "2", mods = "LEADER", action = act { ActivateTab = 1 } },
{ key = "3", mods = "LEADER", action = act { ActivateTab = 2 } },
{ key = "4", mods = "LEADER", action = act { ActivateTab = 3 } },
{ key = "5", mods = "LEADER", action = act { ActivateTab = 4 } },
{ key = "6", mods = "LEADER", action = act { ActivateTab = 5 } },
{ key = "7", mods = "LEADER", action = act { ActivateTab = 6 } },
{ key = "8", mods = "LEADER", action = act { ActivateTab = 7 } },
{ key = "9", mods = "LEADER", action = act { ActivateTab = 8 } },
{ key = "0", mods = "LEADER", action = act { ActivateTab = -1 } },
create_keybind("ActivateTab", "ALT", "1", 0),
create_keybind("ActivateTab", "ALT", "2", 1),
create_keybind("ActivateTab", "ALT", "3", 2),
create_keybind("ActivateTab", "ALT", "4", 3),
create_keybind("ActivateTab", "ALT", "5", 4),
create_keybind("ActivateTab", "ALT", "6", 5),
create_keybind("ActivateTab", "ALT", "7", 6),
create_keybind("ActivateTab", "ALT", "8", 7),
create_keybind("ActivateTab", "ALT", "9", 8),
create_keybind("ActivateTab", "ALT", "0", -1),
{ key = "1", mods = "ALT|CTRL", action = act { ActivateTab = 0 } },
{ key = "2", mods = "ALT|CTRL", action = act { ActivateTab = 1 } },
{ key = "3", mods = "ALT|CTRL", action = act { ActivateTab = 2 } },
{ key = "4", mods = "ALT|CTRL", action = act { ActivateTab = 3 } },
{ key = "5", mods = "ALT|CTRL", action = act { ActivateTab = 4 } },
{ key = "6", mods = "ALT|CTRL", action = act { ActivateTab = 5 } },
{ key = "7", mods = "ALT|CTRL", action = act { ActivateTab = 6 } },
{ key = "8", mods = "ALT|CTRL", action = act { ActivateTab = 7 } },
{ key = "9", mods = "ALT|CTRL", action = act { ActivateTab = 8 } },
{ key = "0", mods = "ALT|CTRL", action = act { ActivateTab = -1 } },
标签移动
{ key = "R", mods = "LEADER", action = act.ActivateKeyTable { name = "move_tab", one_shot = false, timeout_milliseconds = 5000 } },
create_keybind("MoveTabRelative", "SHIFT|ALT", "{", -1),
create_keybind("MoveTabRelative", "SHIFT|ALT", "}", 1),
{ key = "UpArrow", mods = "SHIFT|CTRL", action = act.MoveTabRelative(-1) },
{ key = "DownArrow", mods = "SHIFT|CTRL", action = act.MoveTabRelative(1) },
{ key = "P", mods = "SHIFT|LEADER", action = wezterm.action_callback(move_tab_with_dir(-1)) },
{ key = "N", mods = "SHIFT|LEADER", action = wezterm.action_callback(move_tab_with_dir(1)) },
鼠标绑定
沿袭 windows 终端的习气是:
{
event = { Down = { streak = 1, button = 'Right' } },
mods = "NONE",
action = wezterm.action_callback(function(window, pane)
local has_selection = window:get_selection_text_for_pane(pane) ~= ""
if has_selection then
window:pe