[Software installation] tmux installation and related matters

tmux installation and related matters

tmux is a terminal multiplexing tool that can run multiple terminal sessions simultaneously in a single terminal window. Installing tmux can improve work efficiency and make command line operations more convenient.

1. Install tmux:

In Linux systems, you can use the package manager to install tmux. For example, in Ubuntu systems, you can use the following command to install:

sudo apt update
sudo apt install tmux

Under macOS systems, you can use Homebrew to install tmux:

brew update
brew install tmux

2. Start tmux:

Enter tmux in the terminal to start. By default, a tmux session will be opened in a new window, where you can execute commands. If you want to exit tmux, you can use Ctrl + b, then press d.

#Start a new session:
$ tmux [new -s session name -n window name]

#Restore session:
$ tmux at [-t session name]

#List all sessions:
$ tmux ls

#Close session:
$ tmux kill-session -t session name

#Close the entire tmux server:
$ tmux kill-server

3. Important concepts of Tmux (https://www.cnblogs.com/zuoruining/p/11074367.html#2423136631)

Never memorize instructions when using Tmux. All instructions can be bound to your own shortcut keys in the .tmux.conf configuration file, and you can also configure the mouse to be turned on.

This is my configuration file: https://github.com/zuorn/tmux.conf

In Tmux logic, it is extremely important to clearly distinguish the size and hierarchical order of Server > Session > Window > Pane, which is directly related to work efficiency:

  • Server: It is the background service of the entire tmux. Sometimes the configuration changes do not take effect, so you need to use tmux kill-server to restart tmux.
  • Session: are all sessions of tmux. I mistakenly used this session as a window before, which caused a lot of inconvenience. Generally just saving one session is enough.
  • Window: It is equivalent to a workspace, including many split screens. A Window can be divided for each task. For example, download a Window and program a window.
  • Pane: It is a small split screen in Window. The most commonly used and best used

4. Commonly used shortcut keys for tmux:

Ctrl + b is the default tmux command prefix. You need to enter this prefix first, and then enter other shortcut keys to execute the corresponding command. The following are commonly used tmux shortcut keys:

  • Ctrl + b d: Detach the current tmux session (equivalent to suspending to the background)
  • Ctrl + b c: Create a new tmux window (Note: The concept of this window is equivalent to a window in a session. A session can contain multiple windows, but a window can only belong to a fixed session)
  • Ctrl + b n: switch to the next tmux window (can only switch in the window of the current session)
  • Ctrl + b p: switch to the previous tmux window (same as above)
  • Ctrl + b %: Split the current window horizontally (further split the current window, so the conceptual inclusion relationship is: server>session>window>split window)
  • Ctrl + b “: Split the current window vertically (same as above)
  • Ctrl + b x: Close the current pane
  • Ctrl + b [: Enter copy mode
  • Ctrl + b ]: Paste the copied text

5. More comprehensive shortcut keys for tmux

System command:

Prefix Command Description
Ctrl + b ? Show shortcut key help document
Ctrl + b d Disconnect the current session
Ctrl + b D Select the session to disconnect
Ctrl + b Ctrl + z Suspend the current session
Ctrl + b r Force reloading of the current session
Ctrl + b s Display session list for selection and switching
Ctrl + b : Enter command line mode, this You can directly enter commands such as ls
Ctrl + b [ Enter copy mode, press q to exit
Ctrl + b ] Paste text copied in copy mode
Ctrl + b ~ List prompt information cache

Window command:

Prefix Command Description
Ctrl + b c New window
Ctrl + b & amp; Close the current window
Ctrl + b 0~9 Switch to the specified window
Ctrl + b p Switch to the previous window
Ctrl + b n Switch to the next window
Ctrl + b w Open the window list for switching windows
Ctrl + b , Rename the current window
Ctrl + b . Modify the current window number (applicable to window reordering)
Ctrl + b f Quickly locate the window (enter keywords to match the window name)

Panel command:

td>

Prefix Command Description
Ctrl + b The current panel is divided into two, and a new panel is created on the lower side
Ctrl + b % The current panel is divided into two parts, and a new panel is created on the right side
Ctrl + b x Close the current panel (you need to enter y or n to confirm before closing)
Ctrl + b z Maximize the current panel and return to normal after pressing the key again (new in v1.8 version)
Ctrl + b ! Move the current panel to a new window to open (it is valid if there are two or more panels in the original window)
Ctrl + b ; Switch to the last used panel
Ctrl + b q Display the panel number, in Enter the corresponding number before the number disappears to switch to the corresponding panel
Ctrl + b { Displace the current panel forward
Ctrl + b } Displace the current panel backward
Ctrl + b Ctrl + o Rotate all panels in the current window clockwise
Ctrl + b Direction keys Move the cursor to switch panels
Ctrl + b o Select the next panel
Ctrl + b Spacebar In the built-in panel layout Cycle switching
Ctrl + b Alt + arrow keys Adjust the edge of the current panel in units of 5 cells
Ctrl + b Ctrl + arrow keys Adjust the edge of the current panel in units of 1 cell (under Mac
Ctrl + b t Show clock

5. tmux configuration:

The configuration file of tmux is ~/.tmux.conf. You can change the default configuration of tmux by modifying this file. Here are some commonly used configuration options:

  • set-option -g prefix C-a: Change the tmux command prefix to Ctrl + a
  • setw -g mouse on: enable mouse support
  • set-option -g default-shell /bin/bash: Set the default shell to bash
  • set-option -g history-limit 5000: Set the history record size to 5000 lines

Beginners are advised to configure it after they are proficient in it. There are many public configurations on the Internet. You can refer to the selection.

Error

hint:
/home/user/anaconda3/envs/virtualenvironment/lib/libtinfo.so.6: no version information available (required by -bash)
I got this error because I was in a virtual environment, so installing ncurses fixed it.
Install:

conda install -c conda-forge ncurses

Rename session (rename-session)

Most users forget to name the session they are using when they start using Tmux. However, as the number of sessions increases along with the workflow, it becomes a pain to remember which session you are using and the related services running within it. Therefore, it is best to always start a session using a name to avoid any confusion. However, if you forget to name a session when you create it, you can still give it a name or change the existing name.

Method 1: Rename the session through the shell prompt

$ tmux rename-session -t old-session-name new-session-name

Way 2: Rename the session using Tmux command prompt

$ rename-session -t my_session_1 my_session_2

Way 3: Rename session using key combination

Ctrl + b + $

reference

@misc{BibEntry2023Oct,
title = {{Tmux configuration xn–ih7c to create the most suitable terminal reuse tool for yourself – zuorn – Blog Park}},
year = {2023},
month = oct,
urldate = {2023-10-23},
language = {chinese},
note = {[Online; accessed 23. Oct. 2023]},
url = {https://www.cnblogs.com/zuoruining/p/11074367.html}
}