Skip to content

Instantly share code, notes, and snippets.

@rbf
Last active October 9, 2021 19:31
Show Gist options
  • Select an option

  • Save rbf/3529029 to your computer and use it in GitHub Desktop.

Select an option

Save rbf/3529029 to your computer and use it in GitHub Desktop.
tmux config file
# To download and install this file to your home folder run the following command:
# cp -v ~/.tmux.conf ~/.tmux.conf.backup_$(date +"%Y%m%d%H%M%S"); curl https://gist.githubusercontent.com/rbf/3529029/raw/.tmux.conf -o ~/.tmux.conf
# To download and install this file for all users run the following command:
# cp -v /etc/tmux.conf /etc/tmux.conf.backup_$(date +"%Y%m%d%H%M%S"); curl https://gist.githubusercontent.com/rbf/3529029/raw/.tmux.conf -o /etc/tmux.conf
# The command 'reattach-to-user-namespace' allow to use tools like 'pbcopy' or 'subl .' within tmux.
# SOURCE: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/blob/master/Usage.md#cross-platform-conditional-usage
if-shell '[ -z "${C9_USER}" ]' "set-option -g default-command 'command -v reattach-to-user-namespace >/dev/null && exec reattach-to-user-namespace -l \"$SHELL\" || exec \"$SHELL\"'"
set -g default-terminal "screen-256color"
set -g history-limit 20000
# use VI
set-window-option -g mode-keys vi
# Use ctrl-a instead of ctrl-b
set -g prefix C-a
unbind C-b
bind a send-prefix
# reload config
unbind r
bind r source-file ~/.tmux.conf
unbind ^T
bind ^T split-window -p 25
# Re-bind c (already the default) to open new windows in the same path
bind c new-window -c "#{pane_current_path}" # SOURCE: http://unix.stackexchange.com/a/118381
# horizontal and vertical splits
unbind |
bind | split-window -h -c '#{pane_current_path}' # Split panes horizontally and stay on same path
unbind _
bind _ split-window -v -c '#{pane_current_path}' # Split panes vertically and stay on same path
# SOURCE: Corrections for staying on the same path found in: http://unix.stackexchange.com/a/146826
# tile all windows
unbind =
bind = select-layout tiled
# Go to last window
unbind C-w
bind C-w last-window
# cycle through panes
unbind ^A
bind ^A select-pane -t :.+
unbind Right
bind Right resize-pane -R 8
unbind Left
bind Left resize-pane -L 8
unbind Up
bind Up resize-pane -U 4
unbind Down
bind Down resize-pane -D 4
unbind h
bind h select-pane -L
unbind j
bind j select-pane -D
unbind k
bind k select-pane -U
unbind l
bind l select-pane -R
# Set status bar
set -g status-bg black
set -g status-fg white
set -g status-interval 15
set -g status-left-length 60
set -g status-right-length 60
# Use ctrl-a shift-b to change the background color of the status bar to white.
# Reload (aja source) this conf file with ctrl-a r to set it back to black.
# FROM: https://unix.stackexchange.com/a/115820
unbind B
bind B set -g status-style "bg=brightwhite"
# Use ctrl-a b to toggle the status bar
unbind b
bind b set -g status
set -g status on
# Use 'set -g status off' to disable the status bar.
# Use 'set -g status on' to enable the status bar.
# When no value is given, boolean options are toggled.
# Character pair Replaced with:
# # #(command) => First line of command's output
# # #H => Hostname of local host
# # #S => Session name
# # #T => Current window title
# # ## => A literal #
# # Where appropriate, these may be prefixed with a number to specify the maximum length, for example #24T.
# To display a color list:
# for i in {0..255} ; do [ -z "${i##*0}" ] && echo; printf "\x1b[38;5;${i}m%10s" colour${i}; done; printf "\x1b[0m\n\n";
# Display at the left side of the status bar:
# If we are in c9.io (i.e. ubuntu machine): IDE url and local ip address
if-shell '[ -n "${C9_USER}" ]' "set -g status-left \"#[fg=colour32]c9.io/$C9_USER/$C9_PROJECT #[fg=red](#(hostname -i)) \""
# If we are not in c9.io: username, hostname, local ip address and session name (session index is displayed if session is unnamed).
if-shell '[ -z "${C9_USER}" ]' "set -g status-left \"#[fg=red]#(whoami)@#H (#(ifconfig | grep 'inet ' | grep -v 127.0.0.1 | head -1 | sed -e 's/[^0-9. ]//g' -e 's/ */ /g' -e 's/ //' | cut -d ' ' -f 1)) #[fg=colour32]#S \""
set -g status-justify left
set -g status-right '#[fg=colour32]%a %d %b %R'
# SOURCE: https://github.com/tmux/tmux/issues/1689#issuecomment-486732891
set-window-option -g window-status-current-style bg=colour32,fg=black
# clock
set-window-option -g clock-mode-colour colour32
set-window-option -g clock-mode-style 24
# From http://jasonwryan.com/blog/2011/06/07/copy-and-paste-in-tmux/
unbind [
bind Escape copy-mode
unbind p
bind p paste-buffer
# SOURCE: https://github.com/tmux/tmux/issues/592#issuecomment-255763680
# SOURCE: https://sanctum.geek.nz/arabesque/vi-mode-in-tmux/
if-shell '[ -z "${C9_USER}" ]' "bind-key -Tcopy-mode-vi 'v' send -X begin-selection"
if-shell '[ -z "${C9_USER}" ]' "bind-key -Tcopy-mode-vi 'y' send -X copy-selection"
# Remap key to close windows to X since x is to close panes
unbind X
bind X confirm-before -p "kill-window #W? (y/n)" kill-window
# Tips from https://mutelight.org/practical-tmux
set -g base-index 1 # Start Window Numbering at 1
set -s escape-time 0 # Faster Command Sequences
# window movement / renumbering like in screen's :number
bind-key m command-prompt -p "move window to:" "move-window -t '%%'" # must be a non-used window index
bind-key M command-prompt -p "swap window with:" "swap-window -t '%%'" # must be a currently used window index
# Fix underlining on tmux v1.8
# From: http://sourceforge.net/mailarchive/forum.php?thread_name=F892202E-B27B-400E-A5BD-596A124E058F%40high5.nl&forum_name=tmux-users
set -ag terminal-overrides ",*:XT@"
# SOURCE: https://github.com/airblade/vim-gitgutter#vim-gitgutter
set -g focus-events on
@rbf
Copy link
Copy Markdown
Author

rbf commented Feb 10, 2015

Some reminders:

Leaving and entering tmux

tmux => creates a new tmux session
tmux ls => lists active tmux sessions
tmux a -t target-session => reattach to the target-session
tmux a => reattach to the most recently used unattached session

CTRL-A + D => within a tmux session, deattaches from it, leaving it running (type tmux a to reattach to it)

Windows

CTRL-A + C => creates a new window
CTRL-A + [0-9] => changes to window [0-9]
CTRL-A + W => changes to the last active window (flagged with a - after the window name in the status bar)
CTRL-A + , => allows to rename the active window

Panes

CTRL-A + _ => splits the active pane horizontally
CTRL-A + | => splits the active pane vertically
CTRL-A + CTRL-A => changes to the next pane in the same window (in a circular way)

CTRL-A + : + break-pane => extracts the active pane to a new window

CTRL-A + cursor keys => increases the size of the active pane in the direction of the cursor key

CTRL-A + Z => zoom to the active pane (i.e. go full-window). CTRL-A + Z to zoom out back to the original window layout

@st
Copy link
Copy Markdown

st commented Feb 10, 2015

c'est comme ma toyota.
fantastique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment