ToB企服应用市场:ToB评测及商务社交产业平台

标题: Tmux 配置 [打印本页]

作者: 杀鸡焉用牛刀    时间: 2022-8-9 14:40
标题: Tmux 配置
Tmux 配置

前面提到的窗口管理只是 tmux 功能的一小部分,另一个很有用的功能就是,连接到远程主机之后,一旦断开,那么当前账户登录的任务就被取消了,但是使用 tmux 可以在断开之后继续工作,下次登录可以查看。其他的功能还有:
安装的话也很简单,在 mac 下直接 brew install tmux(前提需要安装 homebrew),Debian 下则直接 sudo apt-get install tmux
​         (adsbygoogle = window.adsbygoogle || []).push({});
在终端中输入 tmux 就可以打开一个新的 tmux session,tmux 的所有操作必须先使用一个前缀键(默认是 ctrl + b)进入命令模式,或者说进入控制台,就像 vim 中的 esc。
基本操作

信息查询

窗口控制
先来看看在 tmux 之外如何进行控制
更常用的是在 tmux 中直接通过默认前缀 ctrl + b 之后输入对应命令来操作,具体如下(这里只列出输入默认前缀之后需要输入的操作):
基本操作

窗口操作

面板操作

因为 iTerm2 的支持,很多切换的操作可以直接用鼠标进行,非常方便。具体大家可以自己尝试一下。
配置

我们可以先进行一些简单的配置,修改 ~/.tmux.conf 即可,让整个使用更方便。
  1. #-- base --#
  2. set -g default-terminal "screen-256color"
  3. set -g display-time 3000
  4. set -g history-limit 10000
  5. set -g base-index 1
  6. set -g pane-base-index 1
  7. set -s escape-time 0
  8. set -g mouse on
  9. #-- bindkeys --#
  10. # split windows like vim. - Note: vim's definition of a horizontal/vertical split is reversed from tmux's
  11. unbind s
  12. bind s split-window -v
  13. bind S split-window -v -l 40
  14. bind v split-window -h
  15. bind V split-window -h -l 120
  16. # navigate panes with hjkl
  17. bind h select-pane -L
  18. bind j select-pane -D
  19. bind k select-pane -U
  20. bind l select-pane -R
  21. # key bindings for horizontal and vertical panes
  22. unbind %
  23. bind | split-window -h # 使用|竖屏,方便分屏
  24. unbind '"'
  25. bind - split-window -v # 使用-横屏,方便分屏
  26. # swap panes
  27. bind ^u swapp -U
  28. bind ^d swapp -D
  29. bind q killp
  30. bind ^e last
  31. unbind r
  32. bind r source-file ~/.tmux.conf \; display "Configuration Reloaded!"
  33. #-- statusbar --#
  34. set -g status-justify centre
  35. set -g status-left "#[fg=red]s#S:w#I.p#P#[default]"
  36. set -g status-right '[#(whoami)#(date +" %m-%d %H:%M ")]'
  37. set -g status-left-attr bright
  38. set -g status-left-length 120
  39. set -g status-right-length 120
  40. set -g status-utf8 on
  41. set -g status-interval 1
  42. set -g visual-activity on
  43. setw -g monitor-activity on
  44. setw -g automatic-rename off
  45. # default statusbar colors
  46. set -g status-bg colour235 #base02
  47. set -g status-fg colour136 #yellow
  48. set -g status-attr default
  49. # default window title colors
  50. setw -g window-status-fg colour244
  51. setw -g window-status-bg default
  52. #setw -g window-status-attr dim
  53. # active window title colors
  54. setw -g window-status-current-fg colour166 #orange
  55. setw -g window-status-current-bg default
  56. #setw -g window-status-current-attr bright
  57. # window title string (uses statusbar variables)
  58. set -g set-titles-string '#T'
  59. set -g status-justify "centre"
  60. set -g window-status-format '#I #W'
  61. set -g window-status-current-format ' #I #W '
  62. # pane border
  63. set -g pane-active-border-fg '#55ff55'
  64. set -g pane-border-fg '#555555'
  65. # message text
  66. set -g message-bg colour235 #base02
  67. set -g message-fg colour166 #orange
  68. # pane number display
  69. set -g display-panes-active-colour colour33 #blue
  70. set -g display-panes-colour colour166 #orange
  71. # clock
  72. setw -g clock-mode-colour colour64 #green
  73. # 修改进入命令模式按键
  74. # remap prefix to Control + a
  75. # set -g prefix C-a
  76. # unbind C-b
  77. # bind C-a send-prefix
