tmux

Originally written: December 1st, 2021

In an attempt to live inside the terminal, I have finally started learning how to use tmux.

I am primarily using it in conjunction with Vim (the other option of living inside the terminal would be living inside emacs... maybe some day?), and I use the vim-tmux-navigator, which makes moving between tmux and Vim a breeze. It simplifies the binding left/right/down/up to <C-h>, <C-l>, <C-j>, <C-k>.

Thoughtbot gives an amazing tutorial of how to install vim-tmux-navigator, but to defend against link rot, here are the reproduced steps:

  1. Install vim-tmux-navigator, i.e. via Vundle.
  2. Add the following to ~/.tmux.conf:
                      
                        # smart pane switching with awareness of vim splits
                        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"
                        bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"
                      
                    

Otherwise, here is a cheatsheet of some commands I use, all prefixed by <C-b> (Control + b):

  • d: Detach session
  • $: Change session Name
  • a: Attach to last session
  • a -t [NAME]: Attach to session [NAME]
  • c: New window
  • ,: Rename window
  • n: Next window
  • p: Previous window
  • w: List windows
  • %: Vertical split
  • ": Horizontal split
  • z: Maximize pane