Today, I would like to introduce how to use tMUX, a terminal reuse artifact. I can hardly do without it every day, whether it is local development or login server.

Why use TMUX?

A lot of developers have experienced this kind of embarrassment when logging in to the server regularly:

  • If you want to open multiple directories at once, you have to open many terminal tabs and switch back and forth
  • After opening a vim window, you have to reopen a terminal window to SSH to the server if you want to switch to another directory
  • Run a script, the server is disconnected after the current process is ruthlessly killed by the server, have to use nohup and other ways to let the script run in the background
  • Every time you SSH to the server, you need to switch to the working directory again and open multiple processes. The previous working records will be lost
  • The mouse is a great invention, but unfortunately, moving and positioning between the mouse and keyboard on a terminal wastes time and can affect your thinking
  • .

Tmux, introduced today, solves these problems and frees up our hands from relying on the mouse at the terminal.

What is TMUX?

Tmux is a terminal reuse tool for running multiple terminal sessions in a terminal window. For example, we can achieve very cool effects:



Installation is also relatively simple, MAC users

# the brew ruby installation - e "$(curl - fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # use the brew tmux installation brew install tmuxCopy the code

Ubuntu users can sudo apt-get install tmux to install it.

Tmux concepts and usage

The default shortcut for TMUx is prefixed with CTRL + B, which you can change, but I’ll stick with the default for simplicity. (Tip: I changed the Capslock key to CTRL key, because CTRL is used very frequently, and CTRL key is not very convenient to use, especially laptop keyboard, pinkie hurts)

There are several important concepts in TMUX:

  • Session: To establish a TMUX workspace session, the session can reside for a long time, reconnecting to the server will not be lost, we simply attach tMUx to the previous workspace to restore the session
  • Windows: Holds multiple panes
  • Panes: You can divide a window into panes


In this video I will introduce these concepts and demonstrate how I use TMUx on a daily basis from scratch, just using the basics and having fun using TMUx without having to memorize so many shortcuts.

Teach you how to use terminal reuse artifact TMUX

Using third-party tools such as TMUXP/Terminator, we can even automate TMUX session management, such as configuring a TMUXP file for a project and then loading it directly to generate a TMUX session. If you are interested, see the demonstration in this article.

Pegasus Wang: Play TMUXP [Video]zhuanlan.zhihu.com

In addition, shared accounts can be paired by attaching to the same session using native TMUx or using a tool like Wemux, such as opening two Panes in a window, with vim on the left and Emcas on the right. Or attach two computers to the same session, and code written on one computer will appear in sync on the other, creating the illusion that the computer will write its own code.


If you can’t be bothered to configure it yourself, you can also use someone else’s tMUX, like this one:

gpakosz/.tmuxgithub.com


reference

Tmux Crash Course: Tips and Tweaks

tmux-cheatsheet.markdown

Tmux User manual

About the book | tmux – Productive – Mouse – Free – Development_zh