Skip to content

This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!


tmux

tmux (terminal multiplexer) is a program that enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen or terminal window.

Reference(s)

Table of contents


Install

# emerge -a tmux
# pacman -S tmux
# apt install tmux
# yum install tmux
# dnf install tmux

Config

If like me, you have some commands and personal scripts in your .zlogin or .login (e.g. like startx), you should modify it like so:

# vi ~/.zlogin

    > pgrep 'tmux|startx' || (
    >   some-command &
    >   some-personal-script &
    >   ...
    >   startx &
    > )


Use

  • Start tmux:

    $ tmux
    

  • Detach from tmux (without killing session):

    > Ctrl-b d
    

  • Restore tmux session:

    $ tmux attach
    

  • Detach an already attached session (great if you are moving devices with different screen resolutions)

    > tmux attach -d
    

  • Display session:

    > tmux ls
    

  • Rename session:

    > Ctrl-b $
    

  • Switch session:

    > Ctrl-b s
    

  • List sessions:

    $ tmux ls # or `$ tmux list-sessions`
    

  • Start a shared session:

    $ tmux -S /tmp/your_shared_session
    $ chmod 777 /tmp/your_shared_session
    

  • Help screen (Q to quit):

    > Ctrl-b ?
    

  • Scroll in window:

    > Ctrl-b PageUp/PageDown
    

  • Enter scroll mode:

    > Ctrl-b [
    
    (then up up/down arrow keys and/or pageup/pagedown)

  • Exit scroll mode:

    > q
    

  • Reload configuration file

    > Ctrl-b : source-file /path/to/file
    

Window management

  • Create window:

    > Ctrl-b c
    

  • Destroy window:

    > Ctrl-b x
    

  • Switch between windows:

    > Ctrl-b [0-9]
    or
    > Ctrl-b Arrows
    

  • Split windows horizontally:

    > Ctrl-b %
    

  • Split windows vertically:

    > Ctrl-b "
    

  • Swap windows

    > Ctrl-b :swap-window -s [0-9] -t [0-9]
    

tmuxp

tmuxp is a tmux session manager: see https://github.com/tmux-python/tmuxp.

TODO

Troubleshooting

  • If you get the following error message after running $ tmux ls: error connecting to /tmp/tmux-1000/default (No such file or directory), then this is probably because no tmux session is running (in this case $ pgrep tmux should return an error, i.e. a number superior to 0).

If this cheat sheet has been useful to you, then please consider leaving a star here.