[Literacy post] Do you know about the Linux Window Management Program Tmux?
Introduction
Tmux is a program for window management in linux. Unlike iTerm2, tmux provides a Session storage and restoration function at any time (the Session concept will be introduced later ), detach Session (keep the Session running in the background) and attach the Session again.
In common scenarios, multiple tags and files are opened in the company's Terimal. When I got home from work, I suddenly got inspiration and wanted to continue writing. I used ssh to remotely connect to the company's computer, then we found that the tabs and files should be re-opened. If Tmux is used, the current Session of detach will be closed. After going home to ssh remote connection, after attach Session, the scenario will be restored and the programming will continue happily...
Install
# Install the lost package management Homebrew under Mac OS X
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install Tmux
$ brew install tmux
Basic
# Start Tmux
$ tmux
# Disable Tmux
$ ctrl + d
# Or exit
$ exit
Tmux has three basic concepts: Session, Window, and panel ). After you enter tmux, what tmux actually does is to first create a Session and then create a Window in this Session. You can continue to create multiple windows ), each window contains only one panel. After you continue to split the screen, multiple panels (Pane) will appear. The terminals you see in the window actually belong to a panel of tmux.
Further, the Session can contain multiple windows, and each Window can contain multiple Pane.
Basic operations
How to execute all shortcut keys:
Presscontrol + b
Combine the two buttons and release them.control + b
(To tell Tmux that I want to use the Tmux shortcut key), and then trigger various actions by the shortcut key.
For example:C-b ?
The execution process is as follows:control + b
Combine the two buttons and release them.control + b
And then press '? 'Key, the list of all Shortcut Keys is displayed.
C-b ?
List all shortcut keys and press q or Esc to return
C-b d
Detach the current session. You can return to the Shell Interface temporarily and enter tmux attach to re-enter the previous session.
C-b s
Select and switch sessions.
Shortcut Key
Window operation
C-b c
Create a new window
C-b &
Close current window
C-b w
List all window selections
C-b p
Switch to the previous window
C-b n
Switch to the next window
C-B window number
Use the window number to switch the window (for example, if the window number is 1C-b 1
)
C-b ,
Rename the current window for easy identification of each window
Pane operation
C-b %
Horizontal Terminal
C-b "
Vertically split Terminal
C-B direction key
The Panel is selected freely.
C-b x
Close current pane
C-b q
Display Panel number
Session operation
# Create a new session
$ tmux new -s <name-of-my-session>
# Create a new session in the current Session and ensure that the previous session still exists
# C-B: Enter the following command:
new -s <name-of-my-new-session>
# Enter the session named test
$ tmux attach -t test
C-b s
List all sessions
C-b d
Detach the current session (which can be considered as running in the background)
Advanced
Beautify Tmux
Use the Tmux configuration of gpakosz for beautification.
Advantages
- Use
C-a
It is easier to use as a prefix and savesC-b
Trigger prefix
- Powerline status bar beautification (familiar with vim)
- Display laptop battery status
Installation and Use
$ cd
$ rm -rf .tmux
$ git clone https://github.com/gpakosz/.tmux.git
$ ln -s .tmux/.tmux.conf
$ cp .tmux/.tmux.conf.local .
Reference
- Official Tmux website
- A Tmux crash course: tips and tweaks
- Tmux getting started
- Tmux-essential tool for Linux practitioners
- Tmux conf
- Tmux, a tool for Linux Terminals