约 3 分钟
Tmux的基本操作整理和插件管理(使用TPM)

本文假设读者对tmux已经有一定的了解。

Tmux的强大之处

tmux可以让工作在后台持续进行,可以随时detach和attach到一个session开展工作。tmux还能让一个界面显示多个pane,使“多线程”工作更加便利。

Tmux的基本操作

首先需要知道tmux的前缀键这一概念,这是在想要执行其快捷指令时需要先按的,默认的前缀键是“Ctrl+c”。

下面是常见的指令,区分大小写且都要跟在前缀键后面。

  • c:创建一个新的window
  • 0-9:切换到指定window
  • p: 切换到前一个window
  • n:切换到下一个window
  • &:关闭(kill)一个window
  • %:在当前pane下方新建一个pane并切换到该处
  • “:在当前pane右方新建一个pane并切换到该处
  • q:紧接pane的编号以切换到该pane
  • z:将一个pane放大为单独的window
  • x:关闭(kill)一个pane
  • w:打开windows预览界面

更多的命令可以参考Tmux Cheat Sheet & Quick Reference(貌似国内不能很顺畅地访问)。

安装TPM

这一部分可以参考官方GitHub导引。值得提醒的是可以将配置文件放在~/.config/tmux目录下以减少HOME目录的杂乱度。

用TPM安装插件

例如设置主题颜色为nova,只需在配置文件中相应部分添加

set -g @plugin 'o0th/tmux-nova'

然后在tmux中按下<prefix> + I (大写)便可完成插件的安装。

顺便提一下,在该配置文件中可以对tmux进行一些设置,例如设置鼠标支持和256颜色支持等,具体可以自行查询。

最后附上我的tmux.conf文件

set-option -sa terminal-overrides ",xterm*:Tc"
set -g mouse on

# Open panes in current directory
bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"


# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# set -g @plugin 'odedlaz/tmux-onedark-theme'
# set -g @plugin 'catppuccin/tmux'
# set -g @plugin 'dracula/tmux'
set -g @plugin 'o0th/tmux-nova'

set -g @nova-pane-active-border-style "#44475a"
set -g @nova-pane-border-style "#282a36"
set -g @nova-status-style-bg "#4c566a"
set -g @nova-status-style-fg "#d8dee9"
set -g @nova-status-style-active-bg "#89c0d0"
set -g @nova-status-style-active-fg "#2e3540"
set -g @nova-status-style-double-bg "#2d3540"

set -g @nova-segment-mode "#{?client_prefix,Ω,ω}"
set -g @nova-segment-mode-colors "#78a2c1 #2e3440"

set -g @nova-segment-whoami "#(whoami)@#h"
set -g @nova-segment-whoami-colors "#78a2c1 #2e3440"

set -g @nova-rows 0
set -g @nova-segments-0-left "mode"
set -g @nova-segments-0-right "whoami"

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin '[email protected]:user/plugin'
# set -g @plugin '[email protected]:user/plugin'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

本文整理自Youtube,原标题:Tmux has forever changed the way I write code.