Saltar al contenido principal

📋 Cheatsheet Tmux

🔑 Conceptos clave

  • Prefix: Combinación de teclas para activar comandos (por defecto Ctrl+b)
  • Sesión: Contenedor principal, persiste al cerrar terminal
  • Ventana: Equivalente a pestañas en navegadores
  • Panel: División de ventana (split horizontal/vertical)

🎮 Sesiones

Gestión básica

ComandoAcción
tmuxNueva sesión
tmux new -s nombreNueva sesión con nombre
tmux lsListar sesiones
tmux attach -t nombreConectar a sesión
tmux kill-session -t nombreEliminar sesión

Dentro de tmux

ComandoAcción
prefix + dDesconectar (detach)
prefix + sListar y cambiar sesiones
prefix + $Renombrar sesión actual
prefix + (Sesión anterior
prefix + )Sesión siguiente

🪟 Ventanas

ComandoAcción
prefix + cNueva ventana
prefix + ,Renombrar ventana
prefix + &Cerrar ventana
prefix + nSiguiente ventana
prefix + pVentana anterior
prefix + lÚltima ventana activa
prefix + 0-9Ir a ventana número
prefix + wLista de ventanas
prefix + fBuscar ventana

📱 Paneles

Crear paneles

ComandoAcción
prefix + %Split vertical
prefix + "Split horizontal
prefix + xCerrar panel
ComandoAcción
prefix + →Panel derecha
prefix + ←Panel izquierda
prefix + ↑Panel arriba
prefix + ↓Panel abajo
prefix + oSiguiente panel
prefix + ;Último panel activo
prefix + qMostrar números de panel
prefix + q + númeroIr a panel número

Redimensionar paneles

ComandoAcción
prefix + Ctrl + →Agrandar derecha
prefix + Ctrl + ←Agrandar izquierda
prefix + Ctrl + ↑Agrandar arriba
prefix + Ctrl + ↓Agrandar abajo
prefix + Alt + →Redimensionar 5 chars derecha
prefix + Alt + ←Redimensionar 5 chars izquierda
prefix + Alt + ↑Redimensionar 5 chars arriba
prefix + Alt + ↓Redimensionar 5 chars abajo

Organizar paneles

ComandoAcción
prefix + {Mover panel izquierda
prefix + }Mover panel derecha
prefix + spaceCambiar layout
prefix + !Convertir panel en ventana
prefix + zZoom/unzoom panel

📋 Copy Mode (modo copia)

Entrar y navegar

ComandoAcción
prefix + [Entrar copy mode
qSalir copy mode
h,j,k,lNavegar (como vim)
wSiguiente palabra
bPalabra anterior
gInicio de buffer
GFinal de buffer
/Buscar hacia adelante
?Buscar hacia atrás
nSiguiente resultado
NResultado anterior

Seleccionar y copiar

ComandoAcción
spaceComenzar selección
enterCopiar selección
vSelección rectangular
yCopiar (sin salir)

Pegar

ComandoAcción
prefix + ]Pegar
prefix + =Lista de buffers

⚙️ Configuración común

Archivo ~/.tmux.conf

# Cambiar prefix a Ctrl+a
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Splits más intuitivos
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# Navegación estilo vim
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Redimensionar paneles
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

# Habilitar mouse
set -g mouse on

# Comenzar ventanas y paneles en 1
set -g base-index 1
setw -g pane-base-index 1

# Renumerar ventanas automáticamente
set -g renumber-windows on

# No delay para escape key
set -sg escape-time 0

# Aumentar history
set -g history-limit 10000

# Recargar configuración
bind r source-file ~/.tmux.conf \; display "Config reloaded!"

# Copy mode estilo vim
setw -g mode-keys vi
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 -selection clipboard"

# Colores
set -g default-terminal "screen-256color"

🎨 Personalización visual

Status bar

# Configuración de 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]%d %b %R"
set -g status-justify centre

# Colores de ventanas
setw -g window-status-current-style fg=black,bg=white

Themes populares

  • tmux-powerline: Status bar avanzado
  • oh-my-tmux: Configuración completa
  • tmux-themepack: Temas pre-hechos

🔗 Integración con vim

# En ~/.tmux.conf
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'

🚀 Workflows comunes

Desarrollo web

# Sesión para proyecto web
tmux new-session -d -s web
tmux rename-window -t web:0 'editor'
tmux send-keys -t web:0 'nvim .' Enter
tmux new-window -t web -n 'server'
tmux send-keys -t web:server 'npm run dev' Enter
tmux new-window -t web -n 'git'
tmux send-keys -t web:git 'git status' Enter
tmux attach -t web

DevOps

# Sesión para monitoreo
tmux new-session -d -s monitor
tmux split-window -h
tmux split-window -v
tmux send-keys -t monitor:0.0 'htop' Enter
tmux send-keys -t monitor:0.1 'watch kubectl get pods' Enter
tmux send-keys -t monitor:0.2 'tail -f /var/log/nginx/access.log' Enter
tmux attach -t monitor

🎯 Comandos avanzados

Scripteo

ComandoAcción
tmux send-keys 'comando' EnterEnviar comando a sesión
tmux capture-pane -pCapturar contenido de panel
tmux list-sessions -F '#{session_name}'Listar solo nombres

Sesiones múltiples

# Trabajar con múltiples sesiones
tmux new-session -d -s trabajo
tmux new-session -d -s personal
tmux new-session -d -s experimentos

# Cambiar entre sesiones rápidamente
tmux switch-client -t trabajo

🔧 Comandos de línea útiles

# Crear sesión completa desde script
tmux new-session -d -s proyecto \; \
send-keys 'cd /path/to/project' Enter \; \
split-window -h \; \
send-keys 'git status' Enter \; \
select-pane -L \; \
send-keys 'nvim .' Enter

# Backup de sesión
tmux capture-pane -p > session_backup.txt

# Listar todas las sesiones con detalles
tmux list-sessions -F "#{session_name}: #{session_windows} windows (created #{session_created_string}) [#{session_width}x#{session_height}]"

🐛 Troubleshooting

Problemas comunes

  • Colors no funcionan: Revisar $TERM variable
  • Copy/paste no funciona: Instalar xclip o pbcopy
  • Prefix no responde: Verificar conflictos con otros shortcuts
  • Mouse no funciona: Añadir set -g mouse on a config

Reset completo

# Matar todas las sesiones
tmux kill-server

# Recargar config
tmux source-file ~/.tmux.conf

💡 Pro tip: Crea aliases para tus sesiones más comunes. Por ejemplo: alias dev='tmux new-session -d -s development || tmux attach -t development'