If there is any tool can be used Encounter to describe it, Tmux count as one.
Tmuxs is an excellent terminal multiplexing tool, use it to benefit is the most intuitive, login to remote host and run through a terminal after tmux, where you can open multiple consoles without having to "waste" extra terminals to connect the remote host;
Features
- To provide a strong, easy-to-use command-line interface.
- Laterally and longitudinally split window.
- Pane can be freely moved and resized, or directly to one of four preset layouts.
- UTF-8 encoding and supports 256 colors terminal.
- You can copy and paste a plurality of buffers.
- You can be selected window, the session and the client through an interactive menu.
- Support cross-window search.
- It supports automatic and manual locking window.
- Freely configurable shortcut key bindings.
Tmux important concepts
When using Tmux do not go back instructions, all instructions can .tmux.conf
bind its own handy shortcut keys configuration file, you can also be configured to open the mouse.
This is my profile: https: //github.com/zuorn/tmux.conf
In Tmux logic, it is necessary to distinguish Server> Session> Window> Pane and hierarchical order of this size is extremely important, is directly related to productivity:
- Server: the whole background tmux service. Sometimes change does not take effect, it is necessary to use tmux kill-server restart tmux.
- Session: Session tmux of all. Before I'd be wrong to use this session as a window, causing a lot of inconvenience in. General as long as it is sufficient to hold a session.
- Window: equivalent to a workspace that contains a lot of split-screen, it can be divided into a Window for each task. Such as downloading a Window, a programming window.
- Pane: a small split-screen in Window inside. The most common and best use
Knowing this logic, the entire Tmux use and configure it clear.
(Ps: below this nice convenience Status bar status bar shows the windows, rather than sessions)
installation
In Mac OS, by installing brew
brew install tmux
apt-get install version directly under ubuntu
sudo apt-get install tmux
Yum install version directly under centos7
yum install -y tmux
```sh
centos6版本需要编译安装
```sh
yum install libevent libevent-devel ncurses-devel
tar -zvxf tmux-2.3.tar.gz # (提前下载:wget https://github.com/tmux/tmux/releases/download/2.3/tmux-2.3.tar.gz)
cd tmux-2.3
./configure
make && make install
Tmux commonly used commands
#启动新session:
$ tmux [new -s 会话名 -n 窗口名]
#恢复session:
$ tmux at [-t 会话名]
#列出所有sessions:
$ tmux ls
#关闭session:
$ tmux kill-session -t 会话名
#关闭整个tmux服务器:
$ tmux kill-server
Tmux common internal command
The so-called internal command, that is, into the Tmux, and press the command key prefix, general prefix key is Ctrl + b. Although ctrl and b very far away but is not recommended to change the prefix key, other keys are not necessarily easy because good remember do not conflict. The default memory or more reliable.
System instructions:
Prefix | instruction | description |
---|---|---|
Ctrl+b | ? | Display shortcuts help documentation |
Ctrl+b | d | Disconnect the current session |
Ctrl+b | D | Select a disconnected session |
Ctrl+b | Ctrl+z | Suspend the current session |
Ctrl+b | r | Forced reload the current session |
Ctrl+b | s | The session list for selecting and switching |
Ctrl+b | : | Into the command line, and the like can now be entered directly ls command |
Ctrl+b | [ | Enter the copy mode, press q to exit |
Ctrl+b | ] | Copy and paste the copied text mode |
Ctrl+b | ~ | Lists the message cache |
Window (window) instructions:
Prefix | instruction | description |
---|---|---|
Ctrl+b | c | New Window |
Ctrl+b | & | Close the current window |
Ctrl+b | 0~9 | Switch to the specified window |
Ctrl+b | p | Switching to a window |
Ctrl+b | n | Switch to next window |
Ctrl+b | w | List of open windows, and for switching window |
Ctrl+b | , | Rename the current window |
Ctrl+b | . | Modifying the current window number (suitable for window reordering) |
Ctrl+b | f | Quickly locate the window (enter a keyword matching window name) |
Panel (Pane) instructions:
Prefix | instruction | description |
---|---|---|
Ctrl+b | " | The next panel is divided into two upper current, the lower side of the new panel |
Ctrl+b | % | The current is divided into two left and right panels, right panel new |
Ctrl+b | x | Close the front panel (must enter y or n confirmation before closing) |
Ctrl+b | with | Maximize the current panel, the repeat button to return to normal (v1.8 version added) |
Ctrl+b | ! | The current panel is moved to a new window opens (the presence of two or more panels in the original window active) |
Ctrl+b | ; | Switch to the last used panel |
Ctrl+b | q | The display panel number, enter the corresponding number before the disappearance of the digital switch to the corresponding panel |
Ctrl+b | { | Forward displacement of the current panel |
Ctrl+b | } | The current replacement back panel |
Ctrl+b | Ctrl+o | Clockwise rotation of all panels in the current window |
Ctrl+b | Arrow key | Move the cursor switch panel |
Ctrl+b | O | Select the next panel |
Ctrl+b | space bar | Cycle through the carrying panel layouts |
Ctrl+b | Alt + direction key | 5 to adjust the current cell units panel edge |
Ctrl+b | Ctrl + arrow keys | In a current cell is the unit adjustment panel edge (Mac the |
Ctrl+b | t | Clock display |
My Profile
use
$ git clone [email protected]:zuorn/tmux-config.git
$ cp tmux-config/.tmux.conf ~/.tmux.conf
Tmux restart restart tmux
or tmux window, first press Ctrl+b
instruction prefix, instruction press system: after the input command mode is entered source-file ~/.tmux.conf
, the transport take effect.
Configuration Item
Modify instruction prefix
You can be set according to their preferences, such as to enable, to cancel comment.
#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 ` # 设置一个不常用的`键作为指令前缀,按键更快些
Adding to load configuration files quick instruction r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded.."
Support Mouse
- Select Text
- Resizing panels
- Select and switch panel
# 老版本:
#setw -g mode-mouse on # 支持鼠标选取文本等
#setw -g mouse-resize-pane on # 支持鼠标拖动调整面板的大小(通过拖动面板间的分割线)
#setw -g mouse-select-pane on # 支持鼠标选中并切换面板
#setw -g mouse-select-window on # 支持鼠标选中并切换窗口(通过点击状态栏窗口名称)
# v2.1及以上的版本
set-option -g mouse on
panel
Change the new panel keys
-
- New vertical panel
-
- New panel level
unbind '"'
bind - splitw -v -c '#{pane_current_path}' # 垂直方向新增面板,默认进入当前目录
unbind %
bind = splitw -h -c '#{pane_current_path}' # 水平方向新增面板,默认进入当前目录
Resize panel
Ctrl + hjkl binding key to adjust the vertical edges of the left and right panels shortcut commands
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个单元格
Copy mode
Change the copy mode vi style
setw -g mode-keys vi # 开启vi风格后,支持vi的C-d、C-u、hjkl等快捷键
Copy mode closer to the vi
- v start selecting text
- y Copy selected text
- p paste text
bind -t vi-copy v begin-selection # 绑定v键为开始选择文本
bind -t vi-copy y copy-selection # 绑定y键为复制选中文本
bind p pasteb # 绑定p键为粘贴文本(p键默认用于进入上一个窗口,不建议覆盖)
optimization
Starting sequence number setting window panel
set -g base-index 1 # 设置窗口的起始下标为1
set -g pane-base-index 1 # 设置面板的起始下标为1
Custom status bar
set -g status-utf8 on # 状态栏支持utf8
set -g status-interval 1 # 状态栏刷新时间
set -g status-justify left # 状态栏列表左对齐
setw -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 "" # 状态栏窗口名称之间的间隔
Tmux FAQ
No matter how Tmux change the configuration file, not a difference
This is mainly due to the back buffer mechanism Tmux caused. I made a big mistake: even deleted Tmux, reloading Tmux, restart the computer, did not reach.
Tmux have called Tmux-server stuff. Just put it kill, restart tmux on OK:
tmux kill-server -a