Skip to content

Instantly share code, notes, and snippets.

@Starefossen
Last active August 21, 2024 14:20
Show Gist options
  • Save Starefossen/5955406 to your computer and use it in GitHub Desktop.
Save Starefossen/5955406 to your computer and use it in GitHub Desktop.
My personal tmux cheat sheet for working with sessions, windows, and panes. `NB` I have remapped the command prefix to `ctrl` + `a`.

Sessions

New Session

  • tmux new [-s name] [cmd] (:new) - new session

Switch Session

  • tmux ls (:ls) - list sessions
  • tmux switch [-t name] (:switch) - switches to an existing session
  • tmux as [id] [-t name] (:attach) - attaches to an existing session
  • <C-a>c (:detach) - detach the currently attached session

Session Management

  • <C-a>s - list sessions
  • <C-a>$ - name session

Close Session

  • tmux kill-session [-t name] (:kill-session)

Windows

New Window

  • <C-a>c (:neww [-n name] [cmd]) - new window

Cursor Movement

  • <C-a>[i] (:selectw -t [i]) - go to window [i]
  • <C-a>l - go to last window
  • <C-a>p - go to previous window
  • <C-a>n - go to next window

Window Management

  • <C-a>T - rename window
  • <C-a>, - rename window
  • <C-a>w - list all windows
  • <C-a>f - find window by name
  • <C-a>. - move window to another session (promt)
  • :movew - move window to next unused number

Close Window

  • <C-a>& (:kill-window) - kill window

Panes

New Pane

  • (%) <C-a>| (:splitw [-v] [-p width] [-t focus] [cmd]) - split current pane vertically
  • (") <C-a>s (:splitw -h [-p width] [-t focus] [cmd]) - split current pane horizontally

Cursor Movement

  • (o) <C-a><Tab> (:selectp -t :.+) - move cursor to the next pane
  • <C-a><Up> (:selectp -U) - move cursor to the pane above
  • <C-a><Down> (:selectp -D) - move cursor to the pane below
  • <C-a><Left> (:selectp -L) - move cursor to the pane to the left
  • <C-a><Right> (:selectp -R) - move cursor to the pane to the right
  • :selectp [i] - move cursor to the pane [i]

Panes Management

  • (:swap-pane -U) - move current pane up
  • (:swap-pane -D) - move current pane down
  • <C-a>{ (:swap-pane -L) - move current pane to the left
  • <C-a>} (:swap-pane -R) - move current pane to the right
  • <C-a>q - show pane numbers (type number to move cursor)
  • <C-a><Space> - toggle pane arrangements

Resize Pane

  • :resize-pane -U [i] - move horizontal divider up by [i] lines
  • :resize-pane -D [i] - move horizontal divider down by [i] lines
  • :resize-pane -L [i] - move vertical divider left by [i] columns
  • :resize-pane -R [i] - move vertical divider right by [i] columns

resize-pane [-DLRUZ] [-x width] [-y height] [-t target-pane] [adjustment]

Close Pane

  • <C-a>x (:kill-pane) - kill current pane

Misc

  • <C-a>t - show time
  • <C-a>r - reload config

Sources

@laudai
Copy link

laudai commented Oct 30, 2021

In tmux 3.0a version manual
Can't find swap-pane -L / -R options

@MosJef
Copy link

MosJef commented Nov 1, 2021

In tmux 3.0a version manual Can't find swap-pane -L / -R options

It hasn't changed. Swap pane L/R is still:
<C-a>{ (:swap-pane -L) - move current pane to the left
<C-a>} (:swap-pane -R) - move current pane to the right

Note: make sure you are holding shift to get { as [ is used for other things.

@laudai
Copy link

laudai commented Nov 2, 2021

It hasn't changed. Swap pane L/R is still

This is the manual in tmux 3.0a
圖片

The actually move current pane to right and left command is swap-pane -D / -U
In fact, -D / -U options is move to the next/previous pane number. So it is not work for move the pane to left or right.

test2-2021-11-02_21.45.46.mp4

@MosJef
Copy link

MosJef commented Nov 2, 2021

It hasn't changed. Swap pane L/R is still

This is the manual in tmux 3.0a 圖片

The actually move current pane to right and left command is swap-pane -D / -U In fact, -D / -U options is move to the next/previous pane number. So it is not work for move the pane to left or right.
test2-2021-11-02_21.45.46.mp4

This is also in the man page for tmux 3.0a:
image

The default swap pane shortcuts haven't changed. This action only swaps with previous/next, if you need to define panes which are switched you can use the -s and -t options with the swap-pane command as you mentioned.

@laudai
Copy link

laudai commented Nov 3, 2021

It hasn't changed. Swap pane L/R is still

This is the manual in tmux 3.0a 圖片
The actually move current pane to right and left command is swap-pane -D / -U In fact, -D / -U options is move to the next/previous pane number. So it is not work for move the pane to left or right.
test2-2021-11-02_21.45.46.mp4

This is also in the man page for tmux 3.0a: image

The default swap pane shortcuts haven't changed. This action only swaps with previous/next, if you need to define panes which are switched you can use the -s and -t options with the swap-pane command as you mentioned.

Yes, so the default action is not move the pane to the right or left.
So it can't move pane like as vim buffer to the right or left in this markdown file say.

@MosJef
Copy link

MosJef commented Nov 3, 2021

I get ya, I haven't tested this as I have no need for the workflow, but it looks like:
:bind-key -n C-{ select-pane -L \; swap-pane -s '!'
will select the left pane, and then swap with the previously active pane.

more info here: https://itectec.com/superuser/tmux-keybinding-to-swap-pane-left-or-right/

@laudai
Copy link

laudai commented Nov 4, 2021

Yes, it's exactly what I said. :)
The reason normal user can move the pane to right because the pane number is :

 1  |  2             1  |  3
----|-----   not    ----|-----
  3 | 4               2 | 4   

So in the previous message. I show the what will happen in different number sequence in tmux pane.

Thank you for your information. I will try later and improve my tmux workflow.
Have a nice day.

@laudai
Copy link

laudai commented Nov 9, 2021

I get ya, I haven't tested this as I have no need for the workflow, but it looks like: :bind-key -n C-{ select-pane -L \; swap-pane -s '!' will select the left pane, and then swap with the previously active pane.

more info here: https://itectec.com/superuser/tmux-keybinding-to-swap-pane-left-or-right/

In my tmux workflow. My keybindings is bind -r C-Right swap-pane -s '{right-of}' etc ...
It's more powerful for move smoothly the pane via repeatedly the prefix.

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