Tmux
Introduction
Official website explanation: tmux is a terminal multiplexer: it allows multiple terminals to be created, accessed and controlled on a single screen. tmux can detach from the screen, continue running in the background, and reattach later.
This release runs on Open BSD, Free BSD, Net BSD, Linux, mac OS, and Solaris.
Official website address: tmux/tmux: tmux source code (github.com)
Basic usage
Install
# Ubuntu or Debian $ sudo apt-get install tmux # CentOS or Fedora $ sudo yum install tmux # Mac $ brew install tmux
Startup
tmux
The above command will start a Tmux window with a status bar at the bottom. The left side of the status bar is window information (number and name), and the right side is system information.
To exit a Tmux window, press Ctrl + d
or explicitly enter the exit
command.
Prefix key
The Tmux window has a large number of shortcut keys. All shortcuts are invoked by prefix keys. The default prefix key is Ctrl + b
, that is, press Ctrl + b
before the shortcut key will take effect.
For example, the shortcut key for the help command is Ctrl + b ?
. Its usage is, in the Tmux window, first press Ctrl + b
, then press ?
, and the help information will be displayed.
Then, press the ESC key or the q
key to exit the help.
Session management
New session
The number of the first Tmux window started is 0
, the number of the second window is 1
, and so on. The sessions corresponding to these windows are session 0 and session 1.
It is not very intuitive to use numbers to distinguish sessions. A better way is to name the sessions.
tmux new -s <session-name>
Detach session
In the Tmux window, press Ctrl + b d
or enter the tmux detach
command to detach the current session from the window.
$ tmux detach
After the above command is executed, the current Tmux window will be exited, but the session and the processes inside it will still run in the background.
The tmux ls
command can view all current Tmux sessions.
$ tmux ls # or $ tmux list-session
Access session
The tmux attach
command is used to reattach an existing session.
# use the session number $ tmux attach -t 0 # use the session name $ tmux attach -t <session-name>
Kill session
The tmux kill-session
command is used to kill a session.
# use the session number $ tmux kill-session -t 0 # use the session name $ tmux kill-session -t <session-name>
Switch session
The tmux switch
command is used to switch sessions.
# use the session number $ tmux switch -t 0 # use the session name $ tmux switch -t <session-name>
Rename session
The tmux rename-session
command is used to rename a session.
$ tmux rename-session -t 0 <new-name>
The above command renames session 0.
Session shortcuts
Below are some session-related shortcuts.
Ctrl + b d
: Detach the current session.Ctrl + b s
: List all sessions.Ctrl + b $
: Rename the current session.
The simplest process
- Create a new session
tmux new -s my_session
. - Run the desired program in a Tmux window.
- Press the shortcut key
Ctrl + b d
to detach the session. - Next time you use it, reattach to the session
tmux attach-session -t my_session
.
pane operations
Split panes
The tmux split-window
command is used to split panes.
# Divide the upper and lower panes $ tmux split-window # Divide left and right panes $ tmux split-window -h
Move the cursor
The tmux select-pane
command is used to move the cursor position.
# The cursor switches to the upper pane $ tmux select-pane -U # The cursor switches to the lower pane $ tmux select-pane -D # Cursor switches to the left pane $ tmux select-pane -L # Cursor switches to the right pane $ tmux select-pane -R
Swap pane positions
The tmux swap-pane
command is used to swap pane positions.
# Move the current pane up $ tmux swap-pane -U # Move the current pane down $ tmux swap-pane -D
pane shortcut
Below are shortcut keys for some pane operations.
Ctrl + b %
: Divide the left and right panes.Ctrl + b "
: Divide the upper and lower panes.Ctrl + b
: The cursor switches to other panes.is the arrow key pointing to the pane to be switched to, for example, to switch to the lower pane, press the arrow key
↓
.Ctrl + b ;
: The cursor switches to the previous pane.Ctrl + b o
: The cursor switches to the next pane.Ctrl + b {
: The current pane is swapped with the previous pane.Ctrl + b }
: Swap the current pane with the next pane.Ctrl + b Ctrl + o
: Move all panes forward one position, the first pane becomes the last pane.Ctrl + b Alt + o
: Move all panes back one position, the last pane becomes the first pane.Ctrl + b x
: Close the current pane.Ctrl + b !
: Split the current pane into an independent window.Ctrl + b z
: The current pane is displayed in full screen, and it will return to its original size when used again.Ctrl + b Ctrl +
: Resize the pane in the direction of the arrow.Ctrl + b q
: Display the pane number.
Window management
In addition to dividing a window into multiple panes, Tmux also allows creating multiple windows.
New window
The tmux new-window
command is used to create a new window.
$ tmux new-window # Create a new window with the specified name $ tmux new-window -n <window-name>
Switch windows
The tmux select-window
command is used to switch windows.
# Switch to the window with the specified number $ tmux select-window -t <window-number> # Switch to the window with the specified name $ tmux select-window -t <window-name>
Rename window
The tmux rename-window
command is used to name (or rename) the current window.
$ tmux rename-window <new-name>
Window shortcut keys
The following are shortcut keys for some window operations.
Ctrl + b c
: Create a new window, and the status bar will display the information of multiple windows.Ctrl + b p
: switch to the previous window (according to the order on the status bar).Ctrl + b n
: switch to the next window.Ctrl + b
: Switch to the window with the specified number, whereis the window number on the status bar.
Ctrl + b w
: Select a window from the list.Ctrl + b ,
: Rename the window.
Other commands
Below are some other commands.
# List all shortcut keys and their corresponding Tmux commands $ tmux list-keys # List all Tmux commands and their arguments $ tmux list-commands # List information about all current Tmux sessions $ tmux info # Reload the current Tmux configuration $ tmux source-file ~/.tmux.conf
Ranger
Introduction
Official explanation: ranger is a console file manager with VI key bindings. It provides a clean and beautiful curses interface and provides a directory hierarchy view. It comes with rifle, a file launcher that automatically figures out what file type to use for the program.
Official link: ranger/ranger: A VIM-inspired filemanager for the console (github.com)
Install
The ubuntu installation command is as follows
apt install ranger
Finally, enter ranger in the terminal to open the program
Use
Use h
, j
, k
, l
to move the cursor through different folders
Use q
to exit the program, use S
to enter the folder where the current cursor is (after entering the folder, execute the exit
command in the terminal to return to the ranger program)
Configuration
Using ranger --copy-config=all
will generate a series of configuration files in ~/.config/ranger
- rc.conf is often used to set options and bind shortcut keys. (most commonly used)
- scope.sh is often used to set the preview mode of files
- rifle.conf is often used to set which software to use to open files
- commands.py python file, enhance and improve various functions of ranger
ranger --copy-config=all
rc.conf
– option settings and shortcut keyscommands.py
– commands that can be executed via:
commands_full.py
– full set of commandsrifle.conf
– specifies the default opener for different types of filesscope.conf
– responsible for various file previews
Note: If you want to use the configuration in the ~/.config/ranger
directory to take effect, you need to set the RANGER_LOAD_DEFAULT_RC
variable to false
bash echo "export RANGER_LOAD_DEFAULT_RC=false">>~/.bashrc zsh echo "export RANGER_LOAD_DEFAULT_RC=false">>~/.zshrc
Optional configuration (recommended)
Modify the configuration file ~/.config/ranger/rc.conf
- Display border
set draw_borders both
- Display serial number
set line_numbers true
- The serial number starts from 1
set one_indexed true
Configuration icon
git clone https://github.com/alexanderjeurissen/ranger_devicons ~/.config/ranger/plugins/ranger_devicons echo "default_linemode devicons" >> $HOME/.config/ranger/rc.conf
Effect
Configure text editor
Set the default to nvim
# bash echo export EDITOR=/usr/bin/nvim >> ~/.bashrc # zsh echo export EDITOR=/usr/bin/nvim >> ~/.zshrc
Shortcut keys
File manager operations
File manager operation | Function |
---|---|
h |
Back to the previous layer |
l |
Enter the file |
j |
down |
k |
Up |
Enter |
Open file |
q |
Exit |
Get help
You can get help while using Ranger
character | function |
---|---|
m |
Open the ranger man page |
k |
Open the list of keybindings |
c |
Opens a list of available commands and descriptions |
s |
Opens a list of settings and their current values| |
Delete
key | description |
---|---|
dD Or F8 |
to delete an item (file or folder), or : + delete . |
DD |
Move the item to the recycle bin. |
New
key | description |
---|---|
F7 |
Create a new folder, equivalent to :mkdir? . |
INSERT |
Create a new file, equivalent to :touch? . |
Rename
key | description |
---|---|
cw |
Rename (including suffix) |
I |
Rename, the cursor is at the top |
A |
Rename, the cursor is at the end (including the suffix) |
a |
Rename, the cursor is at the end (excluding the suffix) |
Copy
key | description |
---|---|
yy Or F5 |
Copy |
ya |
add mode, add the file at the cursor to the copy queue (the folder is invalid). |
yr |
remove mode, remove the file at the cursor from the copy queue (file folder is invalid). |
yt |
toggle mode, switch whether the file at the cursor is in the copy queue (file folder is invalid). |
yk |
Add the file at the cursor and the previous file to the copy queue (the folder is invalid). |
yj |
Add the file at the cursor and the next file to the copy queue (the folder is invalid). |
ygg |
Add all files from the cursor to the top to the copy queue (folder invalid) |
yG |
Add all files at the cursor to the bottom to the copy queue (folder is invalid) |
Cut
key | description |
---|---|
dd Or F6 |
Cut |
da |
add mode, same as copy. |
dr |
remove mode, same as copy. |
dt |
toggle mode, same as copy. |
dk |
same copy |
dj |
Copy |
dgg |
Copy |
dG |
Copy |
ud or uy |
Cancel cutting |
Paste
key | description |
---|---|
pp |
Paste, default append mode |
pP |
append mode, if there is an entry with the same name in the directory, add _ , _0 , _1 … . If the entry is a file, it is added after the file extension. |
po |
overwrite mode, if there is an entry with the same name in the directory, it will overwrite the original entry. |
pO |
append mode + overwrite mode. |
pl |
Paste as a symbolic link, do not display the relative path of the target entry in the status bar. |
pL |
Paste as a symbolic link (relative path), display the relative path of the target entry in the status bar. |
phl |
Paste as hard link |
pht |
Paste as a subdirectory of a hard link (hardlinked subtree) |
Search
key | description |
---|---|
/ |
Open the search box, enter the character string to be searched, and press Enter to start searching. |
f |
Finding is equivalent to running a file that meets the condition or opening a folder that meets the condition. |
zf |
It is the same as the command line filter , only the items that meet the conditions are displayed, case sensitive. |
n N |
Find next search result Find previous search result |
c + corresponding letter |
traversal through the corresponding attributes, such as: ca : traverse cc through atime attribute in turn cc : traverse ci through ctime attribute in turn: pass mimetype attributes traverse cm in turn: traverse cs through mtime attributes in turn: traverse cs through size attributes code>ct: Traverse through the tag attribute in turn |
Related plugins
ubuntu sudo apt-get install caca-utils # img2txt image sudo apt-get install highlight # code highlight sudo apt-get install atool # archive preview sudo apt-get install w3m # html page preview sudo apt-get install mediainfo # multimedia file preview sudo apt-get install catdoc #doc preview sudo apt-get install docx2txt # docx preview sudo apt-get install xlsx2csv # xlsx preview
LazyGit
Introduction
Official explanation: Simple terminal UI for git commands, written in Go using the gocui library.
Official link: jesseduffield/lazygit: simple terminal UI for git commands (github.com)
Install
ubuntu
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*' ) curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" tar xf lazygit.tar.gz lazygit sudo install lazygit /usr/local/bin
Execute lazygit
to start
Aliases can be added
echo "alias lg='lazygit'" >> ~/.zshrc
Effect:
You can use the number keys or tab
or h
and l
to switch tabs
Then use ?
in the corresponding tab to view the help document to learn the corresponding operation
Reference link:
https://www.ruanyifeng.com/blog/2019/10/tmux.html
https://www.zssnp.top/2021/06/03/ranger/#post-comment