
An introduction to Tmux - frenky
http://perltricks.com/article/an-introduction-to-tmux/
======
n0us
Worth noting that you can enable mouse mode which is significantly easier for
scrolling. It's also recommended by most people that you remap Caps-Lock to
Ctrl and change the activation key from b to a. There are some great themes
that make it nicer to look at as well.

I use tmux all the time for things like sshing into a vagrant box. As soon as
I'm in I can switch between the tail of my logs, the readout of my build tool,
the dev server readout etc. No more fumbling around starting multiple ssh
sessions in multiple iTerm tabs. tmux honestly has been a game changer in
terms of productivity just because of how easy it is to open things up and
look at them. For those who are wondering why you wouldn't just use tabs in
iTerm, its really more of an "also" not an "or"

~~~
smw
Control-a is 'beginning of line'. Why would you possibly pick that?

~~~
sp332
It's what screen uses by default, and a lot of people come to tmux from screen
so they already have the muscle-memory. Not sure of the original logic though.

------
ludwigvan
Here are some things that might be helpful for newcomers.

All those tmux commands, like set, bind-key etc might be put inside your
tmux.conf file, as well as executed as commands directly.

For example, once you are inside a tmux session, simply execute them by
prefixing with tmux:

    
    
      tmux set status off
    
      tmux set status on
    
      tmux set status-style "bg=red"
    
      tmux new-window
    
      tmux new-window -n "my window name"
    
      tmux rename-session mysession
    
    

Of course, you can execute them outside the tmux session too, you just need to
tell it which tmux you want to control.

Open a new terminal, do not enter the tmux session, execute the following:

    
    
      tmux set -t mysession status-style "bg=yellow" 
      tmux new-window -t mysession
    
    

Inside a tmux session, tmux automatically knows which session you are talking
about, so no need for "-t mysession" section.

Now, I hope you get the idea, you can manipulate tmux using a client-server
architecture from the outside, this is the gist of the other tools like
tmuxinator.

You could easily script tmux this way, so that it sets up 4 windows, one
running your server, one running your db etc.

What the keybindings do is, effectively to map these commands to keyboard
shortcuts, you can also execute any command using `C-b :`, similar to how
emacs can do `M-:`. I think tmux was in some ways inspired by emacs.

