0 - Prologue
0.1 - Where am I right now ?
As of now, I’m using my soon to be old tmux configuration for quite some time. I feel like it can benefit from a re-visit a lot :)
The configuration I talk about looks like the following
~/.tmux.conf
# setting prefix to esc+return
unbind C-b
set -g prefix C-Space
bind Space send-prefix
# custom keybindings
bind m set -g mouse
bind s setw synchronize-panes
# Function to split windows with the same user
bind h split-window -h -c "#{pane_current_path}"
bind v split-window -v -c "#{pane_current_path}"
bind q kill-pane
bind -n C-s command-prompt -p "send pane to (target pane):" "join-pane -t :'%%'"
# Special mode for resizing panes
bind r run-shell "tmux display-message 'Entering pane resize mode'; \
tmux bind -n h resize-pane -L 5; \
tmux bind -n j resize-pane -D 5; \
tmux bind -n k resize-pane -U 5; \
tmux bind -n l resize-pane -R 5; \
tmux bind -n Enter run-shell 'tmux unbind -n h; \
tmux unbind -n j; \
tmux unbind -n k; \
tmux unbind -n l; \
tmux unbind -n Enter; \
tmux unbind -n Escape; \
tmux display-message \"Exited pane resize mode\"'; \
tmux bind -n Escape run-shell 'tmux unbind -n h; \
tmux unbind -n j; \
tmux unbind -n k; \
tmux unbind -n l; \
tmux unbind -n Enter; \
tmux unbind -n Escape; \
tmux display-message \"Exited pane resize mode\"';"
# Special mode for moving panes
bind k run-shell "tmux display-message 'Entering pane move mode'; \
tmux bind -n h select-pane -L; \
tmux bind -n j select-pane -D; \
tmux bind -n k select-pane -U; \
tmux bind -n l select-pane -R; \
tmux bind -n Enter run-shell 'tmux unbind -n h; \
tmux unbind -n j; \
tmux unbind -n k; \
tmux unbind -n l; \
tmux unbind -n Enter; \
tmux unbind -n Escape; \
tmux display-message \"Exited pane move mode\"'; \
tmux bind -n Escape run-shell 'tmux unbind -n h; \
tmux unbind -n j; \
tmux unbind -n k; \
tmux unbind -n l; \
tmux unbind -n Enter; \
tmux unbind -n Escape; \
tmux display-message \"Exited pane move mode\"';"
# Move panes around using Shift + arrow keys
bind -n C-S-Up swap-pane -U
bind -n C-S-Down swap-pane -D
bind -n C-S-Left select-pane -L \; swap-pane -t !
bind -n C-S-Right select-pane -R \; swap-pane -t !
# status line config
set -g status-bg black
set -g status-fg white
set -g status-left "#[fg=green]#H"
set -g status-right "#[fg=yellow]#(date)"
# setting some defaults
set -g mouse on
set -g mode-keys vi
set-option -g base-index 1
set-window-option -g pane-base-index 1
# Automatically renumber windows when one is closed
set-option -g renumber-windows on
set -g xterm-keys on
set -g allow-passthrough on0.2 - What am I aiming to accomplish ?
Well my goal of this article is simply while preserving the current key maps mostly, making it more readable. Also improve on the capabilities. And I have to admit that I need to play with some key bindings, such as moving around panes. Those really should be a one time key presses instead of being a two step process.
1 - Going through reference
1.1 - tmux - ArchWiki
1.1.1 - configuration
I see that tmux not only looks for ~/.tmux.conf file but it actually looks for ~/.config/tmux/tmux.conf for a more structured configuration out of the box.
Here are some interesting configuration snippets
# using this syntax we can split our configuration files into multiple parts
source-file ~/.config/tmux/binds.tmux.conf1.1.2 - theming
Apparently there are some pretty cool tips and tricks about theming tmux on Archwiki. The below command lists all color codes with their output.
for i in {0..255}; do printf "\x1b[38;5;${i}mcolor${i} - ██████████\n"; done1.1.3 - history
The following option solves a serious problem I’ve had since day 1 of using tmux. Yes. You can just set the history limit of tmux :)
set -g history-limit 300001.1.4 - tmuxinator
Tmuxinator is a utility that you can define any layout with predefined commands and orientation.
You can get pane orientations from the current sessions windows issuing the command tmux list-windows It’ll have a similar output to the following
0: default* (3 panes) [274x83] [layout 20a0,274x83,0,0{137x83,0,0,3,136x83,138,0[136x41,138,0,5,136x41,138,42,6]}] @2 (active)
# 20a0,274x83,0,0{137x83,0,0,3,136x83,138,0[136x41,138,0,5,136x41,138,42,6]}
1: remote- (2 panes) [274x83] [layout e3d3,274x83,0,0[274x41,0,0,4,274x41,0,42,7]] @3
# e3d3,274x83,0,0[274x41,0,0,4,274x41,0,42,7]You’ll use those layout strings in the tmuxinator configuration like following
name: default
root: ~/
windows:
- default:
layout: 20a0,274x83,0,0{137x83,0,0,3,136x83,138,0[136x41,138,0,5,136x41,138,42,6]}
panes:
- clear
- vim
- clear && emacs -nw
- remote:
layout: 24ab,274x83,0,0{137x83,0,0,3,136x83,138,0,4}
panes:
-
-1.1.5 - plugins
Well this one really should be it’s own investigation. So I’m just gonna skip it for now. With some useful links to re-visit later. tmux-plugins · GitHub