Skip to content

Instantly share code, notes, and snippets.

@jaredhirsch
Last active September 5, 2017 20:04
Show Gist options
  • Save jaredhirsch/c3ede1aa90f0b3a1a1a9 to your computer and use it in GitHub Desktop.
Save jaredhirsch/c3ede1aa90f0b3a1a1a9 to your computer and use it in GitHub Desktop.
tmux step by step

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.

Basics

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.

Session and window basics

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.

Start a new session
  • Create a new session: ]$ tmux new -s <session-name>
Add multiple windows to a session
  • 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
Leave a session, optionally saving it for later

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
Attach to an existing session
  • List sessions: tmux ls
  • Attach to session foo: tmux attach -t foo

reference table with commands used in this section

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

splitting the screen: panes

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.

make tmux scrollable?

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.

references

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment