Tmux Tutorial
leimao.github.io
leimao.github.io
esc + 1: All windows take up equal space horizontally, and stretch the full vertical width
esc + 2: All windows take up equal space vertically, and stretch the full vertical width
esc + 3: The first window takes up half of the screen vertically, and all remaining windows divide up the space equally
esc + 4: The first window takes up half of the screen horizontally, and all remaining windows divide up the space equally
esc + 5: Windows are divided into two equal columns horizontally, and split remaining space vertically.
Even if I have to alter the sizes a bit usually, the pre-defined layouts are super useful for positioning different windows.
Alternatively, there's apparently a forked version of mosh out there with iterm2 support hacked in, but I've not tried it.
Unfortunately.
Tmux + iTerm2 is a fantastic combo that takes all of Tmux's pwer and removes all the downsides.
I searched if anything else used Tmux's Control Channel on Linux to replicate iTerm2's features, and I'm sad that I found nothing.
(Frankly, it's kind of stunning to me that one terminal app on macOS has more useful features than the plethora of me-too terminals on Linux)
If by "useful features" you mean intercepting tmux output and having it integrate with the terminal, then no. But more generally, I think the closest thing to iTerm2 on Linux is Tilix [1].
Such an enormously usable thing, why isn't that readily available on Linux?
So much of it is lost because work machines have been either windows or Ubuntu. I tried a few things but nothing comes even close to the level of overview and speed you have with iterm. In the end I usually end up using multiple windows and too much mouse..
The tmux integration is just the cherry on top
I of course use graphical applications for browsing, image editing, etc. but nearly everything else I do is from the command line and almost all of that happens over tmux, either locally or remotely. I prefer using a new Tmux window instead of a new graphical window for a temporary shell so I usually just end up having one terminal emulator running on my screen.
The value here is state: tmux keeps my state forever which gives me one less thing to worry about or remember. If I can't finish something right away, I know I'll just go back to the tmux window when I have time. Laptop running out of battery? No problems, I'll just reconnect when I find a charger and reboot my laptop.
For example, I have the exact cursor-to-cursor same view for what I do at work whether I'm at my desktop workstation in the office or using my laptop from the home couch. I can literally leave my cursor on a certain line, leave the office, go home, and continue exactly from where I was when I left, the same exact line. Especially using mosh makes it even more transparent: I just open my laptop at home and my work tmux session is already waiting there on my screen, and will update as soon as I reconnect the work vpn.
I'd much prefer to have something like this for browsing too. I'd like to run a browser muxer server that keeps all my tabs online with all the runtime state, making it available to me wherever I happen to connect from. Browsing something interesting on the train but then I had to hop off? No problem, I'd return to that session on the big screen as soon as I get home and open my laptop. Tab and bookmark syncing doesn't go far enough: I'd like to share one live browser process and access that from everywhere.
I could imagine I could rig up something like that using VNC and Xnest/Xephyr but a custom, hand-designed protocol for remote rendering natively in the browser might just work more seamlessly. I would like the browser in my phone to look like a mobile browser even if the content and state came from the browser server. And I definitely would not want to operate a desktop browser over VNC using my phone.
I have Caps Lock set to be Ctrl and tmux set to use Ctrl+a. For a vertical split, I have it mapped to Ctrl+a, |. For horizontal, Ctrl+a, -
It’s pretty flexible.
# In ~/.tmux.conf Change prefix key to Ctrl+z
unbind C-b
set -g prefix C-zIt is stems 100% from the terminal emulator. Just install a better one. Test your keys with https://metacpan.org/source/PEVANS/Tickit-0.67/examples/demo...
Screenshot: https://i.imgur.com/JfHjJXy.png
The only key combos marked not ok are global/taken by the window manager, so they don't arrive at the application.
You have to type: apt install tmux. Or, whatever your distro of choice's package manager install line is. I'd hardly call that going out of one's way.
screen is more akin to a unix program that borrows the styling of options from getopts.
What possible reason can there be?
I usually make a point of setting different prefix keys in that case though.
If you're using screen, you're already sipping the terminal multiplexer coolaid. I think it's the paradigm that's more important than the specific program/implementation.
I've been happy with the switch. I was a long-time `screen` user, too, and something that helped me a lot with the switch to tmux was adding a few lines to my ~/.tmux.conf to change the command prefix from ^b to ^a, like screen. It made the muscle-memory shortcuts I'd used for so long still basically work.
unbind C-b
set -g prefix C-a
bind-key a send-prefix
Hope that helps, and good luck!On the plus side, tmux has plugins that allow pretty sophisticated interactions (more than tmux)
My major painpoint might seem minor, but: If you're using the default ctrl+a meta in screen, and usually keep ctrl pressed when cycling through screen windows, it will take some getting used to tmux as you need to release ctrl as it will otherwise read it as another combination.
Most other stuff is configurable to your liking, though I prefer adapting to new defaults to evaluate the mindset behind the tools.
It's otherwise less different than I imagined, and I'm not sure how much you'll gain from the switch. Unless tmux gurus know a lot of cool secrets that I don't.
Really, if screen works for you, tmux isn't going to change your life. And I say this as someone who used screen for at least 10 years before switching to tmux.
e.g., in screen I could configure "^a j p" to do one command and "^a j d" to for another:
> bind j command -c foo
> # CMD KEY NAME CMD
> bind -c foo p screen -t '% |db' make db
> bind -c foo d screen -t '% |prod' ssh prod
If that's possible, I'd love to know how. It's what stopped me from switching a few months ago, and is now the most painful change after switching again a couple days ago.
I guess I am not a very advanced user but some of its features really appeal to me.
We use Macbooks at work and initially I used iTerm2. I've always been a heavy user of the terminal and split views. (Neo)Vim is my main editor. However, I experienced difficulties switching back and forth between my work laptop and my personal Ubuntu system at home. I switched to tmux to be able to have the exact same set up on both OS's.
Although that was my initial reason for switching; I have come to love tmux. Just the fact that I can quickly SSH into my home machine, attach to my tmux instance and continue working from anywhere is amazing.
See e.g. https://unix.stackexchange.com/questions/450184/in-tmux-how-...
If Alice has a session on a remote machine you have access to. You can run `tmux new-session -s bob -t Alice`
With this both share he same view but can move cursors independently.
Does this mean they have 2 separate cursors, or that that can control the same cursor? Your can sort of do the same thing in screen by using a nested screen session and sharing the outer session with the other user.
I don't want to have to scp over my tmux conf to every single server I jump on, but OTOH difference in pretty much anything but the prefix gets really frustrating with habits. Particularly remembering all the emacs mode-keys when I really want the vi ones.
For tmux, it will look at VISUAL/EDITOR so for vi keys you could just try to remember to run it as "VISUAL=vi tmux" or to run "tmux set -g mode-keys vi" if you forget.
Searching back in the buffer in emacs mode is the one thing I've been keep having to look up
I use one tmux prefix for the local machine and another one for ssh sessions (setup in bash_profile using something like `if [[ -n "$SSH_CLIENT" ]] ; then tmux set-prefix ... etc`. You need different prefixes when using tmux recursively like this, so you can navigate both the inner and outer session.
I also use a different color theme for ssh sessions, whch helps to know which prefix to use until it becomes somewhat subconscious.
I just bind a different prefix and moved the bar to the top locally (I use urxvt+tmux with Ctrl+arrow keys etc to navigate tmux tabs instead of a tabbed terminal client) to get around the nesting issue.
Here's roughly what I use: https://gist.github.com/anthonyclarka2/f2aae1e167c7899d7d263...
It could also be adapted to anything other than ssh. For instance kubectl, aws cli, virtualenvs, etc etc.
Let me know if this helps, and if you have any suggestions!
Recently I wanted to manage a Golang service, found that PM2 is not stable for it yet and I didn't want to install Node.js just for managing the Golang service; so used Tmux for it. It keeps the process up, we can get the basic process stats as in any terminal and I use external monitoring service for alerts when the service is down[2].
Assuming you're on a modern Linux distribution, it's pretty easy creating a systemd service file which will make it easier to manage the service.
For restarting the service, systemd is the way to go.
pc:bt2$ cat ~/bin/t
#!/bin/bash
if [[ $# == 0 ]]; then
echo tmux list-sessions
echo
tmux list-sessions
echo
echo tmuxp sessions
echo
ls ~/.tmuxp
else
tmuxp load $1 || tmux attach -t $1 || tmux new-session -s $1
fi
usage "t session_name"For that I use a file to save the name of the socket and PID, and restore this in my .profile.
tmuxp is also a great tool for creating predefined layouts. Personally I store a config for every client and by typing "tmuxp load client_config" my session is immediatelly available and I can get productive within seconds.
All-together it looks something like this: Open iTerm. autossh -t myRemoteHost "tmux -CC -A"
One question we had was about scrolling in the tmux window and keeping the terminal output (as in Linux where I can scroll back with Shift+PageUp). Does anybody knows how that works with tmux?
To exit just press q or ctrl+c
Note that you have to press Q to exit this mode :(
1) press ctrl + b
2) release
3) press shift + 7
You may already know this, and the RSI concerns still stand (I'm not sure what all goes into RSI risks), but wanted to clarify if the concern is over pressing 4 keys at the same time that are all over the keyboard.
# remap prefix from 'C-b' to 'C-a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
I've heard that he reason for ctrl + b is because screen uses ctrl + a, which just doesn't make any sense to me. You can nest both tmux and screen and to get to an inner layer you press (if ctrl + a has been mapped) ctrl + a + a - and now your command is sent to the inner tmux/screen.Defaults matter. It is not feasible to configure this on every machine you touch so one have to remember both the default one and the sane one...
But at least the defaults should be sensible.
C-b is terrible for your wrist, especially in conjunction with the following commands.
Choosing C-a isn't as much about preference as it is about not-terrible ergonomics. Now people are right to prefer anything other than C-a or C-b but C-a is objectively a much saner default than C-b.
[0] http://xahlee.info/kbd/keyboard_ctrl_vs_capslock_position.ht...
I always use the modifier key on the opposite side of the keyboard to avoid that issue. So for ctrl-b , I press the ctrl key on the right side of the keyboard worth my right pinky and press the b key with my left index finger.
# change prefix to backtick
unbind-key C-b
set-option -g prefix `
bind-key ` send-prefixI've been using C-z for the prefix for ages. It's conveniently nearly under the default position where my fingers lay and it also masks the mostly useless suspend signal which I seemed to accidentally hit every now and then. (If I really want to suspend my program 'C-z z' will do just fine.)
Switching around using, for example, C-z C-n/C-p is pretty fast to key in. You can keep ctrl down for support and then it reduces down to typing 'zn' / 'zp'. YMMV.
How can I use my Mac's mouse to switch the active window in tmux? I have tried Googling this and the .conf setting everyone says to use doesn't work.
set-option -g mouse on tmux attach || tmux new -s main
I also recommend remapping ctrl-b to ctrl-space (set -g prefix C-Space). Easier to hit and as a bonus, ctrl-b will work as expected when connected to a remote tmux session.http://cockpit.27ae60.com/ https://news.ycombinator.com/item?id=15432986
They even show how to use Tmux with Vim which is my favourite setup
Emacs's terminal emulator is almost correct but last few times I tried to use it I had trouble with certain curses-based programs.
Also, disconnecting tmux UI (and even restarting X) does not affect the session, and you can reconnect. Unfortunately, I was not able to reproduce it with Emacs for some reason, though it should be possible.
As far as I know, M-x shell doesn't allow for running multiple shell buffers in emacs, but :term in vim will allow you to do so.
I'm in a tmux session in my desktop. Then I ssh into a server from within tmux. I want to start tmux to be able multiplex and detach from some tasks. What do?
The other thing I didn't care w/byobu was that it had a clock in the bottom row. Once a minute my terminal window would light up telling me that something on that tab had changed.
If I have the time, though, I'll fire up byobu and see if I can make it happen again. I tend to leave sessions open for many months and it wasn't something which happened on a regular basis, and I never experienced it with bare tmux.