[Linux] tmux 终端复用命令行工具
tmux 终端复用命令行工具tmux 是一款终端复用命令行工具,通常用于 Terminal 的窗口管理.可以在终端软件重启后通过命令行恢复上次的 session. 安装运行macOS 上使用 Homebrew 安装即可: brew install tmux 在 shell 主进程下运行以下命令可以操作 tmux 会话: tmux new -s foo # 新建名称为 foo 的会话 tmux ls # 列出所有 tmux 会话 tmux a # 恢复至上一次的会话 tmux a -t foo # 恢复名称为 foo 的会话,会话默认名称为数字 tmux kill-session -t foo # 删除名称为 foo 的会话 tmux kill-server # 删除所有的会话 快捷键一般情况下 tmux 中所有的快捷键都需要和前缀快捷键 ?b 来组合使用. 窗格(pane)操作
窗口操作
会话操作在 tmux 会话中,使用前缀快捷键 ?b 配合以下快捷键可操作会话:
常见配置与问题1、鼠标滚屏在中.tmux.conf 配置文件增加以下内容: 开启鼠标模式
允许鼠标选择窗格
如果喜欢给窗口自定义命名,那么需要关闭窗口的自动命名
如果对 vim 比较熟悉,可以将 copy mode 的快捷键换成 vi 模式
配置文件修改完成后,可以 tmux kill-server 重启所有 tmux 进程,或者在 tmux 会话中使用 ?b : 进入控制台模式,输入 source-file ~/.tmux.conf 命令重新加载配置。 2、复制
bind Escape copy-mode # 绑定esc键为进入复制模式 bind -T copy-mode-vi v send-keys -X begin-selection # 绑定v键为开始选择文本 bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel # 绑定y键为复制选中文本 我的.tmux.conf# 修改 ctrl+b 前缀为 ctrl+a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# set-option -g prefix2 `
# 绑定重载 settings 的热键
bind r source-file ~/.tmux.conf ; display-message "Config reloaded.."
# 设置为vi编辑模式
setw -g mode-keys vi # 设置为vi编辑模式
bind Escape copy-mode # 绑定esc键为进入复制模式
bind -T copy-mode-vi v send-keys -X begin-selection # 绑定v键为开始选择文本
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel # 绑定y键为复制选中文本
set-option -g default-command 'exec reattach-to-user-namespace -l zsh'
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'
# bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "pbcopy"
# bind-key C-c run-shell 'tmux save-buffer - | reattach-to-user-namespace pbcopy'
# bind-key C-v run-shell 'reattach-to-user-namespace pbpaste | tmux load-buffer - ; paste-buffer -d'
# 设置window的起始下标为1
set -g base-index 1
# 设置pane的起始下标为1
set -g pane-base-index 1
#-- base --#
set -g default-terminal "screen-256color"
set -g display-time 3000
set -g history-limit 65535
# 鼠标支持
set-option -g mouse on
# 关闭默认窗口标题
set -g set-titles off
#-- bindkeys --#
unbind '"'
bind - splitw -v -c '#{pane_current_path}'
unbind %
bind | splitw -h -c '#{pane_current_path}'
bind c new-window -c "#{pane_current_path}"
# 定义上下左右键为hjkl键
bind -r k select-pane -U
bind -r j select-pane -D
bind -r h select-pane -L
bind -r l select-pane -R
# 定义面板边缘调整的^k ^j ^h ^l快捷键
bind -r ^k resizep -U 1 # upward (prefix Ctrl+k)
bind -r ^j resizep -D 1 # downward (prefix Ctrl+j)
bind -r ^h resizep -L 1 # to the left (prefix Ctrl+h)
bind -r ^l resizep -R 1 # to the right (prefix Ctrl+l)
# 定义交换面板的键
# bind ^u swap-pane -U
# bind ^d swap-pane -D
# bind e lastp
# bind ^e last
# bind q killp
#bind '~' splitw htop
#bind ! splitw ncmpcpp
# bind m command-prompt "splitw 'exec man %%'"
# bind @ command-prompt "splitw 'exec perldoc -t -f %%'"
# bind * command-prompt "splitw 'exec perldoc -t -v %%'"
# bind % command-prompt "splitw 'exec perldoc -t %%'"
# bind / command-prompt "splitw 'exec ri -T %% | less'"
# 输出日志到桌面
# bind P pipe-pane -o "cat >>~/Desktop/#W.log" ; display "Toggled logging to ~/Desktop/#W.log"
#-- statusbar --#
set -g status-right-attr bright
set -g status-bg black
set -g status-fg yellow
# 设置状态栏高亮
setw -g window-status-current-attr bright
# 设置状态栏红底白字
setw -g window-status-current-bg red
setw -g window-status-current-fg white
# 设置状态栏列表左对齐
set -g status-justify left
# 非当前window有内容更新时在状态栏通知
setw -g monitor-activity on
set -g status-interval 1
#set -g visual-activity on
setw -g automatic-rename off
setw -g allow-rename off
# 最大化(默认为z,增加模拟的b指令)
# unbind b
# bind b run ". ~/.tmux/zoom"
# set -g status-keys vi
# plugin-manager
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# plugins
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
# load-plugins-without-manager
#run-shell ~/.tmux/tmux-resurrect/resurrect.tmux
#run-shell ~/.tmux/tmux-continuum/continuum.tmux
# plugins-settings
set -g @resurrect-strategy-vim 'session' # for vim
set -g @resurrect-strategy-nvim 'session' # for neovim
set -g @continuum-save-interval '180' # '0'
set -g @continuum-restore 'on'
set -g @continuum-boot-options 'fullscreen'
set -g status-right 'Continuum status: #{continuum_status}'
set -wg window-status-format " #I:#W "
setw -g window-status-current-format " #I:#W "
set -wg window-status-separator ""
set -g message-style "bg=#202529,fg=#91A8BA"
set -g @resurrect-capture-pane-contents 'on' # 恢复面板内容
run '~/.tmux/plugins/tpm/tpm'
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
