Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For those who are just getting started with tmux: I advise looking around others' .tmux.conf files for some sensible settings. Like Vim, Tmux ships with a lot of powerful features disabled by default.

My absolute favorite has to be binding a hotkey to opening URLs in the current window [0]. See [1] for a small demo I just recorded.

To get started, here's my current config: [1]

[0]: https://github.com/jbnicolai/tmux/blob/master/.tmux.conf#L12...

[1]: http://recordit.co/vdxy09GpYG

[2]: https://github.com/jbnicolai/tmux/blob/master/.tmux.conf



I wrote a book titled "Getting started with tmux" which can be a helpful guide for those who may want to get started.

http://gettingstartedwithtmux.com

(Sorry if the self plug is not cool, I'm happy to delete this comment if it's not ok but I figure the community may get use out of my work)


As long as the comment is useful and contributes, I think it's fair game. This definitely qualifies. That said, if it's not free, I personally would prefer that be mentioned, (and at the same time a link to a free sample chapter or equivalent if it exists would be useful).


90% of HackerNews is self plug ... so don't worry :)


It was quite a good book! It might be due for an update, what with tmux plugins and other new tools. I'd buy an updated version.


Thanks! It was most helpfull when I got to know tmux.


Here's mine: https://github.com/olalonde/dotfiles/blob/master/tmux.conf

One tweak I can't live without is having the same key bindings to seamlessly switch between tmux panes and Vim split windows. (https://gist.github.com/mislav/5189704)

TPM is also really useful for managing tmux plugins https://github.com/tmux-plugins/tpm.

My prefix key is Ctrl-Space. It's very convenient to press on the keyboard, I'm surprised to not see it used more widely (maybe because it's commonly bound to some OS utilities?).


> One tweak I can't live without is having the same key bindings to seamlessly switch between tmux panes and Vim split windows.

YES, THIS! Setting up directional pane navigation to work with both tmux and vim panes as first-class entities was a huge workflow boon for me as well. It was a significant change that helped kick my setup over into vim+tmux+zsh as IDE vs. merely a collection of separate parts.

It's worth noting that some relevant bits of @mislav's stuff has been packaged up nicely as a Vim plugin:

https://github.com/christoomey/vim-tmux-navigator

I also just noted that @tarruda (of neovim fame) chimed in on @mislav's gist with his own independently created version of the Vim-side of things. It looks worth comparing some of the implementation details from @tarruda's work, he's done some stuff to eliminate redraws in Vim, etc.


> It was a significant change that helped kick my setup over into vim+tmux+zsh as IDE vs. merely a collection of separate parts.

Same thing here :) I also set `tmux attach -t base || tmux new -s base` as my start command in iTerm which kind of forces me to use tmux windows/panes/sessions instead of iTerm tabs. It took a while to lose the habit of hitting `cmd-t` but was definitely worth it.

The thing that sucks now is that I'm really not sure which parts of my environment can be optimised further other than learning new Vim commands :)


Heh, I have something similar, with a tmux session-start script[1] that's the first thing run by my default iTerm windows. It displays and lets me select from existing sessions via prompt tab completion. Or I can just enter a new session name at the prompt.

In iTerm, this would be a start command of:

    login -fp YOUR_USERNAME /Path/To/local/bin/mux --prompt
Or used directly from a normal command line (with zsh completion [2]) as:

    mux <session_name>
Apologies to tmuxinator users for conflicting with 'mux'; obviously feel free to rename it. This is really just a part of my personal setup vs. a formally published utility, and I don't use tmuxinator.

[1] https://github.com/jwhitley/tilde-local/blob/master/local/bi...

[2] https://github.com/jwhitley/zshrc/blob/master/.zfunctions/_m...


Honest question: Is there any benefit of using tmux over a proper tiling window manager? Or, why would I want to delegate some of the window manager tasks to a terminal emulator?


I use both a tiling window manager (xmonad) and tmux. The main reason I started using tmux was to do pair programming sharing the same terminal via ssh. If you pair program and have never tried this before, I highly recommend trying it. I live in Japan and even pair with people in London using tmux and vim. It's the next best thing to being there.

After I started getting used to using tmux, I found that my workflow naturally separated between things I'm doing on my terminal and things that require X (like my browser). These days I use a separate workspace for X apps and terminal (occasionally moving them around).

To make my life easy, I've added xmonad-like key bindings and window layout to tmux. Since other people are sharing:

https://github.com/ygt-mikekchar/dotfiles/blob/taka/home/.tm...

I often work while travelling and when I'm on the road I often don't bother cranking up X -- just work in the Linux console. Using tmux I barely notice a difference in my workflow and it helps extend the battery.