复制代码
版本2

[code]# --------------------------------------------------- Tmux Config -----------------------------------------------------------# --------------------------------------------------- prefix -----------------------------------------------------------# 修改指令前缀set -g prefix C-f #unbind C-f # C-b 即 Ctrl+b 键,unbind 意味着解除绑定bind C-f send-prefix # 绑定 Ctrl+f 为新的指令前缀# 从tmux v1.6版起,支持设置第二个指令前缀# set-option -g prefix2 ` # 设置一个不常用的`键作为指令前缀,按键更快些# 添加载在配置文件指令为: rbind r source-file ~/.tmux.conf \; display-message "Config reloaded.."# --------------------------------------------------- 更改新增面板键 -----------------------------------------------------------unbind '"'bind - splitw -v -c '#{pane_current_path}' # 垂直方向新增面板,默认进入当前目录unbind %bind =  splitw -h -c '#{pane_current_path}' # 水平方向新增面板,默认进入当前目录# --------------------------------------------------- 开启鼠标支持 -----------------------------------------------------------# v2.1及以上的版本set-option -g mouse on# --------------------------------------------------- vim 风格 -----------------------------------------------------------# 绑定hjkl键为面板切换的上下左右键bind -r k select-pane -U # 绑定k为↑bind -r j select-pane -D # 绑定j为↓bind -r h select-pane -L # 绑定h为←bind -r l select-pane -R # 绑定l为→# 面板调整大小# 绑定Ctrl+hjkl键为面板上下左右调整边缘的快捷指令bind -r ^k resizep -U 10 # 绑定Ctrl+k为往↑调整面板边缘10个单元格bind -r ^j resizep -D 10 # 绑定Ctrl+j为往↓调整面板边缘10个单元格bind -r ^h resizep -L 10 # 绑定Ctrl+h为往←调整面板边缘10个单元格bind -r ^l resizep -R 10 # 绑定Ctrl+l为往→调整面板边缘10个单元格# 复制模式更改为 vi 风格# 进入复制模式 快捷键:prefix + [setw -g mode-keys vi # 开启vi风格后,支持vi的C-d、C-u、hjkl等快捷键# --------------------------------------------------- 复制粘贴 -----------------------------------------------------------# 复制模式向 vi 靠拢#旧版本:#bind -t vi-copy v begin-selection  # 绑定v键为开始选择文本#bind -t vi-copy y copy-selection # 绑定y键为复制选中文本# 新版本:bind -T copy-mode-vi v send -X begin-selection # 开始复制bind -T copy-mode-vi y send -X copy-selection # 复制剪切板bind p pasteb # 绑定p键为粘贴文本(p键默认用于进入上一个窗口,不建议覆盖)# --------------------------------------------------- 其他 -----------------------------------------------------------#设置窗口面板起始序号set -g base-index 1 # 设置窗口的起始下标为1set -g pane-base-index 1 # 设置面板的起始下标为1set -s focus-events onset-window-option -g automatic-rename onset-window-option -g monitor-activity on# --------------------------------------------------- 状态栏 -----------------------------------------------------------set -wg window-status-format " #I #W " # 状态栏窗口名称格式set -wg window-status-current-format " #I:#W#F " # 状态栏当前窗口名称格式(#I:序号,#w:窗口名称,#F:间隔符)set -wg window-status-separator "" # 状态栏窗口名称之间的间隔set -g message-style "bg=#202529, fg=#91A8BA" # 指定消息通知的前景、后景色# 自定义状态栏set -g status-interval 1 # 状态栏刷新时间set -g status-justify left # 状态栏列表左对齐setw -g monitor-activity on # 非当前窗口有内容更新时在状态栏通知# --------------------------------------------------- linux -----------------------------------------------------------# set -g status-left "Zorn #W" # 状态栏左侧内容# set -g status-fg yellow # 设置状态栏前景黄色# set -g status-style "bg=black, fg=yellow" # 状态栏前景背景色# set -g status-right 'zorn@machine #{continuum_status}' # 状态栏右侧内容# set -g status-left-length 300 # 状态栏左边长度300# set -g status-right-length 500 # 状态栏左边长度500# set -wg window-status-current-style "bg=black" # 状态栏当前窗口名称的样式# set -wg window-status-current-style "bg=red" # 状态栏当前窗口名称的样式# set -wg window-status-last-style "fg=red" # 状态栏最后一个窗口名称的样式set -g status-left "
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4