from Hacker News

Tmux – The Essentials (2019)

by devonnull on 3/5/25, 1:31 AM with 97 comments

  • by anyfoo on 3/5/25, 2:30 AM

    I like tmux a lot, but like its predecessor "screen" I mostly use it for explicitly running long-lived jobs (i.e. for its detach feature), and for very special situations where I have elaborate tmux window configurations with dedicated stuff running in each window/pane.

    Note that I have been using text-only terminals since the 1980s, but I've adapted my tty usage over time.

    The problem that tmux (or screen) brings are first and foremost:

    * Smooth/fast scrolling goes away. I can no longer give my trackpad a slight push to find myself tens or hundreds of lines in the scrollback history, and visually scan by slightly pushing my fingers back and forth. Instead I have to use the horrendous in-tmux scrollback using "Ctrl-b [".

    * My terminal app's tabs and windows are not tmux's tabs and windows. I cannot freely arrange them in space, snap them off with the mouse, easily push them to another desktop, and so on. I have to start a multiple tmux clients and do awkward keyboard interactions with them for any of the same.

    * tmux's terminal emulation and my terminal emulator's terminal emulation (heh) are not congruent. As a result, programs cannot make full use of my actual terminal's capabilities. For example selecting, copying, and pasting text sometimes behave weirdly, and there are other annoyances.

    What I'd really like to have instead is terminal session management at a higher level, i.e. involving my actual graphical terminal app itself. Attaching to a running session would mean restoring the terminal app's windows and tabs, and the entire scrollback history within (potentially with some lazy loading).

    tmux could likely be a major part of that, by providing the option of replacing its tty-facing frontend with a binary protocol that the graphical terminal app talks to, while keeping the backend (i.e. the part that provides the tty to anything running inside it) the same as it is today.

    As it is, the downsides of using tmux all the time are too high.

  • by mdaniel on 3/5/25, 4:05 AM

    I'll toss my "works on my machine" hat in the ring with two things that I have found invaluable in combination with iTerm2's tmux integration:

    - env KUBECONFIG=$HOME/.kube/setup-1 tmux new -s setup1

    - teamocil: https://github.com/remi/teamocil#readme (MIT)

    The first one I use for circumstances where I want to investigate a lot of different things in a dedicated cluster, without the hassle of having $(kubectl --kubeconfig ...) or the risk of k() { kubectl --kubeconfig ... "$@"; } and losing track of what context I'm in[1]. Because, with iTerm2's integration command-n or command-t opens a new window or tab but with retaining the credential scoping. If I need to change scopes, I can just detach from the tmux session, attach to a different one, confident that I don't have any variables to unset

    The second I use in "standard" setups where I want to view the same configuration every day (say: web, api, database pods). Having teamocil allows me to either have those same commands laid out in the same pattern as yesterday, or I've also had pretty good luck just generating the yaml files because their syntax is simple enough

    1: related to that, if you haven't seen it, iTerm2 offers the ability to set the RGB of a tab via OSC: https://iterm2.com/documentation-escape-codes.html#:~:text=t...

  • by Tsiklon on 3/5/25, 2:35 AM

    Personally I find tmux’s default split keys to be a bit obtuse, personally I like to use hyphen and pipe for horizontal and vertical splits.

    Likewise i enable vim keybindings, mouse mode, and if you use a Mac and iTerm selecting text will automatically drop it into your clipboard ready to paste.

    I tend to make use of the following command - which will output the last 100000 lines of the current pane to a text file local to you; it’s useful for documenting screwups, maintenance work, and of course making notes on what you’ve done for future reference

    > bind-key P command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S -100000 ; save-buffer %1 ; delete-buffer'

  • by pjs_ on 3/5/25, 6:24 AM

    Fun fact the main WSGI server for prod AWS console has been running out of a detached tmux process since 2018. We are just really careful not to press Ctrl-D
  • by YouWhy on 3/5/25, 4:20 AM

    My only non-truvial tip about tmux is that the only thing that one needs to do is to look for help: Ctrl+B then '?', and then figure the rest out.

    When I learnt tmux, I had to access multiple VMs which were de-facto ephemeral, which meant customization was not an option anyway. I kind of learnt to like the defaults as they are.

  • by remram on 3/5/25, 3:37 AM

    I tried to move to tmux, mostly because the Red hat servers at work don't have screen, but I found out I really really prefer screen. The whole server/session/window/pane thing is overly complicated and somehow still less capable than screen's session/pane/window.

    It's a tiny bit more scriptable, but it's not like a real API either.

  • by lproven on 3/5/25, 10:35 AM

    There are not so many console-mode windowing terminal multiplexors.

    I am aware of tmux, dvtm, zellij, and GNU screen. That's it: just 4.

    Has anyone written a comparison of them? I would be genuinely interested. I personally favour ease of use over features.

  • by lemonwaterlime on 3/5/25, 3:30 AM

    I'm a fan of "How to configure tmux from scratch" [1]

    [1]: https://ianthehenry.com/posts/how-to-configure-tmux/

  • by zvr on 3/5/25, 8:06 AM

    Can anyone provide some information on the differences between tmux and screen? Are there significant features missing from one or the other? The more "objective" (or unbiased) the better. As an analogy, I know of some features available in neovim not available on vim; they are not important for me, so I continue to use vim. On the other hand, the vim features not available in vi made me switch.

    I use screen, but whatever I have read till now on comparison seems to point more to personal preferences.

  • by lynx97 on 3/5/25, 5:55 AM

    There are three tmux customisations that I love and use all day:

    1. Set the prefix key to C-Space. Much easier to type then any letter, and (in my case) only collides with Emacs set-mark. Its easy to remember and just type C-Space C-Space in that case.

    2. Set IC (insert key) as prefix2. If you have a full-size keyboard, you can now scroll up by pressing insert (on the block of 6) and pageup. Easy to type.

    3. Using sessions for ssh hosts. Add ControlPersist and/or AddKeysToAgent to ~/.config/ssh and bind the following to some key. Pressing that key will prompt for a hostname, and create a new session named after that hostname. The default-command will make it such that Prefix c will open a new window which is already logged in on that host. Its not the same as running a remote tmux, as your windows/session will not persist on the remote host, but it avoids nested tmux. I use it all the time during a typical day...

    command-prompt -p "Secure Shell ([user@]host):" { new-session -A -s "%1" "ssh %1" ; set-option default-command "ssh %1" }

  • by eu on 3/5/25, 2:14 AM

    it's missing changing Ctrl+B to Ctrl+A:

        # ~/.tmux.conf
        set-option -g prefix C-a
  • by g-b-r on 3/5/25, 4:37 AM

    Since no one said it yet, in case you don't already know tmux and you find it complex, zellij is a lot easier to learn
  • by azaras on 3/5/25, 9:22 AM

    I use byobu, a Tmux wrapper, as my primary terminal.

    I changed the Keybindings for splitting and moving around terminals to be as in Emacs, and I am very happy.

  • by alyandon on 3/5/25, 4:19 PM

    I've slowly been converting from screen to tmux. However, muscle memory is really hard to overcome so I've come up with this:

    https://gist.github.com/alyandon/b19e2634fac6505bb5bd0e0c99d...

    Yes - I'm a terrible person.

  • by avinassh on 3/5/25, 6:38 AM

    Is there any introduction post on why one should use tmux OR what one is missing by not using them?