Tmux

Updated: September 28, 2024

Tmux is an oldie but goodie for managing many windows & panes in the terminal.

Combined with neovim one can approach having a near vscode feel inside the terminal.
Combine tmux and neovim with nix shell environments to create devshells within
specific folders of a file structure.
In setup we will use a plugin to tie the movements between tmux and neovim so the
keymaps are the same as well as working between the two separate applications.


Table of Contents

Setup

Install

For macOS use brew

brew install tmux

For linux use various pkg manager

pacman -S tmux              # arch
apt install tmux            # debian
devbox add tmux@latest      # devbox (may also select specific version)
nix config                  # best way for nix is declarative

After installing tmux we want to add tpm (tmux plugin manager)
This will allow us to add plugins for extra features. Just run:

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

In the dotfile below is the starter plugin and some good
rock solid plugins. To add/remove a plugin adjust the list
in the dotfile. Then use the commands to maintain them with tpm

Download config file into your home folder

.tmux.conf

# TPM
prefix + I          # install plugins listed in .tmux.conf
prefix + U          # update
prefix alt + u      # uninstall/remove plugins not on list

Commands

tmux uses a prefix key default .
This is only active when inside a session.
You may use ? to list all shortcuts!

# OUTSIDE session
tmux info                           # show every pane, window, session
tmux new -s <name>                  # create a new tmux session (note: all new windows for session will start where this is exec)
tmux ls                             # see list of sessions
tmux detach                         # exit the session
tmux attach, at, a                  # enter most recent session
tmux attach -t <name>               # go into certain session
tmux kill-session -t <name>         # delete a certain session
tmux kill-session -a                # delete all session but current

# INSIDE session
<C-h,j,k,l>     # switch between panes
<C-b>           # prefix key follow by:
    0-9         # swtich between windows

    c           # create a window
    d           # detach from a session
    h,j,k,l     # resize a pane
    m           # maximize a tmux pane
    n           # switch to next window
    p           # switch to previous window
    q           # identify pane numbers
    r           # refresh config file
    s           # show sessions (nav with j,k)
    w           # see all windows
    x           # close a pane
    z           # toggle zoom (maximize a pane)

    I           # install a plugin after doing r

    <space>     # sync all panes (run commands on all at same time)
    ?           # list key bindings
    |           # split pane vertically (default = %)
    -           # split pane horizontally (default = ")
    :           # enter command mode
    ;           # toggle last active pane
    !           # convert a pane into a window
    &           # close window
    ,           # rename window
    $           # rename session
    [           # copy mode <C-c> to exit
    {,}         # move panes left or right
    (,)         # previous, next session

# tmux command mode (tmux && plugins)
> This is not in terminal nor in nvim command mode!
> They only work after <C-b> :
list-keys                   # same as <C-b> ?
new                         # start a new session
rename                      # rename session
rename-window               # rename window
swap-window -s 2 -t 1       # swap source 2 with dest 1
list-buffers                # show buffers
show-buffer                 # show contents of a buffer
save-buffer buf.txt         # copy buffer to file
delete-buffer -b 1          # delete buffer_1

# plugin commands
tmux-resurrect save         # <C-s>
tmux-resurrect restore      # <C-r>
tmux-resurrect list         # list
tmux-resurrect delete       # delete
tmux-resurrect delete-all   # delete all

tmux-continuum on           # turn on auto save
tmux-continuum off          # turn off auto save
tmux-continuum save         # save
tmux-continuum restore      # restore
tmux-continuum list         # list
tmux-continuum delete       # delete
tmux-continuum delete-all   # delete all
tmux-continuum remove <backup-id>   # remove
tmux-continuum save -b <backup-id>  # force save