DEV Community

Cover image for Jaime's Guide to Tmux: The Most Awesome Tool You Didn't know you needed

Jaime's Guide to Tmux: The Most Awesome Tool You Didn't know you needed

Jaime González García on December 25, 2019

This article was originally published on Barbarian Meets Coding. tmux is one of those things in life that at first encounter sound really weird an...
Collapse
 
yujinyuz profile image
Yujin

I use zsh and I added the vi-mode plugin so I could hit and do I what I would normally do in Vim.

I tried removing that plugin and copied your config file in ~/.tmux.conf

setw -g mode-keys vi

But I'm not sure how to activate it, can you help me with this?

Collapse
 
vintharas profile image
Jaime González García

The vi key bindings in tmux that are activated with that configuration only work when you enable copy mode in tmux with CTRL-[. This mode allows you to scroll up/down inside a tmux pane, search, select and copy stuff, etc with vi key bindings.

For using vi bindings when inserting text you'll still need to enable vi within zsh as well. (But the vi support is so so)

The best vim experience in the terminal comes when using :terminal mode inside of Vim. I don't use it often. Only when I need to do something complicated with text in the terminal. But it would be fun to do more experimentation there. Perhaps in time I could rely more on Vim and less on tmux.

Collapse
 
vintharas profile image
Jaime González García

Btw this article describes vi mode in tmux quite well sanctum.geek.nz/arabesque/vi-mode-...

Collapse
 
wrldwzrd89 profile image
Eric Ahnell

Great post! For those of you with new enough versions of Windows 10 to be able to use Windows Terminal, a tool like tmux is not needed to get tabbed terminals. Alas, the console framework isn't (yet) up to the task of simulating what tmux does... also, if you just want tabbed terminals, Terminal.app supports this since "generic" tabs were added in macOS 10.9 "Mavericks", IIRC. As for Linux, it very much depends on what the distribution offers, as is always the case - some support this, like Gnome Terminal. One thing is clear, though - ANY Unix-like terminal with tmux is a better multi-tasking tool.

Collapse
 
vintharas profile image
Jaime González García • Edited

Thank you! And thank you for contributing with all that information! :D

Collapse
 
kennethlum profile image
Kenneth Lum • Edited

You mean for your alias:

alias tn="t new -t"

it really is

alias tn="t new -s"

? Also, for

create a new session with t {session-name}

it is

create a new session with tn {session-name}

?

Collapse
 
cristoamh profile image
Cristo Alberto Medina Henríquez

Hello! Nice post.

I just have 2 questions:

1) You recommended yo remap caps-lock to control key so we can use the shortcut on tmux ctrl+a easily, but me as a vim user, I have been using cap Lock as scape since I started with vim. On mac is awesome because I can have both, scape if cap lock is pressed alone and control if it was pressed with another key. How do you scape from insert mode por example? I just see scape key too far away.

2)I don't know If I misunderstood but, can I go to work use a tmux session then turn off the computer and still working on the day after, attacking myself to the last session? Or I have to leave the computer on?

Thanks!

Collapse
 
vintharas profile image
Jaime González García • Edited

Thank you Cristo!

1)

Cool!! I didn't know you could use it both as Escape and CTRL. I must look into how to do that :D. My mapping to exit insert mode is 'jk', so I type j followed by k, it's very convenient because my fingers are already on top of j and k so it flows very naturally. Alternatively I use CTRL-C or CTRL-[ (for instance, when leaving visual mode).

Anyhow, if I had to choose between having ESC or CTRL in the caps lock position I rather have CTRL because it opens more possibilities than just having ESC. (And ESC can be reproduced with other mappings like jk or CTRL-C, CTRL-[)

2)

I normally have my workstation on so I can SSH from home whenever I need to. So in that case the tmux server is always running and it is trivial to attach to my last session.

You can switch off your computer, and continue working on the day after. But in order for that to work you need to use the tmux-resurrect (which lets you save and restore sessions) which works even better with tmux-continuum (which saves sessions periodically, and automatically restores them when you start tmux).

So:

  • You can reattach if you leave your computer on
  • You can also reattach if you switch off your computer by taking advantage of these plugins: tmux-resurrect and tmux-continuum
Collapse
 
cristoamh profile image
Cristo Alberto Medina Henríquez

Cool! I'll take a look. Later I'll send you how I use ctrl and scape in the same key.

A would like to read your opinion about working with vscode vs tmux-vim.

Maybe a future post(?). I have vim ready to fight but I always end up working on vs code.

Thread Thread
 
vintharas profile image
Jaime González García

Yeah! That would be awesome! :D

hmm I should write an article about that :D Thanks for the idea!

Collapse
 
karx1 profile image
Yash Karandikar

Cool! Do you know whether this works on KDE Konsole?