码迷,mamicode.com
首页 > 其他好文 > 详细

tmux 简单实用

时间:2020-09-17 17:12:30      阅读:39      评论:0      收藏:0      [点我收藏+]

标签:tps   ase   source   setw   上下左右   too   block   sep   com   

tmux 是一个与 GNU screen 类似的程序,可作为后者的替代品使用。

安装

# Ubuntu 或 Debian
$ sudo apt-get install tmux

# CentOS 或 Fedora
$ sudo yum install tmux

# Mac
$ brew install tmux

配置文件 $HOME/.tmux.conf

适用于mac 和 centos,ubuntu,其他操作系统未测试

# ============================
# ===       Plugins        ===
# ============================

set -g @plugin ‘tmux-plugins/tpm‘
set -g @plugin ‘tmux-plugins/tmux-sensible‘
set -g @plugin ‘tmux-plugins/tmux-copycat‘
set -g @plugin ‘tmux-plugins/tmux-urlview‘
set -g @urlview-key ‘u‘
set -g @plugin ‘tmux-plugins/tmux-resurrect‘
# for darwin and ubuntu
set -g @plugin ‘xamut/tmux-network-bandwidth‘
# for centos
set -g @plugin ‘tmux-plugins/tmux-net-speed‘
set -g @plugin ‘ayzenquwe/tmux-ping‘


# ==========================
# ===  General settings  ===
# ==========================

set -g default-terminal "screen-256color"
# 命令回滚/历史数量限制
set -g history-limit 20480
set -sg escape-time 0
set -g display-time 1500
set -g remain-on-exit off

# 启用 UTF-8 编码
#setw -g utf8 on
#set -g status-utf8 on

# 从 1 开始编号,而不是从 0 开始
set -g base-index 1
set -g pane-base-index 1

# 取消默认的前缀键 C-b
# unbind C-b
# 设置新的前缀键
# set -g prefix C-a


# ================================================
# ===     Copy mode, scroll and clipboard      ===
# ================================================

# enable mouse
#set -g mouse-select-pane on
# 鼠标支持默认是关闭的,开启鼠标后,支持复制,翻屏,切换面板,切换窗口,resize。
set -g -q mouse on

# Vim 风格的快捷键绑定
setw -g mode-keys vi
set -g status-keys vi


# ==========================
# ===   Key bindings     ===
# ==========================

bind -r Tab lastp # 选择最后一个面板
bind -r l last-window

# 使用 Vim 风格的按键在窗格间移动
#bind h select-pane -L
#bind j select-pane -D
#bind k select-pane -U
#bind l select-pane -R

# 调整窗口大小, Alt or option + x
bind-key -r    M-Up resize-pane -U 10
bind-key -r  M-Down resize-pane -D 10
bind-key -r  M-Left resize-pane -L 10
bind-key -r M-Right resize-pane -R 10

# 较易于使用的窗格分割快捷键
bind | split-window -h
bind - split-window -v
unbind ‘"‘
unbind %

# Kill pane/window/session shortcuts
bind x kill-pane
bind X kill-window
bind C-x confirm-before -p "kill other windows? (y/n)" "kill-window -a"
bind Q confirm-before -p "kill-session #S? (y/n)" kill-session

# Detach from session
bind d detach
bind D if -F ‘#{session_many_attached}‘     ‘confirm-before -p "Detach other clients? (y/n)" "detach -a"‘     ‘display "Session has only 1 client attached"‘

# reload configuration ~/.tmux.conf
unbind r
bind r source-file ~/.tmux.conf; display-message "tmux config reloaded ok"

# Prompt to rename window right after it‘s created
set-hook -g after-new-window ‘command-prompt -I "#{window_name}" "rename-window ‘%%‘"‘

# Rename session and window
#bind C-r command-prompt -I "#{window_name}" "rename-window ‘%%‘"
#bind C-R command-prompt -I "#{session_name}" "rename-session ‘%%‘"

# Hide status bar on demand
bind s if -F ‘#{s/off//:status}‘ ‘set status off‘ ‘set status on‘


# =====================================
# ===    Appearence and status bar  ===
# =====================================
# 状态栏颜色
set -g status-justify left
set -g status-bg black
set -g status-fg blue
set -g status-left-length 40
set -g status-right-length 80

### 用户界面
# 通知方式
setw -g monitor-activity on
set -g visual-activity on

# 自动设置窗口标题
set -g set-titles on
set -g set-titles-string ‘#H:#S.#I.#P #W #T‘ # 窗口编号,程序名称,是否活动

# 调整状态栏
set -g status-interval 1    # 状态栏刷新时间
set -g status-justify left  # 状态栏列表左对齐
setw -g monitor-activity on # 非当前窗口有内容更新时在状态栏通知

set -g status-bg "#1c1c1c"    # 设置状态栏背景黑色
set -g status-fg blue       # 设置状态栏前景黄色
set -g status-style "bg=#1c1c1c, fg=#FCCC31" # 状态栏前景背景色

# for darwin and ubuntu
set -g status-left  "?? #[bg=#3a3a3a,fg=#bcbcbc]Session #S "
set -g status-right "?? #{network_bandwidth} #[bg=#272c35,fg=#ff9601]Ping:#{ping} #[bg=#3a3a3a,fg=#bcbcbc] %H:%M "

# for centos
#set -g status-left  "#[bg=#3a3a3a,fg=#bcbcbc]Session #S "
#set -g status-right "↑ #{upload_speed} ? ↓ #{download_speed} #[bg=#272c35,fg=#ff9601] ping #{ping} #[bg=#3a3a3a,fg=#bcbcbc] %H:%M "

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 -wg window-status-current-style "fg=#d7fcaf,bg=#60875f" # 状态栏当前窗口名称的样式
set -wg window-status-last-style "fg=#ffd75f"    # 状态栏最后一个窗口名称的样式
set -g message-style "bg=#202529, fg=#91A8BA"    # 指定消息通知的前景、后景色

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

使用步骤

# 1 编辑配置文件

# 2 安装插件管理工具
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

# 3 安装插件
prefix + C-I

# 4 安装依赖
# 4.1 tmux-urlview
brew install urlview

# 4.2 tmux-network-bandwidth
macOS: brew install gawk coreutils
Linux: apt-get install gawk net-tools coreutils

常用快捷键

  • Alt/option + 上下左右,更改pane大小

  • s 显示隐藏状态栏

  • prefix + / 搜索复制

  • prefix + C-s/C-r 保存恢复session

基本用法参考这里

tmux 简单实用

标签:tps   ase   source   setw   上下左右   too   block   sep   com   

原文地址:https://www.cnblogs.com/hiyang/p/13626312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!