Skip to content

Instantly share code, notes, and snippets.

@dusenberrymw
Last active September 8, 2024 11:52
Show Gist options
  • Save dusenberrymw/638359ea1ce409a2232375edb4a99948 to your computer and use it in GitHub Desktop.
Save dusenberrymw/638359ea1ce409a2232375edb4a99948 to your computer and use it in GitHub Desktop.
Tmux Tips & Tricks

Quick cheat sheet of helpful tmux commands

  1. tmux new - Create and attach to a new session.
  2. tmux new -s NAME_HERE - Create and attach to a new session named NAME_HERE.
  3. CTRL-b, d - Detach (i.e. exit) from the currently-opened tmux session (alternatively, tmux detach). Note, this means press and hold CTRL, press b, release both, press d.
  4. tmux ls - Show list of tmux sessions.
  5. tmux a - Attach to the previously-opened tmux session.
  6. tmux a -t NAME_HERE - Attach to the tmux session named NAME_HERE.
  7. CTRL-d - Delete (i.e. kill) currently-opened tmux session (alternatively tmux kill-session).
  8. CTRL-b, [ - Enter copy mode, and enable scrolling in currently-opened tmux session. Press q to exit.
  9. CTRL-b, " - Split window horizontally (i.e. split and add a pane below).
  10. CTRL-b, % - Split window vertically (i.e. split and add a pane to the right).
  11. CTRL-b, UpArrow - Move to the pane above (I prefer to rebind this to CTRL-b, k to be similar to Vim).
  12. CTRL-b, DownArrow - Move to the pane below (I prefer to rebind this to CTRL-b, j to be similar to Vim).
  13. CTRL-b, LeftArrow - Move to the pane to the left (I prefer to rebind this to CTRL-b, h to be similar to Vim).
  14. CTRL-b, RightArrow - Move to the pane to the right (I prefer to rebind this to CTRL-b, l to be similar to Vim).
  15. CTRL-b, z - Toggle maximization of current pane.
  16. CTRL-b, ESC, 2 - Resize all panes to equal size.
  17. CTRL-b, q - Show pane numbers.
  18. CTRL-b, x - Kill current pane.
  19. CTRL-b, c - Create a new window.
  20. CTRL-b, n - Switch to next window.
  21. CTRL-b, p - Switch to previous window.
  22. CTRL-b, 3 - Switch to window 3.
  23. CTRL-b, CTRL-b, COMMAND - Send the command to a nested tmux session (repeat prefix for each level of nesting).

Helpful guide: https://danielmiessler.com/study/tmux/#gs.KCjdzRc

Vim-Slime tmux integration (https://github.com/jpalardy/vim-slime)

  1. Connect to tmux session/window/pane for each Vim session:
    • Leave tmux socket name set to default.
    • Target pane notes:
      • : - current window, current pane (a reasonable default)
      • :i - ith window, current pane
      • :i.j - ith window, jth pane
      • h:i.j - tmux session h (either session name or number), the ith window, and the jth pane
  2. CTRL-c, CTRL-c - Send either the explicitly selected text, or the current paragraph (i.e. results of vip).
  3. CTRL-c, v - Reset the tmux connection settings.

iTerm2 Integration

  • Start tmux with tmux -CC to enable native iTerm2 window management of the tmux session. Works for local tmux sessions, or sessions on remote machines.

Reload tmux configuration

tmux source-file ~/.tmux.conf

Dump live tmux buffer to a file

  1. CTRL-b, : to enter the command mode
  2. capture-pane -S -32768 ; save-buffer FILENAME_HERE to save at least the last 32,768 lines from the buffer
@heraldomode
Copy link

nice

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