A minimalist guide to tmux
medium.com
medium.com
Another useful thing is to "bind-key C-\ last-window". That makes C-\ C-\ jump back to the last window you visited, which facilitates creating short-lived windows for specific tasks.
Final small tweak I like is "set -g base-index 1" so that C-\ 1 is the first window, 2 is the next, etc. instead of having the first window way over on 0.
My other tweaks are probably more idiosyncratic to my workflow.
But if for some reason I wanted to do that, I would use C-\ : send-prefix. That sends the prefix character to the process running in tmux, in this case the shell. It's also super useful if you ever find yourself running a nested tmux (i.e. in an ssh session) with the same prefix character. You can just send-prefix d to disconnect the remote shell from the remote tmux session, then open a new local shell outside of your local tmux session, log in and reconnect to the remote tmux.
You can open a new shell and reconnect to the remote tmux first, then use Ctrl-b, Shift-D to bring up a list of connected sessions and kick off / detach the nested original one you don't want.
I just realized though that I don't have a mapping for last-window. And there doesn't seem to be a default.
set-option -g prefix `
bind-key ` send-prefix
I don't find it's too much of a pain to press twice when in markdown.I use C-_, which can be "triggered" with C-7 and often with C-/.
# Window switching
bind -n S-up new-window
bind -n S-down confirm-before -p "kill-window #W? (y/n)" kill-window
bind -n S-left prev
bind -n S-right next
# Pane switching
bind -n C-left select-pane -L
bind -n C-right select-pane -R
bind -n C-down select-pane -D
bind -n C-up select-pane -U
# Special pane operations
bind -n C-M-up respawn-pane -k
bind -n C-M-down kill-pane
bind -n C-M-left swap-pane -U
bind -n C-M-right swap-pane -D
# Window splitting
bind -n C-M-\ split-window -h
bind -n C-M-] split-window -vIf you run emacs as a daemon you can do pretty much everything tmux/screen do, without sacrificing precious keystrokes :P
Too bad now I‘m mostly on Windows and miss all these shortcuts. In programs where I can edit the keymapping, I usually change ctrl + a from Select All to jump to beginning of line. I barely use Select All anyway.
IMO the biggest mistake tmux made was not using C-a by default. I don't know anybody who doesn't remap it - it's far more convenient keyboard-wise, and it sets you up for using `screen` on servers where tmux isn't installed. So go ahead and remap it.
[1] http://www.catonmat.net/download/bash-vi-editing-mode-cheat-...
[1] https://www.bountysource.com/issues/4471419-ssh-port-forward...
I generally set up both the same way and sometimes even forget what I'm currently using.
And a semi-random link to more plus what I'd wish I'd seen:
C-a " split vertically (top/bottom)
C-a % split horizontally (left/right)
C-a left go to the next pane on the left
C-a right (or one of these other directions)
C-a ; go to the ‘last’ (previously used) pane
C-a M-left resize by 5 columns
C-a M-right
https://gist.github.com/andreyvit/2921703I do make a few exceptions, though. I stay proficient in VIM and use it for personal projects, but I use the Jetbrains IDEs for professional projects. It really is good enough to justify the price and license.
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
So long as you keep the copyright notice, you are free to add additional restrictions such as those specified in the GPL (keep it open, pretty much).
You might want to ask here to clarify, if you do then please post a link here in a reply: https://opensource.stackexchange.com/
screen -S Testing # Create a named screen for examples:
screen -S Testing -X screen watch date # Run "watch date" in a new window on the remote session
screen -S Testing -X next # Switch back to the initial bash session
screen -S Testing -X stuff "cd /\n" # Type "cd /" and hit enter1) Enter "bash" then vim file.java (some file) 2) Enter :syntax on
I started using tmux last week, and although it's mostly been a good experience, I still haven't been able to settle on a good prefix. I find C-a to be a terrible choice because I actually use that for command line navigation, and so in the meantime I've tried settling on C-q, but it just feels awkward at times.
(Note that I've remapped Caps Lock to Ctrl.)
https://github.com/ransomw/dotfiles/blob/master/tmux.conf
along with a rant about what terminal multiplexers are in the first place
https://github.com/ransomw/dotfiles#tmux
... both are wip, suggestions welcome
My bindings (very happy with them): https://github.com/skilbjo/dotfiles/blob/master/tmux/keybind...
My keyboard layout is set to dvorak, so the o is right next to a, lending similar convenience. I also haven't run into any serious conflicts in Vim, Emacs, or most shell stuff I do.
I use both C-a and C-b in bash all the time.
I guess that is because all the good shortcuts have already been taken!
As Iterm2 has split panels and some level of saving your session and neovim built in termnial I feel tmux may not be needed for local development or am I missing something?
Btw as you’re an iTerm user you might want to read up on its tmux integration, which is quite cute.
#!/bin/bash
tmux split-pane -b -p 30 -d;
tmux send-keys -t {up-of} 'nyancat^M'
"$@"
tmux send-keys -t {up-of} '^C'
tmux kill-pane -t {up-of}
to pop up an obvious animation for longer running processes. like vm startup. When the animation disappears the thing is ready to go. Haven't been bothering with tmux local lately though.(a) Same experience in all machines, Linux or macOS, local or remote (b) You can send keys from one terminal to another, so you can create complex interfaces with specialized windows
Out of those, I have not find any good reason to drop iterm2 for tmux locally.
1. https://github.com/christoomey/vim-tmux-navigator. I use ctrl-h/j/k/l to navigate vim splits, and with vim-tmux-navigator, I can seamlessly move between splits and tmux panes. It's really nice.
2. Project management. I use a separate instance of vim per project I'm working on, and each instance corresponds to a tmux window. I have a no-prefix bind on ctrl-f that brings up the choose-window command, so I can navigate between projects with `ctrl-f <number>`. I haven't found a solution to switch between projects in a single vim instance that is as fast this.
Does that mean that tmux eliminates the need for mosh [0]?
Using mosh + tmux allows you to have both a) state persisted on the remote side, and b) automatic reconnects if your internet drops, or if you change connections. It's a very good combination, if you can handle some of the drawbacks of mosh (no in-terminal scrolling, mostly, but you can outsource that to tmux as well at the cost of a little lag).
A good additional piece of the puzzle is tmux-resurrect [1], which saves and automatically restores a lot of your tmux state to the filesystem so it's proof against power loss and system restarts/relogins. It persists window arrangements and similar, though it obviously can't save everything--the state of programs that were open can't be programmatically preserved (though that's getting closer and closer to seamless with the advent of things like CRIU).
The combination of mosh + tmux + tmux-resurrect is a very popular one and creates a very resilient system for "don't make me think; just log me in to my usual environment"-type systems, or environments where internet connectivity is spotty or the tmux server environment is unreliable or prone to rebooting.
https://superuser.com/questions/209437/how-do-i-scroll-in-tm...
I’m pretty new to using tmux as more than a basic screen replacement, but it seems flexible enough that almost anything you want can be configured.
I would prefer not to have to remember which tmux I was talking to all the time and so I would just connect from a normal shell, but ymmv of course.