Install Tmux on iSH and how to use tmux

The greatest value of Tmux to me: Avoiding the need to spend a lot of time restoring to the previous state due to network disconnection or Terminal crash. Additionally, the functionality of Tmux windows makes it more convenient for me to operate under Git Bash on Windows system.

Install Tmux on iSH

apk add tmux
Install Tmux on iSH
The picture above shows that it has been installed

Type tmux command to start Tmux,and type exit or Ctrl-d exit Tmux and released the session.

Type Ctrl-d ? to display a list of keyboard shortcuts,⚠️ Please hold down the Ctrl and D keys simultaneously, then release them and press the ? key.

Tmux Command List
Ctrl-b ? : Display a list of keyboard shortcuts

session > window > pane

Tmux
|__ Session A
|   |__ Window A1
|   |   |__ Pane A1a
|   |   |__ Pane A1b
|   |
|   |__ Window A2
|       |__ Pane A2a
|
|__ Session B
    |__ Window B1
    |   |__ Pane B1a
    |
    |__ Window B2
        |__ Pane B2a
        |__ Pane B2b

Session

  • tmux new -s <session-name> # Creating a session
  • tmux ls # View session list
  • tmux attach -t 0 # Attach to a session by session id
  • tmux attach -t <session-name> # Attach to a session by session name
  • tmux a # attach the detached-session, when i ssh to server
  • tmux kill-session -t 0 # Release session by session id
  • tmux kill-session -t <session-name> # Release session by session name
  • tmux kill-server # Release all sessions
  • ctrl-b d : Detach from a session,  leaving everything running in the background
  • ctrl-d: ⚠️ Exit Tmux and release the session
  • ctrl-b s: Choose a session from session list, i prefer type ctrl-b w to view all sessions and windows then choose a session.
  • ctrl-b $: Rename the current session

Windows

Tmux Create Windows
ctrl-b w: List all sessions and windows then choose a window.
  • ctrl-b c: Create a new window
  • ctrl-b p: Select the previous window
  • ctrl-b n: Select the next window
  • ctrl-b w: Choose window from a list, see screenshot above
  • ctrl-b ,: Rename the current window

Tmux windows are a very useful feature because Git Bash on Windows system lacks tab functionality and can only open multiple cascaded windows, which is inconvenient. However, with Tmux installed, Git Bash can switch between windows effectively.

Panes

  • ctrl-b %: Split window horizontally
  • ctrl-b “: Split window vertically
  • ctrl-d: Exit the pane
  • ctrl-b <arrow key>: switch to the pane in whichever direction you press
  • ctrl-b z: Zoom the active pane
  • ctrl-b-<arrow key> (Don’t release Ctrl-b then press arrow key): Resizing panes
  • ctrl-b {: Swap the active pane with the pane above
  • ctrl-b }: Swap the active pane with the pane below

Switching panes in Tmux feels a bit awkward because it involves using arrow keys, and moving fingers to the arrow keys takes time. I don’t have the habit of modifying the default shortcuts because I may not always use the same machine. Therefore, I don’t use Tmux pane functionality. I prefer using vim’s :term command to split panes, and then using Ctrl+w+w to switch between panes. After all, many machines have vim installed but may not have Tmux, while machines with Tmux installed usually have vim installed as well.

Others

The vim paste under Tmux will automatically indent, which is not what everyone wants to see. Enter :set paste before pasting, and enter :set nopaste after pasting.

Tmux paste indent

Featured Image