找回密码
 立即注册
首页 业界区 安全 Tmux工作流快捷键配置

Tmux工作流快捷键配置

康器 2026-1-19 01:25:17
说明

以下只列出主要配置内容,完整可运行的配置见:
https://github.com/timothy020/shell_configuration
WezTerm配置

配置Session,Window,Pannel操作快捷键

  • Session:快速detach,退出,查询所有session信息
  • Window:快速创建,切换,删除窗口
  • Pannel:快速分割,切换panel
配置文件: .config/wezterm/wezterm.lua
  1.   -- ╭─────────────────────────────────────────────────────────╮
  2.   -- │                    tmux session操作                      │
  3.   -- ╰─────────────────────────────────────────────────────────╯
  4.   k.cmd_to_tmux_prefix("d", "d"), -- Cmd+d: detach当前会话
  5.   k.cmd_to_tmux_prefix("e", "K"), -- Cmd+e: 退出当前会话(前提是在 ~/.tmux.conf配置了"bind K kill-session")
  6.   k.cmd_to_tmux_prefix("a", "w"), -- Cmd+a: 打开tmux-sessionx会话管理器
  7.   -- ╭─────────────────────────────────────────────────────────╮
  8.   -- │                    tmux windows操作                      │
  9.   -- ╰─────────────────────────────────────────────────────────╯
  10.   k.cmd_to_tmux_prefix("n", "c"),  -- Cmd+n: 创建新的tmux窗口
  11.   k.cmd_to_tmux_prefix("w", "&"),  -- Cmd+w: 关闭当前tmux窗口
  12.   k.cmd_to_tmux_prefix("H", "p"),  -- Cmd+j: 切换到上一个窗口
  13.   k.cmd_to_tmux_prefix("L", "n"),  -- Cmd+k: 切换到下一个窗口
  14.   k.cmd_to_tmux_prefix("0", "0"),  -- Cmd+0: 切换到tmux窗口0
  15.   k.cmd_to_tmux_prefix("1", "1"),  -- Cmd+1: 切换到tmux窗口1
  16.   k.cmd_to_tmux_prefix("2", "2"),  -- Cmd+2: 切换到tmux窗口2
  17.   k.cmd_to_tmux_prefix("3", "3"),  -- Cmd+3: 切换到tmux窗口3
  18.   k.cmd_to_tmux_prefix("4", "4"),  -- Cmd+4: 切换到tmux窗口4
  19.   k.cmd_to_tmux_prefix("5", "5"),  -- Cmd+5: 切换到tmux窗口5
  20.   k.cmd_to_tmux_prefix("6", "6"),  -- Cmd+6: 切换到tmux窗口6
  21.   k.cmd_to_tmux_prefix("7", "7"),  -- Cmd+7: 切换到tmux窗口7
  22.   k.cmd_to_tmux_prefix("8", "8"),  -- Cmd+8: 切换到tmux窗口8
  23.   k.cmd_to_tmux_prefix("9", "9"),  -- Cmd+9: 切换到tmux窗口9
  24.   -- ╭─────────────────────────────────────────────────────────╮
  25.   -- │                    tmux panel操作                        │
  26.   -- ╰─────────────────────────────────────────────────────────╯
  27.   k.cmd_to_tmux_prefix("p", '"'), -- Cmd+p: tmux水平分割面板
  28.   k.cmd_to_tmux_prefix("P", "%"), -- Cmd+Shift+p: tmux垂直分割面板
  29.   k.cmd_to_tmux_prefix("x", "x"), -- Cmd+x: 关闭当前tmux面板
  30.   -- Cmd+h/l/j/k: 切换到左一个/右一个/上一个/下一个面板
  31.   k.cmd_to_tmux_prefix("h", "LeftArrow"),
  32.   k.cmd_to_tmux_prefix("l", "RightArrow"),
  33.   k.cmd_to_tmux_prefix("j", "UpArrow"),
  34.   k.cmd_to_tmux_prefix("k", "DownArrow"),
复制代码
Tmux配置


  • 配置鼠标交互
  • 配置关闭Session 的快捷键
  • 配置关闭Pane和Window无需二次确认
  • 关闭Window后,序号自动重排序
  • 配置TPM和dracula主题
安装TPM和dracula主题
  1. # 安装TPM
  2. git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
  3. # 安装dracula主题
  4. git clone https://github.com/dracula/tmux.git ~/.tmux/plugins/tmux
  5. # 彻底刷新 tmux 环境
  6. tmux kill-server && tmux
复制代码
配置文件:~/.tmux.conf
  1. # 开启鼠标交互
  2. set -g mouse on
  3. # 绑定 ctrl b + K 关闭session
  4. bind K kill-session
  5. # windows序号自动重排
  6. set-option -g renumber-windows on
  7. # 关闭分屏 (Pane) 时不提示确认,直接关闭
  8. bind x kill-pane
  9. # 关闭窗口 (Window) 时不提示确认,直接关闭
  10. bind & kill-window
  11. # 1. 设置 TPM 插件列表
  12. set -g @plugin 'tmux-plugins/tpm'
  13. set -g @plugin 'tmux-plugins/tmux-sensible'
  14. # 2. 引入 dracula 主题插件
  15. set -g @plugin 'dracula/tmux'
  16. # Dracula 主题配置(可选:显示 CPU、内存、天气、时间)
  17. set -g @dracula-plugins "cpu-usage ram-usage time"
  18. set -g @dracula-show-powerline true    # 开启像箭头一样的分隔符
  19. set -g @dracula-show-left-icon session # 左边显示 session 图标
  20. # 3. 初始化 TPM (必须放在文件最后一行)
  21. run '~/.tmux/plugins/tpm/tpm'
复制代码
Zshell配置

配置alias简化tmux目录输入

  • tc:创建新session
  • tl:列出所有session
  • ta  :attach到最新的session或指定session
  • t0:每次终端启动时进入最新的session,如果没有session,则创建一个
配置文件 ~/.zshrc
  1. # tmux相关配置
  2. alias tc="tmux"
  3. alias tl="tmux ls"
  4. ta() {
  5.         if [ -z "$1" ]; then
  6.     tmux attach
  7.   else
  8.     tmux attach -t "$1" "${@:2}"
  9.   fi
  10. }
  11. tk() {
  12.   if [[ -z "$1" ]]; then
  13.     tmux kill-server
  14.   else
  15.     tmux kill-session -t "$1"
  16.   fi
  17. }
  18. t0() {
  19.   # 已在 tmux 内就不做任何事,避免嵌套
  20.   [[ -n "$TMUX" ]] && return 0
  21.   # 没有任何 session:tmux ls 会失败 -> 直接新建并进入
  22.   tmux ls >/dev/null 2>&1 || { tmux new-session; return; }
  23.   # 有 session:直接 attach(默认行为是 attach 到一个现有 session)
  24.   tmux attach
  25. }
  26. # ...
  27. # 放到最后,每次终端启动时启动tmux
  28. t0
复制代码
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

2026-1-21 12:27:04

举报

您需要登录后才可以回帖 登录 | 立即注册