DEV Community

Cover image for tmux - A Terminal Multiplexer

tmux - A Terminal Multiplexer

Preslav Mihaylov on May 01, 2018

Last time, I wrote about why I think everyone should try using a bare bones text editor like vim at least for a while. After such an experience, s...
Collapse
 
biros profile image
Boris Jamot ✊ / • Edited

Hi, tmux is a really useful tool when using a terminal without split feature.
I use guake and I easily started tmux with your config, but I face a problem while trying to resize panes vertically with <ctrl+B><ctrl>Up or Down : nothing happens whereas it works perfectly for horizontal splitting.

Any piece of advise?

Collapse
 
pmihaylov profile image
Preslav Mihaylov

Hi Biros,

I tried doing that on my terminal and it worked (the resizing for vertical splits).
Maybe you have remapped Ctrl-Up/Down to something else in some of your configurations?

Try remapping the controls in tmux.conf to not C-up but something else, like C-u or something like that just to debug what the problem is.

Collapse
 
biros profile image
Boris Jamot ✊ /

In fact, the problem is only in full-screen mode with guake.
I also tried with another terminal and it works, whatever it is fullscreen or not.

Collapse
 
pmcgowan profile image
p-mcgowan • Edited

Yes! Tmux + vim (with ctrlp-vim) is the way to go - only one or two terminals per project.

I also added set -g mouse on to .tmux.conf to click-select panes and mouse wheel to scroll (instead of scrolling through bash history).

Collapse
 
dmfay profile image
Dian Fay

To add: if you don't want to deal with the complexity of a multiplexer, use neovim and you get a built-in terminal emulator that can run in a split :)

Collapse
 
aghost7 profile image
Jonathan Boudreau

There's a couple of things that you can do to make tmux feel similar to VIM. I'm my tmux.conf file I have the following:

# When in clipboard selection mode, behave like vim. E.g., "b" will go back a
# word, "w" goes to the start of the next word, "e" goes to the end of the next
# word, etc.
setw -g mode-keys vi

# Start the selection with "v" just like in vim
bind-key -Tcopy-mode-vi 'v' send -X begin-selection

# Copy the selection just like in vim with "y"
bind-key -Tcopy-mode-vi 'y' send -X copy-selection

# Move around panes like you can with ctrl+w in VIM
bind-key j select-pane -D
bind-key k select-pane -U
bind-key h select-pane -L
bind-key l select-pane -R

Full config: github.com/AGhost-7/docker-dev/blo...

Collapse
 
pmihaylov profile image
Preslav Mihaylov

That's actually pretty useful. Thanks!

Collapse
 
pmihaylov profile image
Preslav Mihaylov

neovim is a great tool, I agree.

However, tmux can be useful outside of vim as well.

If you want to do a non-vim related task in the terminal, I wouldn't want to have to open vim just to be able to multiplex my terminal.

Correct me if I'm wrong. :P

Collapse
 
dmfay profile image
Dian Fay

It depends, as always. If you're just writing code and need a shell or two to start builds or commit things, the inline terminal emulator is everything you need and more. If you're managing a bunch of servers -- obviously not.

Collapse
 
moopet profile image
Ben Sinclair

You don't need neovim to do that - it's been part of Vim for a while now.

Collapse
 
aboardgravyboat profile image
Jon

Nice to see love on this topic.

It's worth mentioning that with some config, you can use your mouse to switch tabs or resize splits in tmux. With x forwarding, this also works over ssh. Mouse is handy to have while you're learning the shortcuts

Collapse
 
colinmtech profile image
Colin Morgan

Great article. Tmux is an awesome tool and I highly recommend learning it. Tmux sessions also provide a great way to maintain your shell sessions across devices and also for sharing them with others.

Collapse
 
frzleaf profile image
Lê Thành • Edited

It makes windows live again :)

Collapse
 
codevbus profile image
Mike Vanbuskirk

Any reason why you wouldn't use Vim buffers?

Collapse
 
pmihaylov profile image
Preslav Mihaylov

Sometimes you want to use tmux not only as an add-on to vim, but for more generic terminal-related tasks as well.

In those cases, I think it's pointless to have to open vim just to be able to multiplex your terminal.

Collapse
 
iglesias profile image
Fernando J. Iglesias García

For very quick tasks, instead of opening a new tmux pane, I also like to Ctrl+z my vim window, do the quick job, and then go back in a microbeat to vim with fg.