tmux
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tmux [2021/03/10 20:19] – [Introduction] hc9 | tmux [2022/12/05 06:18] (current) – [Resources] hc9 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Tmux ====== | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | A newer alternative to the classic [[http:// | ||
+ | |||
+ | A Tmux command is usually of the form **CTRL-b KEY**, i.e., you'll have to press the **CTRL** key along with b, followed by a generic KEY. This initial part of a command is called prefix, and can be configured. | ||
+ | |||
+ | You'll need to be a [[http:// | ||
+ | |||
+ | ===== Starting Tmux, detaching and reattaching ===== | ||
+ | |||
+ | You can run tmux with: | ||
+ | |||
+ | '' | ||
+ | |||
+ | You will create a tmux session name 0. If you want to create a session with a more meaningful name, use: | ||
+ | |||
+ | '' | ||
+ | |||
+ | In your terminal a status bar will show up, with the name of your shell in the bottom left (actually, the name of the terminal window you're on), and a clock in the bottom right. There are many customizations possible for this status bar, you can check the documentation for all available options. To detach from a session, type **CTRL-b d**, and you will return to a normal promopt. Tmux will keep your session alive, and to resume it run: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Multiple windows ===== | ||
+ | |||
+ | By default, a Tmux session starts with only one window. You can create more by typing **CTRL-b c**. All windows have a numeric id, and start named as the current shell or command being run. To rename the current window, type **CTRL-b ,**. Then you can switch between windows typing **CTRL-b " | ||
+ | |||
+ | ===== Multiple sessions ===== | ||
+ | |||
+ | As said before, '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | Now, supose you want to connect to your tmux session from one machine, let's say your work computer connected to SDF, and open the same tmux session from another machine, e.g. your home computer. By design, you can't do this directly, like in Screen. To achieve that, you " | ||
+ | |||
+ | '' | ||
+ | |||
+ | It is possible to split windows in a session with **CTRL-b "** or **CTRL-b %**, respectively, | ||
+ | |||
+ | ===== Sharing screen sessions ===== | ||
+ | |||
+ | Sharing a tmux session between users is simple. Optionally, when starting a shared session, you should specify a socket file, running: | ||
+ | |||
+ | '' | ||
+ | |||
+ | Then, you need to change the permissions of that socket to 777 | ||
+ | |||
+ | '' | ||
+ | |||
+ | And finally, you will be able to share a session with other users. A caveat is that all users connected to that section will use the Tmux configuration of the user who created it. To attach to a shared session: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== .tmux.conf ===== | ||
+ | |||
+ | Tmux is configured by a file located at $HOME/ | ||
+ | |||
+ | <file config $HOME/ | ||
+ | |||
+ | # makes window' | ||
+ | set -g base-index 1 | ||
+ | |||
+ | # resize windows only when a smaller client is using a session | ||
+ | setw -g aggressive-resize on | ||
+ | |||
+ | # disables panel selection using mouse | ||
+ | set -g mouse-select-pane off | ||
+ | |||
+ | # open a man page in a separated split pane | ||
+ | bind m command-prompt -p "man page:" " | ||
+ | |||
+ | # set default terminal | ||
+ | set -g default-terminal " | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Reset Lost Sessions ===== | ||
+ | |||
+ | If you lose the ability to attach a session of tmux (or even see it in `tmux list-sessions`), | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Emulating Emacs-like registers ===== | ||
+ | |||
+ | If you have a need for multiple clipboard-like buffers for storing and retrieving text (akin to registers in Emacs or Vim), Tmux already supports that, although this functionality is not well exposed by default. Below is a sample piece of configuration that makes available 26 registers designated by single lower-case letters //a-z//. | ||
+ | |||
+ | < | ||
+ | |||
+ | # Initialize alphanumerical registers to avoid the problem with ' | ||
+ | run "tmux set-buffer -b a \" | ||
+ | run "tmux set-buffer -b b \" | ||
+ | run "tmux set-buffer -b c \" | ||
+ | run "tmux set-buffer -b d \" | ||
+ | run "tmux set-buffer -b e \" | ||
+ | run "tmux set-buffer -b f \" | ||
+ | run "tmux set-buffer -b g \" | ||
+ | run "tmux set-buffer -b h \" | ||
+ | run "tmux set-buffer -b i \" | ||
+ | run "tmux set-buffer -b j \" | ||
+ | run "tmux set-buffer -b k \" | ||
+ | run "tmux set-buffer -b l \" | ||
+ | run "tmux set-buffer -b m \" | ||
+ | run "tmux set-buffer -b n \" | ||
+ | run "tmux set-buffer -b o \" | ||
+ | run "tmux set-buffer -b p \" | ||
+ | run "tmux set-buffer -b q \" | ||
+ | run "tmux set-buffer -b r \" | ||
+ | run "tmux set-buffer -b s \" | ||
+ | run "tmux set-buffer -b t \" | ||
+ | run "tmux set-buffer -b u \" | ||
+ | run "tmux set-buffer -b v \" | ||
+ | run "tmux set-buffer -b w \" | ||
+ | run "tmux set-buffer -b x \" | ||
+ | run "tmux set-buffer -b y \" | ||
+ | run "tmux set-buffer -b z \" | ||
+ | | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | |||
+ | # Copy to user-selected register | ||
+ | bind -T copy-mode r command-prompt -1 -p ' | ||
+ | # Paste from user-selected register | ||
+ | bind -T prefix C-] command-prompt -1 -p ' | ||
+ | | ||
+ | </ | ||
+ | |||
+ | The way it works is this: when in // | ||
+ | |||
+ | ===== Troubleshooting Colors ===== | ||
+ | |||
+ | If colors are not working in your tmux session try running tmux with the -2 flag. | ||
+ | |||
+ | '' | ||
+ | |||
+ | To persist 256color support in your terminal you can add the following line to your ~/.bashrc | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Resources ===== | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[wp> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | $Id: tmux.html,v 1.6 2014/06/09 06:08:42 ike Exp $ [[http:// | ||