Using tmux for productivity

Tmux comes from Terminal Multiplexer. It’s used to handle multiple terminal sessions in a single window. Sounds cool if you know how you feel when 10 or 12 terminals lying in your desktop.

To start tmux session type… well tmux in your terminal. If you want to create new session with a name type

tmux new -s mysession

You can see the session name on the bottom.

Naming the sessions is crucial sometimes because it gives you a idea what that session was intended to do for you. For creating a new session. See below.

Sessions

Ctrl + b and then :new -s sessionname. Ctrl + b gives us the ability to command to tmux. If we didn’t press that combination we will just end up write in terminal session.

Sessions are like containers. We fill them with our panes. So consider them as buckets for terminals. Apparently only one per window is allowed. Once you create a new session you immediately switch in to that,Detaching the previous one. It doesn’t mean its closed, but hidden underneath the new session. To view sessions in the tmux…

Ctrl + b s

You’ll see the session that is attached.
  • Ctrl + b s list sessions
  • Ctrl + b $ name sessions
Windows

Windows are like individual terminal windows. When created it takes the whole terminal emulators space and presents us with a new playground. Windows can be used to isolate processes and also It comes handy when you want to copy something. Because with panes it will copy what’s other panes as well. Try it, you will see.

[Session name] 0:windowname_1 1:windowname_2
  • Ctrl + b c creates window
  • Ctrl + b w list window
  • Ctrl + b n next window
  • Ctrl + b f find window, Well well well… πŸ˜›
  • Ctrl + b , name window
  • Ctrl + b & kill a window
  • Ctrl + b :swap-windows -s <source window number> -t <destination window number> swaps windows source to destination.
  • Ctrl + b :swap-windows -t -1 moves window to left by one position
  • Ctrl + b :swap-windows -t 1 moves the window to given position.
Panes

True power comes with panes.

  • Ctrl + b " Split pane horizontally
  • Ctrl + b % Split pane vertically
  • Ctrl + b { Move the current pane left
  • Ctrl + b } Move the current pane right
Unlimited Power!!!!

That’s it? No. We still have to move around the panes. And sessions.

To switch between panes use Ctrl + b Arrow keys. And go the last used pane Ctrl + b ;. And also you can switch the layout of your terminal sessions with Ctrl + b Spacebar.

  • Ctrl + b o swap panes. It didn’t swap panes in my experience but switched focus.
  • Ctrl + b q show pane numbers
  • Ctrl + b x kill pane
  • Ctrl + b ! make the pane to a window. To copy text etc.
  • Ctrl + b :join-pane -t <optional session> :<pane index> restore window as a pane. It’s mess but you can customize it with a key. As for default configuration I don’t see it has a key assigned.
  • Ctrl + b + ↑ or Ctrl + b :resize-pane -U <optional size> Resize pane upward
  • Ctrl + b + ↓ or Ctrl + b :resize-pane -D <optional size> Resize pane downward
  • Ctrl + b + β†’ or Ctrl + b :resize-pane -R <optional size> Resize pane right
  • Ctrl + b + ← or Ctrl + b :resize-pane -L <optional size> Resize pane left
  • Ctrl + b x closes the pane
Selecting text

A problem I had by using tmux is scrolling. Turns out we have to use Vim commands fo that. (Oh boy! ) . To enable Vim commands Ctrl + b :setw -g mode-keys vi then…

  • Ctrl + b [ Enter copy mode
  • Ctrl + b PgUp Enter copy mode and go one page up
  • q to quit from copy mode
  • g goto the top line
  • G goto the bottom line
  • Arrow up Scroll up
  • Arrow down Scroll down
  • h move cursor left
  • j move cursor down
  • k move cursor up
  • l move cursor right
  • w move cursor forward one word at a time
  • b move cursor back one word at a time
  • / search forward
  • ? search backward
  • n next keyword occurrence
  • N previous keyword occurrence
  • Spacebar Start selection
  • Esc Copy selection
  • Ctrl + b ]Paste contents to buffer_0
Buffers
  • Ctrl + b :show-buffer show contents of buffer_0
  • Ctrl + b :capture-pane copy entire visible contents to the buffer
  • Ctrl + b :list-buffers Show all buffers
  • Ctrl + b :choose-buffer Show all buffers and paste selected
  • Ctrl + b :save-buffer buf.txt saves the buffer to file
  • Ctrl + b :delete-buffer -b 1 delete buffer_1

Sources

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.