For me it's having two different terminals connected to same tmux session. I use tiling window manager and work on two monitors. Sometimes there is some stuff that I'm working on on my main monitor but I want to have quick look at the terminal. Because I have two terminals opened on both monitors I can just switch to the other one, press ctrl+f(my prefix)+number and have exactly same window as in my main terminal.

For anyone wondering you can achieve above by typing tmux new-session -t and giving it number/name of your current session.

Also there are minor things that are nice. Like if you need to open another terminal instance in the same directory as you're currently in.


Yes, there's lots of value to tmux outside of "window management", even if you only use it locally. That said, lots of the value is using it remotely.


I use <C-s> myself, but <C-Space> works just as well I suppose. Not bound to any OS utilities on OS X afaict.

Thank you so much for pointing me towards that vim+tmux gist!


I use <C-s> for my local machine, and I make the servers I login to use <C-a>. I bind the caps-lock key to ctrl, so it works out pretty well, and lets me work with both local and remote contexts at the same time fairly nicely.


C-Space sets the mark in emacs, which is a regularly used operation.


> My absolute favorite has to be binding a hotkey to opening URLs in the current window.

I suppose this stops working if you SSH into some box and run tmux there? I've implemented something similar, but as an urxvt plugin instead, which avoids that limitation: http://www.cs.helsinki.fi/u/tmtynkky/urxvt.png (Once Alt-O is pressed, the hotkeys with the red background appear next to each link; pressing the hotkey opens the link in browser and copying to clipboard is also possible)


You're absolutely correct, although I do all my terminal work locally in tmux as well (and often nest any remote work in a secondary remote session).

Liking the plugin you wrote!


Why do you create a new window to maximize a pane [1] instead of using resize-pane -Z (mapped to bind-key z by default)?

[1]: https://github.com/jbnicolai/tmux/blob/master/.tmux.conf#L96


Because <Leader-Z> didn't exist in the latest version of tmux at the time. I've removed it now though, thanks!


> Like Vim, Tmux ships with a lot of powerful features disabled by default.

lol, my tmux keys are basically model after vim. This is the book I used to learn tmux and has vim key settings:

https://pragprog.com/book/bhtmux/tmux


Thanks for reading.


Zoom/Unzoom is now part of default tmux.

<bind>z

So you can remove this line from your config:

https://github.com/jbnicolai/tmux/blob/master/.tmux.conf#L98


You're absolutely right, thank you!


You use ctl+s as your bind?


I use ctrl+s on my local config and I use ctrl+a on my remote tmux.conf's.

That way I can attach to a remote tmux in a local session and not produce a terminal muxing singularity that swallows worlds.


I made the mistake of having the same hotkey once. I can verify the existence of said singularity.


Using ` as my bind (no modifier) has been the best thing that's ever happened to my productivity in tmux.


I do the same, and also set up many ` commands to work the same way in emacs.


Consider using <C-Space>. I recently switched and it's made a world of difference to my speed.


Even faster, I set my prefix to just Caps-Lock. See https://github.com/mifix/dotfiles/blob/master/tmux.conf#L5


Amen. This, plus remapping Caps Lock to Ctrl on my Macbook Air was a life changer :)


FWIW, I spent some time deciding what to use years ago and decided on <C-j>. No complaints, and <C-s> feels awkward to me trying it now.


I do. It's closer to the prefix/leader I was used to when using screen (<C-a>), and I find it easier to type.


Ahhhh. Maybe I'll switch from <C-a> to <C-s>, I still miss using <C-a> in Vim to increment integers!


Exactly! And don't forget about <C-a> to move your cursor to the start-of-line in your terminal.


Why not use C-a?


I also use C-s on my local machine because:

1. I can still use C-a with readline (go to first character)

2. If I ssh and then use screen, I can use C-a to navigate my remote screen and C-s to navigate my local tmux.

3. C-s is closer to C-a then other letters on my keyboard.


C-a still works with readline. You just need to C-a first to 'escape' tmux and then C-a again. Actually just hold ctrl and hit 'a' twice.

C-s will suspend the terminal on some platforms. (Which can be resumed by C-q.)


Because C-a already does something useful.


I assume ctrl-s is easier to press than ctrl-a, I have trouble with ctrl-a on Mac with reconfigured CapsLock, and my bind key is ctrl-space.


That's why I remap the right alt key on mac (laptops) to ctrl. Having left right balanced ctrl keys is much more important for my workflow.


For a while I ran a setup where I did all of my work in a local tmux session, but part of this work involved SSH-ing and attaching to a screen session.

When using both, especially nested, I found it beneficial to have a different leader for each.

I also use <^-a> to go to the start of the line, so I'd miss that.


I use `bind a send-prefix` and do a `<^-a> a` to make up for the bind :)


Ctl+s is particularly nice if you've remapped CapsLock to Ctl.


Love your shell prompt. Mind posting your .zshrc/.bashrc?


Nevermind, looks like you are using powerline, found it, got it. :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: