'ssh [your server] -t "tmux -CC attach || tmux -CC"'
Just running that command will connect to your server and attach to an existing tmux session, or create a new one if needed, and make use of iTerm's tmux integration, so you can use the standard macOS keyboard commands (or the UI) to do things like switch tabs, make new tabs, close them, make new windows, etc. all using tmux and a single ssh connection. You can press 'esc' in the command window to detach from your session and when you return (just using that alias) all your work is just as you left it.When I do this, it opens a new window with the "attached tmux running inside" and the old window is running in "tmux mode". Is it possible to not have a new window open, but use the window where the command is run instead?
session "liveform"
directory "/home/minhajuddin/r/liveform/frontend"
window "src", [
pane("vim TODO"),
]
window "server-pry", [
pane("puma --port 3000 --config <(echo '')"),
pane("rails c", :horizontal),
]
window "play", [
pane("git status"),
]
window "misc", [
pane("sidekiq"),
#pane("httpdebug", :horizontal),
pane("cd ~/s/html; fs", :horizontal),
pane("guard", :horizontal),
]
# vim: filetype=rubyOf course I can see the case for combining both tools. If you have a lot of projects, and/or want REPLs loaded you might not want them sitting around in memory for months if you're not going to use them.
It is trivial to get working. Just use tmux plugin manager to install tmux-resurrect and tmux-continuum.
https://github.com/tmux-plugins/tpm
Example usage in my dotfiles: https://github.com/positron/dotfiles/blob/master/.tmux.conf#...
I'm also working on a little app that allows you to open files in Finder into console Tmux+Nvim.
Project: https://github.com/airbnb/appear
Tmux library source: https://github.com/airbnb/appear/blob/master/lib/appear/tmux...
Tmux library docs: http://www.rubydoc.info/gems/appear/Appear/Tmux
Example usage: https://github.com/airbnb/appear/blob/master/lib/appear/edit...
Nvim+Tmux file handler app: https://github.com/airbnb/appear/pull/11
require "tummy/version"
module Tummy
# Your code goes here...
endI am a bit biased, but it has been working very nicely for me. It also has ability to pass raw tmux arguments for things which aren't supported by it.
Really wish more tools took care into making solid defaults and not assuming all users are like the ones on their mailing lists.
set -g mouse on
Likewise, to select from mouse you probably need to press "Shift" in Linux or "Fn" in Mac.I've had more issues with Mac than in Linux with tmux tbh.
IMHO man is the most important command in unix and "man man" the first step in learning unix.
Speaking of... https://github.com/tldr-pages/tldr/blob/master/pages/common/...
I personally like the default mouse setting, but you're completely free to change it if you don't. People have different preferences, that's why there are configuration settings to change things.
> I personally like the default mouse setting, but you're completely free to change it if you don't. People have different preferences, that's why there are configuration settings to change things.
Right, but defaults are important. You have to ask yourself why people are using the project. Are people using tmux for its mouse settings? I think people primarily using it for session management. If that's the case, why does it, by default, override my terminal's settings? That just seems like a violation of "do one thing" to me.
Vim-dispatch also has the best intro video to anything ever ;)
If the tests pass then the tmux window the tests were run in will just disappear, if not, you get popped back to the quickfix window with the errors listed.
Give it a go and see how you like it! :)
Prior to that I used tmux for a few years, and screen before that. I suppose the only compelling reason to use DVTM is that it acts like a tiling WM, so if you use one (I use XMonad http://xmonad.org ) the experience is basically the same (mod-h/mod-l to resize, mod-j/mod-k to navigate windows, mod-space to switch layout, etc.).
The main reason I switched is my preference to avoid bloat. DVTM doesn't do everything tmux and screen do, it only does window management. I use dtach ( http://dtach.sourceforge.net ) for persistence. I previously used abduco ( http://www.brain-dump.org/projects/abduco ), but it segfaulted on me a couple of times (months apart, in a non-reproducible way); haven't tried it for about a year, so it might have stabilised.
I use st ( http://st.suckless.org ) as my terminal, again to avoid bloat.
But I must say that st's font rendering of Unicode is more complete than rxvt-unicode or xterm. With the same font configured in all three, st is the one that manages to render the most glyphs of plan9port's unicode sample file. Would be great to have the same in urxvt or xterm.
[0] like switching to a non-existent-numbered screen to get a list of which ones I do have...
It is slightly inconvenient the first time I fire up tmux (with the defaults) on a new host. I just take a 30 second break, create my customized ~/.tmux.conf, and continue on like nothing happened.
If so, what are the advantages? I know automating sessions is one of them, as explained in the article.
I am more interested in hearing about interactions with the terminal. You already get good mouse-less window management with something like i3 or xmonad.
How about copy & paste? I use urxvt plugin for this, but I often find myself using the mouse to select and middle-click. Is tmux better?
The tiling window-manager is used for longer running GUI apps - webbrowser, pdf/email viewer, CAD etc and for apps that I don't context switch as quickly. Also for handling the dual monitor setup.
I use screen for managing a consistent cli environment - that could be anywhere - on my dev machine, or sshd to a dev container or cloud box. I also tend to context switch screen environments much more quickly - eg. between edit (vim), compile and run turnaround.
I imagine using a tiling window manager with tmux you'd have a similar issue. Sshing into a box you can launch tmux and have windows and splits inside, but you couldn't use your WM.
That way, you can yank/put easily using the usual shortcuts from any tmux window to any tmux window. Then, it's usually easiest to only use intra-process pane splitting (keeping it all in vim or emacs) unless you need to do something that doesn't follow a perfect division, like:
top half vim / bottom left vim / bottom right trailing logfile
or something.
More than happy to write a blog post, if you're interested.
I basically always run all my terminals in a single tmux'd window, and run a single instance of vim. I use vim windows when I edit multiple files at a time.
Advantage (of using tmux on top of i3):
When you spin up a new window with i3, it doesn't retain the previous's current working directory. There are some hacks to make it kind of work, none of which work nicely. With tmux it just works.
tmux has synchronized panes. It allows you to send same keystrokes to multiple terminals at once. This is useful for managing multiple host machines at once, i.e. ssh'ing into different machines at checking certain logs.
Disadvantages:
Double the amount of keybindings you need: one set for i3, one set for tmux. i3 allows you to active a mode where keystrokes are 'forwarded', so theoretically you can use the same keybindings for both, although it is very annoying if you forget to active this mode since you're now creating i3 windows instead of tmux panes and have to clean them up.
The reason I'm doing this is that I'm often ssh'd into a box, and having to ssh into multiple terminal is a chore. I often create a spontaneous term that I close after a couple of minutes. Being able to have a dedicated ssh'd workspace where every split is ssh'd into the box would be a godsent.
This would also fix the mouse integration and various other things that annoy me with raw tmux.
I use Moom on the Mac with hotkeys that match the Windows left/right-side tiling, and a custom OpenBox config[1] that matches those too:
https://github.com/rcarmo/docker-templates/blob/master/deskt...
Then on the Mac I usually use the native Terminal (I keep trying to switch to iTerm, but most of the performance issues Terminal had have been ironed out by now), on Linux I usually use lxterminal, and on Windows I either use Cygwin's mintty or (more recently) wsltty to interact with Bash for Windows:
https://github.com/mintty/wsltty
(even though I'm a Microsoft employee, I strongly dislike the "feel" of the standard console and the way it handles both fonts and copy/paste, so I seldom use it at all)
I also tried various hacks to do raise on hover and suchlike, but I found that some things were best left "native" and get along OK with these bare mouseless window management hotkeys.
Incidentally, tmux has a growing following among my colleagues (there are a lot of Microsoft folk getting to grips with Bash and SSH these days, so when I tried to pass on some best practices, tmux was right at the top of the list)
Edit for another reason: I use Tmux on my work laptop (OSX) and on my Desktop (FreeBSD + i3), so my key bindings are supported on essentially whatever machine I'm on.
So my main "jumphost" machine has a tmux session with multiple "tabs" logged in to other systems I manage. I can connect to this tmux session from my work desktop machine, from my laptop, or from home (via VPN). Makes it very easy to stop, go somewhere else, and pick up with everything the way I left it. I also don't worry about dropped remote ssh connections anymore (not uncommon at home because I often have to reset my cheap wireless router).
I don't do anything really advanced with tmux. One thing I'd like to know is a good way to deal with tmux within tmux, I have occasionally stumbled into that situation and then it's hard to get the "inner" tmux to do anything because the "outer" tmux intercepts all the key commands.
https://coderwall.com/p/4b0d0a/how-to-copy-and-paste-with-tm...
It's rather idiosyncratic but I've gotten used to running all my terminals inside a single tmux window. I spend 95% of my time in either a terminal or Chrome so I basically only use awesome to switch between them, or put a browser and terminal side by side.
I have set things up so that I maintain separate screen sessions per context, including separate shell histories (the single biggest win, by far), separate shell defaults, aliases, etc.
Surprise - I don't run tmux. It is simpler to have several roxterm, in these position, with various tabs open. When I work remotely, I use screen on the remote host, but that's all.
To give you an idea of my shortcuts, in a real life scenario ; my caps lock is remapped to control or escape with xcape:
- esc: pop a new roxterm and from wherever I am, bring me to the terminal desktop
- f9: resize this roxterm to the left part of the screen
- esc: pop another roxterm, focus it
- ctrl-f9: resize it to the right vertical slice of the screen
- f4: switch to the browser desktop
- f12: put by browser in full screen, to check some reference without distraction
- f5: switch back to the terminals desktop
- alt-tab: switch to the roxterm that's currently on the right
- f12: make this roxterm full screen to do something without distraction for a while
- f12: demaximize and put back this roxterm where it was
- f9: now move this roxterm to the left, over the other one
- alt-tab: move to the other roxterm that was on the left
- ctrl-f9: put this roxterm in the vertical slice position on the right
- ctrl-space: make this roxterm sticky, showing on all desktop
- f4: move back to the internet desktop to check more documentation
- f9: resize the browser to be on the left part of the screen, so that I can see both the browser and the roxterm
- f5: move back to the terminal desktop. The space occupied by the browser will be replaced by the roxterm I left there, on the left
- alt-tab: move focus to this roxterm
- ctrl-t: open a new tab in this roxterm
- ctrl-v : paste some stuff from the internet browser
(etc..)
I have accomplished all that with about 20 keystrokes, from muscle memory. When I connect my extra wide screen, f10 and f11 have similar windows resizing function as f9 do on the laptop screen. f1 to f8 take me to desktop dedicated to some use or another (f7 is the windows desktop, with visual studio, f6 is the rstudio desktop, etc)
One think I positively hated until recently: copy and paste. Muscle memory means ctrl-shift-c in one application and ctrl-c in another didn't work. So in the terminal, I remapped the sigint signals to ctrl-x with stty. Hitting ctrl-x is just as convenient as ctrl-c and now I can copy paste as needed. ctrl-v to enter verbatim sequences is done with ctrl-q, just like in vim. so ctrl-c and ctrl-v work everywhere.
When I catch myself wanting to use the x copy paste buffer, the middle click is not so hard: on a thinkpad keyboard, it is right below the space key. But I just prefer ctrl-v. The luxury of having 2 independant copy-paste buffers is appreciable for some tasks however :)
Anyway, sorry for the long reply. I just don't have a lot of opportunities to talk about my setup. I am some kind of an optimization freak, I know it. But I don't want an interface to bother me. I have been using that for the last 3 or 4 years after giving up on OSX, and it has one great quality: I don't have to think about it. It just work the way I want. YMMV of course.
tmux really comes into its own when you combine it with Vim and FZF [2]. I was initially hesitant to try tmux, but once I themed my tmux.conf and nailed down the keybindings, it became indispensable to me. I now use tmux as a basic organizational tool, and I always have at least one tmux session running on my desktop.
I have Ctrl+A+S bound to split the tmux screen horizontally, and Ctrl+A+A to toggle maximizing the tmux pane. Shift-DownArrow opens up a new tmux window to the right of the current one. Shift-LeftArrow and Shift-RightArrow move left and right between the tmux windows. I wanted it to be reminiscent of URxvt tabs.
Another one of my favorite bindings works as follows: visually highlight a line in Vim, then hit <leader>tj, which sends the highlighted line of code to an open terminal in a split tmux window below. Very useful for REPLs. You can also open Vim in the lower split terminal and use the same keybinding to send text directly from one Vim instance to another. It uses vim-tbone [3] and some custom bindings from @junegunn.
[1] https://github.com/atweiden/dotfiles
I agree one of the major pain points of X11 systems, terminals, etc is the clipboard. So many different concepts and shortcuts across programs.
I use xmonad, urxvt or xterm, emacs-nox and vimperator. I'm trying to make all them consistent. Perhaps the last thing to polish in my setup.
I use mostly the stock awesomewm taskbar/dock setup. I tried doing custom stuff there and it was doable ... but the "reload my wm and see if it fails to start even though syntax check passed" got old, and I gave up.
I'll usually have my desktop split two thirds terminal, with the remaining third split between browser[1] and slack. (Or all terminal, with the other stuff on additional monitor(s)). I don't usually have enough windows open to use more than one 'tag' or desktop, but when I find myself wandering afield in my browsing, I tends to shunt offtopic stuff off to another tag.
I use two tmux sessions , with one showing at any one time. I run them in Konsole - out of all the terminal emulators I've found, that's the one that can handle massive scroll rates without lagging.
The first tmux session is named 'pairing' and is where I do my day-to-day work. Anyone on my team who sshs in will auto-connect to that session. For a while I had it prompting me for approval via an awesome popup but that broke with the ugprade to more recent versions and wasn't useful enough to fix. I now just have a notification that displays on connect/disconnect.
Within each session, I have topical windows - usually per-project. A single vim and one or more shell panes. I have set up (neo)vim so that any time I "vi" in any pane of a tmux window, it opens in that window's vi session. A given window may have quite a number of shell panes depending on the environment. And for some testing cases, tmux's "synchronize-window" is invaluable.
In vim, I prefer splits to tabs and end up using lots of both. I'm slowly learning to get comfortable with buffers and will see how that changes things.
In the second named session ('private') I manage mail (mutt, but experimenting with more CLI-driven options like nmh), twitter (rainbowstream), irssi (via nested tmux on a cheap vps) and my project/notes/todo manager - which is another three-pane vim split, with shell functions that let me send stuff over there/read from there from anywhere.
I rely heavily on small helper scripts and lately a growing number of custom macros on my keyboard.
Some of the things I've read in the comments here have given me plenty more stuff to explore :)
Heh. Now that I write it up, I see that it's apparently really complex - but it's evolved over time and suits my work really well. I'm still ironing out the info/todo management tooling but it looks promising.
[1] If browsing text wasn't a horrible experience I'd do all of that in the shell too.
Edit: If folks are remotely interested, I can write up a blog post and publish some of my hacks.
I do wish it was a little better on latency sometimes. But overall this environment is ridiculously nice.
My experience wasn't so simple. Griefs: coloring, git support problems, bash aliases. I'm sure there's a way to get it to work, but I wouldn't call it a full featured shell out-of-the-box; at least, it doesn't really compare with Terminal.
I use it (and created it) so I could use ansi-term instead of e-shell. Then C-c C-j lets you treat the term like a normal buffer (move, yank, etc), and C-c C-k when you are done lets you switch back to normal term style buffer.
if [ $TERM = "xterm" ]; then
( (tmux has-session -t remote && \
tmux attach-session -t remote) || \
(tmux new-session -s remote) ) && exit 0
echo "tmux failed to start"
fi
if [ $TERM = "screen" ]; then
clear
cat /etc/motd
fi
This way tmux gets executed serverside always when I login remotely (e.g. via PuTTY), so my logon session and all running programs are always protected against sudden connectivity breaks. Also I rebind Ctrl+B to Ctrl+A via ~/.tmux.conf.Three keyboard combinations to remember for beginner: Ctrl+A C creates a new window, Ctrl+A D detaches, and Ctrl+A {digit} switches windows. I'm not a power user of tmux, just a few basic features is all I need, but they have changed my server administration habits dramatically.
ctrl+b followed by...
% - split pane vertically
" - split pane horizontally
arrow keys - change pane you're typing in
:new-window
2 - switch to window 2
x - kill pane
d - detach
Command line arguments: tmux list-sessions
tmux attach #will attach to last session by default
tmux attach -t0 #will attach to session 0tmux list-sessions
tmux ls
This is my current configuration: https://gist.github.com/dguaraglia/f15f39f339545041845612a5b...
With that and using tmuxp to manage a context for each of my projects, I can quickly "launch" a project and have a window with an editing pane, a pane to run tests and a pane to run deployment commands/anything else, all of the panes are already using the correct Python virtualenv, etc.
This is a pretty comprehensive cheatsheet: https://gist.github.com/MohamedAlaa/2961058
It doesn't interfere with my shell or Vim usage. C-j is redundant in shell as well as Vim because it does what pressing the Enter key would do. Further, in Vim, C-j is synonymous to j in normal and visual modes. C-j is also very easy to type because my right forefinger always returns to j while resting.
This is what my ~/.tmux.conf looks like.
# Set C-j as secondary prefix key.
# C-b remains intact as primary prefix key.
set -g prefix2 C-j
bind-key C-j send-prefix -2
# Eliminate delay after <Esc> key press in Vim.
set -g escape-time 0
# Let Vim use 256 colors.
set -g default-terminal screen-256colorWhen I set up initially on OSX, the conf took me a few to get right so that I have some mousing abilities and reasonable vim support. Here is a copy of my (simple) tmux.conf file: https://gist.github.com/mcescalante/004e649d8484574ce9d296ad...
If you're asking how I copy in general from stdout with the cursor, I select the text (selection appears yellow) and press Enter and it copies to the clipboard :)
Tmux/Screen provides an extra redirectable abstraction layer over the terminal device.
The biggest complaint I regularly see about it is that people are used to the screen keybindings. I wonder why not add an abstraction layer there, where keypresses really call commands that perform the actions, and you could reconfigure these.
This is how Emacs has done it for 30 years...
That's my problem with Tmux. Ctrl-a,d is already burned into muscle memory, and for my applications Screen is "good enough".
2. in the first shell you get run:
tmux set-option prefix C-a
3. now your prefix is C-a like in screen.Permanentize it by changing tmux.conf :)
https://github.com/tmux/tmux/commit/2a1bb9#diff-fefa423d67264099ae82d4d2f5422b09
However, it appears that they have removed it at the beginning of the year. At least it's still in the commit history. set -g prefix C-a
unbind C-b
bind C-a send-prefix[1]: https://github.com/tmux-plugins/tmux-resurrect [2]: https://github.com/tmux-plugins/tmux-continuum
[1]: https://github.com/tpope/vim-obsession [2]: https://github.com/tmux-plugins/tmux-resurrect/blob/master/d...
What features of the tmux integration do you utilize in iTerm2?
And for sitting through this, here's how to remap the default tmux hotkey: https://github.com/erronjason/dotfiles/blob/master/.tmux.con...
Its ironic that tmux doesn't provide any mechanism to save your terminal history between reboots. Tools like tmuxinator/tmux-resurrect will save your session/window/pane configs, but you lose all your history...
If I could just recover my (typically very valuable) terminal history between reboots, tmux would be the perfect tool for managing my terminal environments...
that said, i do mix screen on the local machine and tmux on the remote machine. lazy, but does the trick. of course one can script either to do everything one needs.
With a pane open as a shell and another pane opened with emacs+intero almost immediately it felt better than using different ssh shells, which is what I usually do. The control-b prefix character use never interfered with any of my activities.
However, I'm prevented from switching to Tmux because you can't attach to the same session from multiple terminals, and show a different window in each terminal.
I use this all the time in Screen - in Tmux, changing the window being viewed in one terminal, changes all other terminals attached to that session.
Similarly my keybindings can be mapped just as I did in my dotfiles (first link). Probably my favorite part is being able to search my terminal instance in vim style with `/` and navigate as I would in any other file
Thanks for posting the .tmux.conf link. Modified the window decorator line as sometimes you can't always tell which pane you are in:
set-option -g set-titles-string '#(whoami)@#H session: #S window: #I-#W pane: #P'
Also noticed that the status right only updates the time if you perform a tmux op.
https://github.com/tmux/tmux/issues/629#issuecomment-2584153...
https://github.com/achiu/consular
to achieve that behavior