Introduction to Tmux
Tmux (Multiplexer Terminal) is a tool that allows multiple terminals to be managed within a single window. In Linux, where the command line remains essential, Tmux becomes indispensable for developers and administrators. Unlike opening several tabs in a traditional emulator, Tmux keeps the sessions active even after closing the SSH connection, allowing it to resume work exactly where it was left. Its model based on sessions, windows and panels provides flexibility that exceeds most available multiplexers. In addition, its free license and low resource consumption make it suitable for both servers and workstations.
Installation
Install Tmux is simple in most distributions thanks to official repositories.
- Ubuntu and Debian: sudo apt update & & sudo apt install tmux
- Fedora: sudo dnf install tmux
- Arch Linux: sudo pacman -S tmux
- Compare from the source code: clone the GitHub repository and follow the compilation instructions.
- After installing, check the version with tmux-V and start exploring its features immediately.
Basic concepts
Tmux organizes its environment on three levels: sessions, windows and panels. A session is the high-level container that can persist between connections and contains one or more windows. Each window acts as an independent tab and can be divided into one or more panels. The panels are rectangular regions within a window that allow to see and interact with different terminals simultaneously. This hierarchy facilitates the grouping of related tasks, such as having a code window, a record window and a debugging third, all within the same session.
Keyboard shortcuts
The default prefix is Ctrl + b.
- Ctrl + b c: create a new window
- Ctrl + b ": divide the panel horizontally
- Ctrl + b%: split the panel vertically
- Ctrl + b + arrows: move the focus between panels
- Ctrl + b z: zoom on a panel
- Ctrl + b?: show help
In addition, commands can be written in the command line of Tmux by typing: after the prefix, which allows to create sessions, rename windows or change designs without memorizing each shortcut.
Meetings management
Session management.
- tmux new -s name: create new session
- tmux ls: list sessions
- tmux attack -t name: attached to an existing session
- tmux switch -t name: change to another session without disassociating
- Ctrl + b $: rename session
- Ctrl + b'o tmux kill-session -t name: log in
These operations allow you to maintain an orderly environment and recover the state after an unexpected disconnection.
Windows and panels
Within a session, the windows are managed with specific shortcuts.
- Ctrl + b c: new window
- Ctrl + b p: previous window
- Ctrl + b n: next window
- Ctrl + b,: rename window
- Ctrl + b &: close window
- Ctrl + b ": horizontal panel division
- Ctrl + b%: vertical panel division
- Ctrl + b + arrows: navigate between panels
- Keep Ctrl + b and press arrow: resize panel
- Ctrl + b z: alternate zoom mode (focus one panel)
Customization with .tmux.conf
The file ~/ .tmux.conf allows to customize Tmux.
- Change prefix to Ctrl + to: set -g prefix C-a, unbind C-b, bind C-a send-prefix
- Activate mouse: set -g mouse on
- Customize status bar: set -g status-bg colour235, set -g status-fg colour136
- Increase history: set -g history -limit 10000
- Enable mode vi: setw -g model-keys vi
- Recharge configuration: Ctrl + b: source-file ~/ .tmux.conf
Plugins with TPM
TPM (Tmux Plugin Manager) simplifies the installation and updating of extensions.
- Install TPM: git clone https: / / github.com / tmux-plugins / tpm ~/. tmux / plugins / tpm
- Add at the end of .tmux.conf: set -g @ plugin 'tmux-plugins / tpm', set -g @ plugin 'tmux-plugins / tmux-sensitive', run '~/ .tmux / plugins / tpm / tpm '
- After recharge, add plugins like tmux-resurrect (save / restore sessions), tmux-yank (copy to clipboard), tmux-logging (record output)
- Update plugins: Ctrl + b U
Cases of practical use
Tmux is ideal for various work scenarios.
- Remote work: session within SSH survives network falls, allows to continue without losing progress
- System management: monitor logs, run scripts and monitor services in separate panels
- Couple programming: two developers share the same session using tmux attack and see the same panels, facilitating real-time review
- Long tasks: compilations or downloads, you can disconnect and return later without losing the job
Problem-solving
Some common problems and their solution.
- shortcuts do not respond: check the prefix and recharge .tmux. conf
- Mouse does not work: activate set -g mouse on and ensure the terminal supports mouse events
- Foreign features in state bar: locale problem, correct with export LANG = in _ USUTF-8
- Tmux does not start: review socket permissions in / tmp / tmux-* and remove corrupt files
Integration with IDes and tools
Many editors and IDEs integrate with Tmux to improve development flow.
- VS Code: extension 'TMux' allows to create and manage panels without leaving the editor
- Neovim: plugin 'vim-tmux@-@ Navigator' makes it easier to move between Vim windows and Tmux panels with the same shortcuts
- This integration allows to maintain the development flow without changing context, taking advantage of Tmux's power to run tests, servers or logs while encoding
Conclusion
Tmux transforms the way to work with the terminal in Linux, offering persistent sessions, flexible windows and panels and a wide customization capacity through files and plugins. Learning your shortcuts and adapting your configuration results in higher productivity and resistance to interruptions. For any user who seeks efficiency in the command line, Tmux is a valuable investment worth mastering. In addition, its active community continues to provide improvements and new plugins that expand its capacities every day.


