update
tmux just didn't do it for me. I'm good enough with vim splits and multiple terminal windows. Sharing a tmux session to do remote pairing is a great feature, but I work solo these days. Giving up for now. Feel free to use this doc if it helps you, though.
meta:
- Based on my experience learning and teaching vim, I think the most effective way to learn similar tools (like tmux, with oh so many options/commands) is to start with a core set of commands and their inverses, then add fancy bits later.
- Starting with the core vocabulary, working our way up to the advanced stuff later.
- Beginners need a workflow, a set of recipes, not a list of commands or a table.
- I'm a beginner, so I'll start by shaping this into something I can use and learn from.
To run commands while inside tmux, you use a "control prefix" to tell tmux to grab the keystrokes, instead of sending them on to the active session. This is just like switching modes in vim.
The default "control prefix" is Ctrl-b
. I'll abbreviate it C-b
.
tmux is a server that supports multiple sessions. Each session can contain multiple windows, each is a separate shell. This is better than having a bunch of terminal windows open.
- Create a new session:
]$ tmux new -s <session-name>
- Create a new terminal window:
C-b c
- Rename a window:
C-b ,
- Switch windows:
C-b n
next,C-b p
prev - Delete a window: switch to that window, then
exit
from its command line
End the session, or, leave it for later by detaching from it:
- End a session:
exit
from the last window - Detach from a session without ending it:
C-b d
- List sessions:
tmux ls
- Attach to session foo:
tmux attach -t foo
tmux command | syntax at command line | syntax inside tmux |
---|---|---|
start a session | tmux new -s <session-name> |
C-b :new -s <session-name> |
stop a session | tmux kill-session -t <session-name> |
exit for current session, C-b :kill-session -t <name> for other sessions |
attach to a running session | tmux attach -t <session-name> |
|
detach from a session without ending it | C-b d |
|
switch sessions | C-b s , then pick one interactively |
|
list sessions | tmux ls |
C-b s |
------------------------- | --------------------------------------- | -------------------- |
create window | C-b c |
|
rename window | C-b , |
|
switch windows | C-b n next, C-b p prev |
|
delete window | exit from inside the window |
how to remember the command-line arguments:
-s
is session-name, used to name a new session-t
is target-session, used to identify an existing session
next up: splitting the screen: add/remove, move, resize
tmux calls these panes. I am familiar with them from vim as splits. I don't yet know why I'm using tmux and vim to do basically the same thing. Just playing around here.
- split the window horizontally:
C-b "
- split the window vertically:
C-b %
- switch between windows:
C-b <arrow key>
- resize the window:
C-b C-<arrow key>
- note, by default, mac's terminal app won't do the right thing with Ctrl + arrow keys.
- you have to manually create a mapping for all four keys, such a pain in the ass. superuser Q/A with instructions here.
- this honestly makes me consider using something to run a terminal inside a vim split window.
- ah well. looks like it is possible, but let's just follow through.
Seems like, by default, you can't scroll back to earlier terminal input, at least, not with the mouse.
I found one very slow way to do it: C-b
, then [
, then up/down arrows to move through scrollback. Urgh.
- http://robots.thoughtbot.com/a-tmux-crash-course
- https://mutelight.org/practical-tmux
man tmux
(seriously, the man pages are great)