You’re editing a file on a remote server and your connection drops. An hour of work — gone. Or you’re switching between multiple files and your terminal is a mess of tabs. Tmux solves both problems: it keeps your editor sessions alive even if you disconnect, and lets you organize multiple editors in one window.
Quick Reference: Tmux + Editor Commands
| Action | Command |
|---|---|
| Start tmux | tmux |
| Start named session | tmux new -s work |
| Detach (keep running) | Prefix d (default: Ctrl+b then d) |
| Reattach | tmux attach or tmux attach -t work |
| New window | Prefix c |
| Switch window | Prefix n (next), Prefix p (prev), Prefix 0-9 |
| Split vertical | Prefix % |
| Split horizontal | Prefix " |
| Switch pane | Prefix arrow |
| Close pane | exit or Ctrl+d |
Why Use Tmux with Editors?
Problem 1: Connection Drops Kill Your Work
Without tmux:
ssh server
vim important.conf # Working for an hour
# CONNECTION DROPS
# Work is lost, editor is gone
With tmux:
ssh server
tmux new -s editing
vim important.conf # Working for an hour
# CONNECTION DROPS
# No problem! Session keeps running
# Reconnect
ssh server
tmux attach -t editing # Back exactly where you were
Problem 2: Multiple Files, One Terminal
Without tmux:
- Open multiple SSH sessions
- Switch between terminal tabs
- Lose context constantly
With tmux:
- One SSH session
- Multiple tmux windows/panes
- Everything visible at once
Basic Workflow: Tmux + Editor
1. Start tmux
ssh user@server
tmux new -s myproject
2. Open Your Editor
vim src/main.py
3. Detach When Done (or Connection Drops)
Prefix d (Ctrl+b, then d)
Session keeps running on the server.
4. Reattach Later
ssh user@server
tmux ls # List sessions
tmux attach -t myproject # Reattach
Your editor is exactly as you left it.
Multiple Files: Windows and Panes
Method 1: Multiple Windows (Like Browser Tabs)
Create new window:
Prefix c (Create window)
Open another file:
vim config/settings.py
Switch between windows:
Prefix n # Next window
Prefix p # Previous window
Prefix 0 # Go to window 0
Prefix 1 # Go to window 1
Prefix w # Interactive window list
Rename window:
Prefix , # Type name like "main.py"
Method 2: Split Panes (Side-by-Side)
Split vertically (left/right):
Prefix %
Split horizontally (top/bottom):
Prefix "
Switch panes:
Prefix arrow # Use arrow keys
Close pane:
exit # Or Ctrl+d
Example workflow:
# Split into 3 panes
Prefix % # Split right
Prefix " # Split bottom pane
# Now you have:
# | vim main.py | vim utils.py |
# | | terminal |
# Switch between panes
Prefix Left # Go left
Prefix Right # Go right
Prefix Down # Go down
Editor-Specific Tmux Workflows
Vim + Tmux
Copy from vim, paste to terminal:
# In vim, yank (copy) text
v"ay # Select, yank to register a
# In terminal pane
Prefix ] # Paste tmux buffer
Better: Use tmux-yank plugin:
# In ~/.tmux.conf
set -g @plugin 'tmux-plugins/tmux-yank'
Then use Prefix y to copy to system clipboard.
Vim keybindings in tmux:
# In ~/.tmux.conf
setw -g mode-keys vi
# Now in copy mode (Prefix [):
# v - start selection
# y - yank
# Ctrl+c - cancel
Nano + Tmux
Nano works fine in tmux. Just remember:
Ctrl+Xto exit nanoPrefix dto detach tmux
Multiple nano windows:
# Window 1: nano file1.txt
# Window 2: nano file2.txt (Prefix c to create, then open)
# Window 3: terminal for commands
Emacs + Tmux
Emacs and tmux can conflict over key shortcuts (both use C-b, C-a).
Solution 1: Remap tmux prefix
# In ~/.tmux.conf
unbind C-b
set -g prefix C-a
bind C-a send-prefix
Solution 2: Use emacs server + tmux
# Start emacs daemon
emacs --daemon
# From tmux, open files
emacsclient filename
Common Stuck Scenarios
”I’m in vim inside tmux and can’t exit either”
First, exit vim:
Esc
:q!
Enter
Then you’re back at the tmux prompt.
If you want to exit tmux too:
exit
Or detach to keep it running:
Prefix d
“I detached but can’t find my session”
List all sessions:
tmux ls
Attach to specific one:
tmux attach -t sessionname
Attach to most recent:
tmux attach
“Tmux shows weird characters / broken display”
Problem: Terminal size changed or encoding issue.
Fix:
Prefix r # Reload tmux config
Or from outside tmux:
tmux attach -d # Force attach, detach others
“I’m in a split pane and my editor is too small”
Resize panes:
Prefix Ctrl+arrow # Resize in that direction
Or:
Prefix z # Zoom pane (fullscreen toggle)
“I accidentally closed my editor pane”
If you just exited:
- Pane is gone, but session is fine
- Open a new pane:
Prefix %orPrefix " - Reopen your editor
If you need that exact file back:
vim -r # Recovery mode, shows swap files
“My SSH connection froze with tmux running”
From another terminal:
ssh user@server
tmux attach -d # Force attach, kills frozen connection
Advanced: Persistent Tmux + Editor Sessions
Auto-restore tmux sessions
Install tmux-resurrect to save/restore sessions across reboots.
Install TPM (Tmux Plugin Manager):
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add to ~/.tmux.conf:
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
# Auto-restore on start
set -g @continuum-restore 'on'
# Initialize TPM (keep at bottom)
run '~/.tmux/plugins/tpm/tpm'
Usage:
Prefix Ctrl+s # Save session
Prefix Ctrl+r # Restore session
Tmuxinator: Pre-defined Layouts
Define complex editor layouts in YAML.
Install:
gem install tmuxinator
Create project:
tmuxinator new myapp
Edit ~/.config/tmuxinator/myapp.yml:
name: myapp
root: ~/projects/myapp
windows:
- editor:
layout: main-vertical
panes:
- vim
- # empty terminal
- server: bundle exec rails server
- logs: tail -f log/development.log
Launch:
tmuxinator myapp
Best Practices
1. Name Your Sessions
tmux new -s frontend # Frontend work
tmux new -s backend # API development
tmux new -s server # Server maintenance
2. Use a Config File
Create ~/.tmux.conf:
# Change prefix to Ctrl+a (easier to reach)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Vi mode for copy/paste
setw -g mode-keys vi
# Mouse support
set -g mouse on
# Start windows at 1 (not 0)
set -g base-index 1
3. Save Your Work
Even with tmux, save files regularly:
# In vim
:w
# In nano
Ctrl+O
# In emacs
C-x C-s
4. Use Git for Code
Don’t rely solely on tmux persistence:
git commit -am "WIP: before lunch"
Summary: Key Commands to Memorize
| Situation | Command |
|---|---|
| Start tmux | tmux new -s name |
| Detach (keep running) | Prefix d |
| Reattach | tmux attach -t name |
| New window | Prefix c |
| Split vertical | Prefix % |
| Split horizontal | Prefix " |
| Switch pane | Prefix arrow |
| List sessions | tmux ls |
Need help with editors? Check How to Exit vi and Vim, How to Exit Nano, or How to Exit Emacs.
Related Articles
Deepen your understanding with these curated continuations.
SSH Remote File Editing: Edit Files on Servers Like a Pro
Master remote file editing — SSH into servers, edit files with vi/nano/emacs, use local editors remotely, and handle common remote editing scenarios.
How to Handle Git's Default Editor: Commit, Abort, and Configure
Master Git's editor prompts — write commit messages, abort commits, change the default editor, and use one-liner commits without opening an editor.
Terminal Text Editors Compared: vi/vim vs Nano vs Emacs
Choose the right terminal text editor — compare vi/vim, Nano, and Emacs by learning curve, power, use cases, and when to use each one.