Tmux – The Essentials (2019)
78 comments
·March 5, 2025anyfoo
axiolite
> * Smooth/fast scrolling goes away.
That was the first thing I looked-up how to fix (years ago). Put the following in your tmux.conf:
set -g terminal-overrides '*:smcup@:rmcup@'
set -g status off
macartain
Not sure what this is tweaking (I'll check) but this does not seem to affect the described behaviour.. PgUp/Down does nothing - with and without shift - and mousewheel still just scrolls thru shell comand history and I need to use Ctrl-B ] to get into session output history..
olegdotcom
I have the same exact gripes with tmux/screen, and I have a similar workflow requirements as you do. I'm currently using Shpool (https://github.com/shell-pool/shpool), which checks all the checkboxes you mention.
tambourine_man
shpool is great, but it’s still Linux-only AFAIK. There was a Mac port coming along last I checked, but I don’t know the current status.
saurik
I am pretty sure dtach is in Homebrew, but maybe you specifically like the exact set of tradeoffs from shpool.
mcspiff
It’s not perfect, but I’ve found wezterms multiplexer quite good for this: https://wezterm.org/multiplexing.html
callc
Try “set-option -g mouse on” in your ~/.tmux.conf. I’ve never used the copy/scroll mode, always use scroll wheel on mouse.
Yeah, copying can be weird. I full screen a panel to copy multiple lines of text using the terminal emulator’s copy, not tmux’s. Works well enough.
anyfoo
That is a far, far cry from using kinetic scrolling. In fact, using a mouse wheel is a very far experience away from that. I basically cannot use "normal" mouses with scroll wheel anymore for that reason, I couldn't get anything done like that.
I think there are/used to be some mice with a ultra-low-fricton "freerunning" scroll wheel. I guess that could be a similar experience, but of course tmux would stand in the way of that as well.
And I'm very old school and had been using text-only terminal starting in the 1980s...
Panzer04
Logitech MX3 is the modern version, not sure what else there is. It's got a magnetic mechanism that allows the scroll wheel to freewheel if you want.
dev-ns8
I have been wrestling with having to enter scroll mode for so long now. It's so infuriating. It works without configurations on iTerm, but does not work on a single other terminal emulator I've tried.
I just tried your config setting in Ghostty and still, when I use my mouse it scrolls through zsh history, not the screen
pfranz
iTerm2 has had Tmux Integration for a few years now. That's not something I want, so I'm not sure if it ticks all your boxes.
https://iterm2.com/documentation-tmux-integration.html
Other terminal emulators offer similar features to Tmux. For example, Kitty claims to support Tmux's features outside of remote persistence.
kitd
Terminator? You can split/configure your terminals anyhow, and save your setup for future reference.
PhilipRoman
Regarding scrolling, I just have a keybind which dumps the scrollback buffer into vim in a new window. Works great for copying or searching things.
philsnow
> 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).
Do you mean something like Xpra, x2go, NX, VNC, or Parsec?
mdaniel
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...
alexeldeib
you seen kubie? `kubie ctx` is great for avoiding the first issue
alyandon
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.
lproven
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.
tiu
Would also like to mention (tab-rs)[0] which has a much more unconventional take on multiplexing.
It is sad that it has not been maintained in a while (written in rust) as I much prefer the low cognitive load approach it presents (just fuzzy find) as well as the workspace feature.
Would be interested in knowing if there is something similar and maintained.
P.S. Does anyone here know how to make GNU Screen start up by default on a terminal launch?
dsr_
That will depend on your terminal and whatever is running it. For xterm, '-e screen' will do.
aaplok
There is also cy [0] which I came across the other day and am yet to try.
mdaniel
I dunno why their repo would choose to offload people to a separate site just to read https://cfoust.github.io/cy/why-not-tmux.html
IMHO <https://cfoust.github.io/cy/replay-mode.html#:~:text=make%20...> is trying to drive down the risk of an Evil Operator reading my files as if it's the 90s at school but my modern risk is that some npm dependency exfiltrates the .borg files, which are readable by me, to North Korea. I was hoping to find an encryption option but did not
> Configuration: cy uses a real programming language, Janet, for configuration.
Man, why everybody gotta reinvent scheme? https://janet-lang.org/#Code-Example
I do like any app with a command palette though https://cfoust.github.io/cy/quick-start/command-palette.html
pjs_
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
remram
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.
kennysoona
> and somehow still less capable than screen's session/pane/window.
How is it less capable?
pkulak
I love it. I have this whole system set up where each desktop gets its own session. So, any time I open a terminal on desktop 2, I get session 2. Then I can make all the windows I need (I very rarely split anything, but cool to be able to) and close the terminal when I’m done. When I open it again later, it’s all still there. I used to absolute overwhelm myself with terminal windows; now it’s all organized.
axiolite
"I tried caviar but found I really prefer hot dogs..."
YouWhy
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.
venusenvy47
Thank you for this. I'm trying to get better at vi(m) and I'm looking for something similar that I can pull up while editing a document - I struggle to remember some basic keystrokes when I need them.
My favorite tmux command from the shell is: "tmux new -A -s me", which I have aliased to "tm". It creates a tmux session named "me", or attaches to a session named that if it already exists.
zvr
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.
Malcolmlisk
This is a good question. Some user made a good list in superuser https://superuser.com/questions/236158/tmux-vs-screen.
For me, it's because it's more common to use tmux and you can find from legacy configs to modern ones. So, for me, that I have not studied IT (and now I work as a programmer) it's essential to find basic configurations all over the place to have an anchor.
But, as always... Use whichever works for you. Don't think in the "best" or the "most efficient" which is just youtube propaganda. Use whichever works for you and makes you feel like home. If that's 98's microsoft word... then embrace it and be proud to have an opinion.
Yie1cho
For me, these are the main use-case differences.
1. if I start something which will run for a long time and/or the connection is unstable, I start a screen session on the remote node and start the program in it
2. if I want to check something (i.e. tail -f foo.log) on several servers at the same time, I start tmux on my machine, create 2,3,...,N panes and in each pane I ssh to the 1-1 remote server and start tail -f foo.log there. So I'll see the logs at the same time on several servers, just like if I had 1-1 monitor for each remote server.
venusenvy47
I use tmux specifically for your first example. I'm not a power user, but after trying screen and tmux, I didn't find anything missing in tmux (relative to screen) and I found it easier to do the things I was interested in. I also like having the ability to attach to an existing tmux session or start one if it doesn't already exist by using something like this: "tmux new -A -s me", which I have as an alias and "me" is just a name for the tmux session. I'm not sure if screen has this feature, but I found this single command lets me get going with a multi-window session without having to first check if I already have a session running.
sirfz
there's truecolor support (which is now available in screen 5) and the other thing is clipboard support (not sure what it's called exactly) which basically allows you to directly copy text from screen (or say, neovim) even from remote sessions. Can't think of anything else personally (oh there's undercurl support if you care about that).
I find screen to be more stable than tmux but can't say I had any issues with tmux in the past couple of years (but it bothers me that tmux sessions share the initial environment the first session was launched from iirc). Right now it's the clipboard support that makes me use tmux over screen.
somat
> but it bothers me that tmux sessions share the initial environment the first session was launched from.
It does do this, but I am curious what would be better? I heard this complaint before and It baffles me. let me explain.
environments are... sticky, a child process inherits it's parent processes environment. so the tmux server starts and inherits the environment from the shell that started it, then each pane inherits the environment from the tmux server. As far as I can tell you want each pane to inherit the environment from somewhere else but can't figure out why or how that would happen.
My best guess is that you want tmux-attach to stash the environment it was ran in so that tmux could then use that when making new panes. my second guess is that you want tmux to use the current pane as the parent process for a new pane. both of which sounds like it would be even harder to control the tmux environment.
sirfz
Any changes to ~/.bashrc or even ~/.tmux.conf would not reflect in any newly created session unless you terminate all sessions and start afresh. In screen, every new session starts from the current host environment which is more convenient
kennysoona
I use it because I like seeing the 'screens' I have open no matter what screen I'm on. Screen itself has no such feature afaik.
lemonwaterlime
I'm a fan of "How to configure tmux from scratch" [1]
Tsiklon
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'
lynx97
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" }
eu
it's missing changing Ctrl+B to Ctrl+A:
# ~/.tmux.conf
set-option -g prefix C-a
anyfoo
tmux changed screen's C-a prefix to a more sensible C-b. C-a is pretty universally used as "jump to beginning of line", which for screen meant that you'd have to git "C-a a" instead all the time. Seriously annoying, and therefore lots of screen configs changed the prefix away from C-a for that reason.
yjftsjthsd-h
Okay, but C-b is "go back one char" and that's also pretty common? I'd personally lean towards saying maybe either C-z or C-s are better? Because suspending a process is a lot less useful when you've got a full multiplexer, and C-s is just... I guess somebody uses it, but I don't think I've ever used it on purpose and it's kind of annoying to accidentally freeze your terminal (and again, tmux has an actual scrollback mode which seems like it covers that use).
Edit: Oh hey, https://superuser.com/questions/74492/whats-the-least-confli... is a whole discussion of options
anyfoo
Good point. Though C-s is fine unless you have software scroll control enabled, and it's used in emacs and anything that follows its key bindings very often as well for incremental search forward. (It's not used in the shell even though that typically implements emacs bindings, because there you usually want to incrementally search backward, i.e. C-r.) I think C-z is the perfect candidate for the reasons you mentioned.
actinium226
But, go back one char is also left arrow. Why do you need another key for that?
theshrike79
I can easily tap C-a with one hand with very minimal hand position change.
C-b requires me to move my whole hand to reach both keys with my left hand.
Thus: C-a wins
tambourine_man
I use C-Space, easy to type, doesn’t conflict with other shortcuts
_imnothere
Uhh... only if you're not a CJK-language-user, C-Space is a common shortcut to switch between IME state.
ravoori
You must mean changing Ctrl-B to Ctrl-A
ink_13
I set it to backtick (`)
No need for that character 99% of the time, and hitting two in a row will still send it anyway
axiolite
I use backticks in shell scripts all the time. Meanwhile, I've never had a legit use for: Ctrl-y so that's my tmux escape.
mdaniel
I don't intend this to yuck your yum, but if you haven't seen it shellcheck advises against backticks because they don't nest unlike $(basename $(dirname "...")) along with some other edge cases https://www.shellcheck.net/wiki/SC2006#rationale and https://mywiki.wooledge.org/BashFAQ/082
ledauphin
this is the way.
also works great in combination with `set -g base-index 1` so that switching between the first 9 windows can be done naturally, with `-1, `-2, etc.
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.