1---2title: 'tmux - where have you been all my life?'3date: '2016-05-19'4published_at: '2016-05-19T16:28:00.004+10:00'5tags: ['command line', 'linux', 'screen', 'tmux', 'unix']6author: 'Gavin Jackson'7excerpt: 'Yesterday I discovered tmux - what an awesome command line tool! So powerful, yet so easy to use (and configure!). If you haven''t heard of tmux before, but have used GNU screen then tmux is basically...'8updated_at: '2021-04-16T09:57:26.603+10:00'9legacy_url: 'http://www.gavinj.net/2016/05/tmux-where-have-you-been-all-my-life.html'10---1112[](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrtvMuO7tiBvzakBZf0o2xdnmAIPbrve21KIL9yfUSsn9kvlECbX7fcd6Cba-NZfQWBZ4Dy12woMQ8zD5LLRVxQbDSthMWOlndNgPsSYeUT9m5Keg4LPrxmYdbPjzeXqoRsNGOtPaCiC0/s1600/tmux.png)1314Yesterday I discovered **tmux** - what an awesome command line tool!1516So powerful, yet so easy to use (and configure!).1718If you haven't heard of tmux before, but have used GNU screen then tmux is basically an enhanced screen replacement.1920It allows you to set up a set of windows (with panes and tabs), detach from the session, and later reattach. You can also attach multiple users to a tmux session (which is great for pair programming - or if you are giving someone a tour of a server).2122Interested You should buy this book - it's short and great:2324https://pragprog.com/book/bhtmux/tmux2526**Basic commands:**2728** **2930**New Session**3132tmux new -s [-d]3334**Attach to Session**3536tmux attach -t3738**Kill Session**3940tmux kill-session -t4142**List Sessions**4344tmux ls4546All key commands start with a prefix (by default it is configured to be **ctrl+b**), most people change this to ctrl+a by the looks of things.4748**Windows**4950New Window (**c**)5152Select Window (**0-9**)5354Rename Window (**,**)5556Detach (**d**)5758**Panes**5960Vertical Split (**"**) *- a good replacement for this is (**|**)*6162Horizontal Split (**%**) *- a good replacement for this is (**-**)*6364Swap Panes (**{}**)6566Select Pane **UDLR**6768Close Pane (**x**)6970Cycle Pane (**o**)7172Turn Page Into a New Window (**!**)73742. Here is my current tmux config (place in ~/.tmux.conf):7576```77# Setting the prefix from C-b to C-a78set -g prefix C-a7980# Free the original Ctrl-b prefix keybinding81unbind C-b8283#setting the delay between prefix and command84set -s escape-time 18586# Ensure that we can send Ctrl-A to other apps87bind C-a send-prefix8889# Set the base index for windows to 1 instead of 090set -g base-index 19192# Set the base index for panes to 1 instead of 093setw -g pane-base-index 19495# Reload the file with Prefix r96bind r source-file ~/.tmux.conf \; display "Reloaded!"9798# splitting panes99bind | split-window -h100bind - split-window -v101102# moving between panes103bind h select-pane -L104bind j select-pane -D105bind k select-pane -U106bind l select-pane -R107108# Quick pane selection109bind -r C-h select-window -t :-110bind -r C-l select-window -t :+111112# Pane resizing113bind -r H resize-pane -L 5114bind -r J resize-pane -D 5115bind -r K resize-pane -U 5116bind -r L resize-pane -R 5117118# mouse support - set to on if you want to use the mouse (tmux > 2.1)119#set -g mouse on120#bind m set -g mouse on \; display "Mouse ON"121#bind M set -g mouse off \; display "Mouse OFF"122123# mouse support - set to on if you want to use the mouse (tmux < 2.1)124#set -g mode-mouse on125#set -g mouse-resize-pane on126#set -g mouse-select-pane on127#set -g mouse-select-window on128#bind m set -g mode-mouse on \; set -g mouse-resize-pane on \; set -g mouse-select-pane on \; set -g mouse-select-window on \; display "Mouse ON"129#bind M set -g mode-mouse off \; set -g mouse-resize-pane off \; set -g mouse-select-pane off \; set -g mouse-select-window off \; display "Mouse OFF"130131# Set the default terminal mode to 256color mode132set -g default-terminal "screen-256color"133134# enable activity alerts135setw -g monitor-activity on136set -g visual-activity on137138# set the status line's colors139set -g status-fg white140set -g status-bg black141142setw -g window-status-style fg=cyan143setw -ga window-status-style bg=default144setw -ga window-status-style dim145setw -g window-status-current-style fg=white146setw -ga window-status-current-style bg=black147setw -ga window-status-current-style bright148set -g pane-border-style fg=green149set -ga pane-border-style bg=black150set -g pane-active-border-style fg=white151set -ga pane-active-border-style bg=yellow152set -g message-style fg=white153set -ga message-style bg=black154set -ga message-style bright155set-window-option -g window-status-current-style bg=black156set-window-option -ga window-status-current-style fg=yellow157set-window-option -ga window-status-current-style dim158159# Status line left side160set -g status-left-length 40161set -g status-left "#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P"162163# Status line right side164# 15% | 28 Nov 18:15165set -g status-right "#(~/battery Discharging) | #[fg=cyan]%d %b %R"166167# Update the status bar every sixty seconds168set -g status-interval 60169170# Center the window list171set -g status-justify centre172173# enable vi keys.174setw -g mode-keys vi175176# shortcut for synchronize-panes toggle177bind C-s set-window-option synchronize-panes178179# Log output to a text file on demand180bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"181```182183184