Hit `C-b :', then run one of the commands, `new-window`, hit Enter.

When you are satisfied with these commands, move them your .tmux.conf file.

However, note that it will not sourced (read) until after you restart tmux or
you source it yourself.

Either quit tmux or do

    
    
      tmux source ~/.tmux.conf
    

Of course, you can similarly group your project-level settings to their own
configs, and source them or start tmux with those settings with tmux -f.

    
    
      tmux source myproject.conf (inside tmux session)
    

or tmux -f myproject.conf (outside tmux session)

------
azaras
I recommend Byobu. Byobu is an elegant enhancement of tmux or Gnu Screen.

For me Byobu is for far easier to use than Tmux.

~~~
ghshephard
I watched the video for a while - and it looks almost identical to tmux -
basically tmux with different key-mappings. I'd almost guess that the someone
has simply gone and skinned the base tmux, everything looks so similar -
panes, sessions, windows, resizing, scrollback, etc...

If you already are familiar with tmux, I don't think Byobu will get you
anything (based on what I saw of the video).

~~~
drummer32
Yeah, byobu is pretty much an opinionated tmux/screen (you can choose a
backend).

------
piratebroadcast
Serious Question: Why would I want to use Tmux instead of iTerm with multiple
tabs open? I don't think I get it. Can anyone ELI5?

~~~
blakesterz
Speaking as someone who doesn't use it, but understands it well, the one and
only thing that excites me is the persistence of sessions, if your connection
drops, you can reconnect and everything is still there. Love that idea.
Everything else is solved that I know it does well (for me) by using tabs. I
could very well be missing other things, I know it does quite a bit, but most
of the things I see other people use it for is solved by tabs (for me at
least).

~~~
StavrosK
Doesn't mosh do that as well (or better)?

~~~
monsieurbanana
I kind of see what you mean, but tmux and mosh are completely different things
and have (almost?) completely different use cases. Mosh is replacement for
ssh.

Without talking about the other _huge_ benefits of tmux, mosh only helps (and
was designed to) prevent disconnections and other inconveniences when your
internet connection falters. If for example your terminal unexpectedly closes
you can't reconnect to your ongoing mosh session (this is an intended feature
for security reasons).

Tmux on the other hand wouldn't help against a poor internet connection, but
at least if your terminal or your ssh session closes you can just restart
another one and wouldn't lose anything.

In other words, always use tmux, and tmux+mosh if your internet connection is
poor.

------
ndmrs
I love tmux but it appears to be messing with my terminal colors for some
reason, especially in vim and after enabling 256 color mode.(Also the line
numbers in vim appears to be bold in tmux when they aren't if run directly
from the terminal, weird.)

~~~
thristian
You may have hit the difference between what a terminal _is_ capable of,
versus what it's _actually_ capable of. Most modern terminals can do all kinds
of fancy things like mouse-support and 256-colour output, but they advertise
themselves as 1990s-era 8-colour devices for compatibility reasons.
Specifically, they set $TERM to "xterm" or similar.

tmux is two kinds of terminal application: it interacts with your outer,
"real" terminal, and it presents an inner, "fake" terminal to the programs
running inside it. By default, tmux will respect the limitations implied by
$TERM, so if your outer terminal claims to be an 8-colour device, tmux will
filter the colours of applications inside it to fit the standard 8-colour
palette.

Vim also respects the limitations implied by $TERM, but some people override
it into using 256-colour mode anyway, by doing something like "set t_Co=256"
in their .vimrc. That works for Vim running in the outer terminal, but it
doesn't work for any other tools running in the outer terminal, and in
particular it doesn't help tmux.

These days, it's generally best to configure your terminal app to set $TERM to
something like "xterm-256color", "nsterm-256color" (for Terminal.app),
"putty-256color" (for PuTTY), "gnome-256color" (for libvte-based emulators) or
similar. If your terminal application doesn't support manually overriding
$TERM, you can do it in your shell profile. That way, every app should
understand your terminal's capabilities, including 256-colour support, both
inside and outside of tmux.

------
ejcx
Discovering tmux and finding a workflow with it that works for me made me so
much more productive

I have a really weird setup though.

I run screen on my laptop with a window for each machine I'm connected to. An
irc box, a VM, a remote dev box, and a local screen. All of these Screen
Windows I have a tmux session in.

I have a minima tmux config that makes resizing panes easy and fast to
whatever size I want and whatever order I want.

It sounds stupid but I see people using multiple iterm or terminal Windows and
I don't know how they do it. It just feels so slow to me. Tmux and screen are
awesome you just need to find one that works for you.

~~~
ludwigvan
You can also have nested tmux sessions instead of screen+tmux setting:

[https://mutelight.org/practical-tmux](https://mutelight.org/practical-tmux)

" Command Sequence for Nested Tmux Sessions

Often I'll run a multiplexer inside another multiplexer and need a command
sequence to send things to the inner session. In Screen, this could be
accomplished using C-a a <command>. This doesn't work out of the box in tmux,
but can be fixed with a little configuration.

bind-key a send-prefix "

~~~
ejcx
I can but I didn't like it as much. Screen out of the box with no screenrc was
exactly what I wanted. now it's kind of stuck, as silly as using screen and
tmux is.

------
lunchladydoris
One of the best tips I got when setting up tmux was to change the default
prefix to ctrl+a. That combined with remapping caps-lock to ctrl makes working
with tmux much more comfortable.

~~~
ghshephard
Or ctrl+s - (I use Ctrl-a all the time to go to beginning of line).
Particularly if you remap Caps-Lock to Ctrl, it's pretty comfortable
combination.

------
deckar01
I recently stumbled across tmux while trying to provide a more customized UX
in a bash script. Tmux and screen seemed a little more powerful than I needed,
with lots of ways to accidentally corrupt the terminal. More and less were
pretty close to what I wanted, but I could not figure out how to accept
arbitrary input from the less prompt, exit, and pass it to bash.

Maybe that's not what less is for. Any tips on how I can create a less UX with
custom input handling would be appreciated.

~~~
zehemer
The select builtin might help in your case:

[http://tldp.org/LDP/Bash-Beginners-
Guide/html/sect_09_06.htm...](http://tldp.org/LDP/Bash-Beginners-
Guide/html/sect_09_06.html)

------
rogerbinns
Is there a good explanation as to why tmux forces all viewers to view the
exact same content? I very frequently want to see different windows (or
whatever the terminology is) on different connections. Screen for example
allowed that by default.

(I do know that you can do some complicated scheme of multiple-layers of
indirection, but really why can't this just work by default?)

------
bcl
He missed one of the most useful commands - ctrl-b z - to zoom a pane to the
full size of the window. Very handy for multi-line copy operations so you
don't get other pane's content or border characters.

tmux is also a great way to keep your workspace available from other machines.
eg. run tmux and all your text mode clients on a server somewhere and ssh into
it.

~~~
jradd
nice! To think I have been using ^-b :break-pane the entire time…

------
nZac
I use tmuxinator to manage all of my tmux sessions.

While, I could write tmux scripts for everything the yaml format does just
about everything I need.

I treat a session as a project, for example mux dotfiles will open a tmux
session, cd into the correct directory, and setup and panes I want when
working with my config, just one. On a customer project I often have one
window for vim, then another window for the server to run, psql, and any
additional services I need.

I have also found, prefix-s to be very helpful to switch between projects very
quickly.

------
airesQ
Recently I've come across the tpm (Tmux Plugin Manager), available at [0].

Happy with it, even though I'm only using two plugins: tmux-sensible (better
defaults) and a theme-pack [1].

[0] - [https://github.com/tmux-plugins/tpm](https://github.com/tmux-
plugins/tpm)

[1] - [https://github.com/jimeh/tmux-themepack](https://github.com/jimeh/tmux-
themepack)

------
renke1
I can only recommend tools like tmuxinator [1]. They make it really easy to
start your development environment. Especially when you deal with multiple
services that need to be started along with certain tasks (mostly watch tasks
like build and test in my case).

[1]:
[https://github.com/tmuxinator/tmuxinator](https://github.com/tmuxinator/tmuxinator)

~~~
anilgulecha
Also
[https://github.com/oxidane/tmuxomatic](https://github.com/oxidane/tmuxomatic),
whose ASCII layout format I find stupid easy to create custom windows and
screens.

~~~
renke1
Wow, that's pretty cool. I tend to use windows a lot though. Within a window I
usually have 3-4 panes that I manage using Ctrl-B space to switch layouts.

------
ashwinaj
I would recommend using mosh+tmux, rather than ssh+tmux, especially if you're
using a laptop to connect to your remote development machine.

~~~
goerz
Ideally yes, but unfortunately mosh doesn't get through most firewalls, as far
as I can tell. A lot of networks filter everything except port 22.

------
picozeta
I sometimes tried that (and used screen for some time), but it never clicked.
AFAIK the only advantage to a scriptable tiling WM is the persistence thing,
but I never had a use-case for that.

------
xufi
Tmux is awesome. been using it for a while but still need to learn more about
it. Its great to have a progress running here and checking on it later while
on another window

------
auxym
I use it over ssh. 1 ssh session, multiple terms/windows/etc. And persistence
of sessions.

------
kr0
The images depict manuals for screen.

------
jtw549
Is this better than putty manager?

~~~
talideon
It serves a different purpose: putty manager is for managing multiple SSH
sessions within a single app, but with tmux running remotely, you only need
one SSH session, and you can leave it running when you disconnect, which is
extraordinarily useful.

------
KKKKkkkk1
Is tmux a MacOS thing? I don't understand why would I want to use it on my
machine. I already have a terminal multiplexer - it's called gnome-terminal
and it supports tabs and multiple windows. Why would I want to add a clunky
middle man with weird key combinations that messes with scrollback and colors?

~~~
blakesterz
>> I don't understand why would I want to use it on my machine. I already have
a terminal multiplexer

I always feel the same way. I've got terminal set to open connections to 6
servers when I open it. I've tried using it, makes perfect sense to me, it's
lovely, but I guess it just solves a problem I don't have? It's one of those
many things that makes me feel like some kind of failure for some reason. Like
using nano as my primary editor. I can use the hell out of emacs and vi, but
for the work I do (I'm a sysadmin), most of the time nano just works, no weird
issues, and it's always there. I know everyone is going to and laugh and me
now, but there it is. I find myself using nano most of the time, though I'll
use emacs a few times a week on some projects. Something about that long reach
to the esc key keeps me away from vi.

~~~
tyingq
When tmux might be handy:

If you find yourself doing repetitive things in those 6 windows. Say they are
production machines that are basically clones of one another. It's simple to
make a key binding that will force all 6 windows to, for example, "tail -f
/var/log/messages". Or start "top" on all of them.

If you kick off a long running task (say a big build) in one of those six
windows, and you leave it running, but go home and watch it finish.
(detach/reattach). It's easier than stdout/stderr redirection, nohup, etc. It
also preserves things you did manually (setting environment variables before
the build) such that restarting a build might be less complex.

You have a peer, not close by, that you want to show how to do something. It
has both read only and read/write session sharing. Your peer can watch what
you're doing, or you can watch them, and take over when needed.

