tmux Cheatsheet¶
Überblick¶
tmux (terminal Multiplexer) ist ein Tool, mit dem Sie mehrere Terminalsitzungen innerhalb eines einzigen Terminalfensters ausführen können. Es ermöglicht Ihnen, Sitzungen zu lösen und neu anzubringen, so dass es perfekt für Remote-Arbeit und Langlauf-Prozesse.
Installation¶
Paketmanager¶
# Ubuntu/Debian
sudo apt install tmux
# macOS
brew install tmux
# CentOS/RHEL
sudo yum install tmux
# Arch Linux
sudo pacman -S tmux
# From source
git clone https://github.com/tmux/tmux.git
cd tmux && ./configure && make && sudo make install
```_
## Grundkonzepte
### Terminologie
## Basisnutzung
### Anfang tmux
```bash
# Start new session
tmux
# Start named session
tmux new-session -s mysession
tmux new -s mysession
# Start session with specific window name
tmux new -s mysession -n mywindow
# Start detached session
tmux new -d -s mysession
```_
### Sitzungsmanagement
```bash
# List sessions
tmux list-sessions
tmux ls
# Attach to session
tmux attach-session -t mysession
tmux attach -t mysession
tmux a -t mysession
# Detach from session
# Inside tmux: Ctrl+b d
# Kill session
tmux kill-session -t mysession
# Kill all sessions
tmux kill-server
```_
## Schlüsselbindungen (Standard-Präfix: Ctrl+b)
### Sitzungsbefehle
Alternative (hold Prefix)¶
Prefix + Alt+↑ # Resize pane up (5 lines) Prefix + Alt+↓ # Resize pane down (5 lines) Prefix + Alt+← # Resize pane left (5 columns) Prefix + Alt+→ # Resize pane right (5 columns)
Prefix + [ # Enter copy mode h, j, k, l # Move cursor (vim-style) Arrow keys # Move cursor w # Next word b # Previous word 0 # Beginning of line $ # End of line g # Go to top G # Go to bottom Ctrl+f # Page down Ctrl+b # Page up / # Search forward ? # Search backward n # Next search result N # Previous search result Space # Start selection Enter # Copy selection and exit Escape # Exit copy mode v # Start selection (vi mode) y # Copy selection (vi mode) Prefix + ] # Paste buffer ```_Konfiguration¶
Konfigurationsdatei (~/.tmux.conf)¶
```bash
Basic settings¶
set -g default-terminal "screen-256color" set -g history-limit 10000 set -g base-index 1 setw -g pane-base-index 1
Change prefix key¶
unbind C-b set -g prefix C-a bind C-a send-prefix
Reload config¶
bind r source-file ~/.tmux.conf \; display "Config reloaded!"
Mouse support¶
set -g mouse on
Vi mode¶
setw -g mode-keys vi
Pane splitting¶
bind|split-window -h bind - split-window -v unbind '"' unbind %
Pane navigation (vim-style)¶
bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R
Window navigation¶
bind -n M-Left previous-window bind -n M-Right next-window
Pane resizing¶
bind -r H resize-pane -L 5 bind -r J resize-pane -D 5 bind -r K resize-pane -U 5 bind -r L resize-pane -R 5
Status bar¶
set -g status-bg black set -g status-fg white set -g status-left '#[fg=green]#S ' set -g status-right '#[fg=yellow]%Y-%m-%d %H:%M' set -g status-interval 60
Window status¶
setw -g window-status-current-style 'fg=black bg=white' setw -g window-status-style 'fg=white bg=black'
Pane borders¶
set -g pane-border-style 'fg=colour238' set -g pane-active-border-style 'fg=colour51' ```_
Erweiterte Konfiguration¶
```bash
Automatic window renaming¶
setw -g automatic-rename on set -g set-titles on
Activity monitoring¶
setw -g monitor-activity on set -g visual-activity on
Copy mode improvements¶
bind -T copy-mode-vi v send-keys -X begin-selection bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' bind -T copy-mode-vi r send-keys -X rectangle-toggle
Synchronize panes¶
bind S setw synchronize-panes
Quick pane cycling¶
bind -n M-o select-pane -t :.+
Session management¶
bind C-s choose-session bind C-n new-session ```_
Erweiterte Funktionen¶
Sitzungsskription¶
```bash
Create session with multiple windows¶
tmux new-session -d -s development tmux new-window -t development -n editor 'vim' tmux new-window -t development -n server 'cd ~/project && npm start' tmux split-window -t development:server -h 'cd ~/project && npm run watch' tmux attach-session -t development ```_
Tmux Scripts¶
```bash
!/bin/bash¶
dev-session.sh¶
SESSION="development"
Check if session exists¶
tmux has-session -t $SESSION 2>/dev/null
if [ $? != 0 ]; then # Create new session tmux new-session -d -s $SESSION
# Setup windows
tmux rename-window -t $SESSION:1 'editor'
tmux send-keys -t $SESSION:1 'cd ~/project && vim' C-m
tmux new-window -t $SESSION -n 'server'
tmux send-keys -t $SESSION:2 'cd ~/project && npm start' C-m
tmux new-window -t $SESSION -n 'git'
tmux send-keys -t $SESSION:3 'cd ~/project && git status' C-m
# Split server window
tmux split-window -t $SESSION:2 -h
tmux send-keys -t $SESSION:2.2 'cd ~/project && npm run watch' C-m
fi
Attach to session¶
tmux attach-session -t $SESSION ```_
Tmuxin¶
```bash
Install tmuxinator¶
gem install tmuxinator
Create project¶
tmuxinator new myproject
Example tmuxinator config (~/.tmuxinator/myproject.yml)¶
name: myproject root: ~/projects/myproject
windows: - editor: layout: main-vertical panes: - vim - guard - server: bundle exec rails s - logs: tail -f log/development.log ```_
Plugins¶
TPM (Tmux Plugin Manager)¶
```bash
Install TPM¶
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add to ~/.tmux.conf¶
set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum'
Initialize TPM (add to bottom of .tmux.conf)¶
run '~/.tmux/plugins/tpm/tpm'
Install plugins: Prefix + I¶
Update plugins: Prefix + U¶
Remove plugins: Prefix + alt + u¶
```_
Beliebte Plugins¶
```bash
tmux-resurrect - save/restore sessions¶
set -g @plugin 'tmux-plugins/tmux-resurrect'
Save: Prefix + Ctrl+s¶
Restore: Prefix + Ctrl+r¶
tmux-continuum - automatic save/restore¶
set -g @plugin 'tmux-plugins/tmux-continuum' set -g @continuum-restore 'on'
tmux-yank - copy to system clipboard¶
set -g @plugin 'tmux-plugins/tmux-yank'
tmux-pain-control - better pane management¶
set -g @plugin 'tmux-plugins/tmux-pain-control'
tmux-sidebar - file tree sidebar¶
set -g @plugin 'tmux-plugins/tmux-sidebar'
Toggle: Prefix + Tab¶
```_
Kommandozeilenschnittstelle¶
Sitzungsmanagement¶
```bash
Create session with command¶
tmux new-session -d -s mysession 'htop'
Send commands to session¶
tmux send-keys -t mysession 'ls -la' C-m
Capture pane content¶
tmux capture-pane -t mysession -p
List windows in session¶
tmux list-windows -t mysession
List panes in window¶
tmux list-panes -t mysession:1 ```_
Scripting Beispiele¶
```bash
Create development environment¶
create_dev_env() \\{ local session="dev-\((date +%s)" tmux new-session -d -s "\)session" tmux send-keys -t "\(session" 'cd ~/project' C-m tmux split-window -t "\)session" -h tmux send-keys -t "\(session" 'cd ~/project && npm start' C-m tmux select-pane -t "\)session":0 tmux attach-session -t "$session" \\}
Kill all sessions except current¶
kill_other_sessions() \\{ local current=\((tmux display-message -p '#S') tmux list-sessions -F '#\\\\{session_name\\\\}'|\ grep -v "^\)current$"|\ xargs -I \\{\\} tmux kill-session -t \\{\\} \\} ```_
Tipps und Tricks¶
Produktivität Tipps¶
```bash
Quick session switching¶
bind -n M-1 switch-client -t session1 bind -n M-2 switch-client -t session2
Broadcast to all panes¶
bind a setw synchronize-panes
Quick layouts¶
Prefix + Space # Cycle through layouts Prefix + Alt+1 # Even horizontal Prefix + Alt+2 # Even vertical Prefix + Alt+3 # Main horizontal Prefix + Alt+4 # Main vertical Prefix + Alt+5 # Tiled
Zoom pane¶
Prefix + z # Toggle pane zoom
Break pane to new window¶
Prefix + ! # Break pane out
Join pane from another window¶
bind j command-prompt -p "join pane from:" "join-pane -s '%%'" ```_
Nützliche Alias¶
```bash
Add to ~/.bashrc or ~/.zshrc¶
alias ta='tmux attach' alias tls='tmux list-sessions' alias tn='tmux new-session' alias tk='tmux kill-session'
Function to create or attach to session¶
tm() \\{ [[ -n "$TMUX" ]] && change="switch-client"||change="attach-session" if [ $1 ]; then tmux \(change -t "\)1" 2>/dev/null||(tmux new-session -d -s \(1 && tmux \(change -t "\)1"); return fi session=\)(tmux list-sessions -F "#\\{session_name\\}" 2>/dev/null|fzf --exit-0) && tmux \(change -t "\)session"||echo "No sessions found." \\} ```_
Fehlerbehebung¶
Gemeinsame Themen¶
```bash
Fix 256 color support¶
export TERM=screen-256color
Fix clipboard issues¶
Install xclip (Linux) or reattach-to-user-namespace (macOS)¶
Reset tmux completely¶
tmux kill-server
Check tmux version¶
tmux -V
Validate configuration¶
tmux source-file ~/.tmux.conf ```_
Leistung¶
```bash
Reduce escape time¶
set -sg escape-time 0
Increase history limit¶
set -g history-limit 50000
Refresh status bar less frequently¶
set -g status-interval 5 ```_
Integration¶
Mit Vim/Neovim¶
```bash
vim-tmux-navigator plugin¶
Seamless navigation between vim and tmux panes¶
bind -n C-h run "(tmux display-message -p '#\\{pane_current_command\\}'|grep -iq vim && tmux send-keys C-h)||tmux select-pane -L" bind -n C-j run "(tmux display-message -p '#\\{pane_current_command\\}'|grep -iq vim && tmux send-keys C-j)||tmux select-pane -D" bind -n C-k run "(tmux display-message -p '#\\{pane_current_command\\}'|grep -iq vim && tmux send-keys C-k)||tmux select-pane -U" bind -n C-l run "(tmux display-message -p '#\\{pane_current_command\\}'|grep -iq vim && tmux send-keys C-l)||tmux select-pane -R" ```_
Mit SSH¶
```bash
Auto-attach to tmux on SSH¶
Add to ~/.bashrc on remote server¶
if [[ -z "\(TMUX" ]] && [ "\)SSH_CONNECTION" != "" ]; then tmux attach-session -t ssh_tmux||tmux new-session -s ssh_tmux fi ```_
Ressourcen¶
- **offizielle Dokumentation*: [github.com/tmux/tmux](LINK_3_
- Manual*:
man tmux
_ - Wiki: [github.com/tmux/tmux/wiki](LINK_3_
- **Awesome tmux*: [github.com/rothgar/awesome-tmux](LINK_3_