User Tools

Site Tools


tmux

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tmux [2021/03/10 20:13] – created hc9tmux [2022/12/05 06:18] (current) – [Resources] hc9
Line 5: Line 5:
 A newer alternative to the classic [[http://savannah.gnu.org/projects/screen/|Screen]] is [[http://tmux.sourceforge.net/|Tmux]]. As a terminal multiplexer, enables you to have multiple terminals open in a windows, saved in a session. You can detach from that session and come back later, and all your windows and programs running on it will still be alive, and share sessions. A newer alternative to the classic [[http://savannah.gnu.org/projects/screen/|Screen]] is [[http://tmux.sourceforge.net/|Tmux]]. As a terminal multiplexer, enables you to have multiple terminals open in a windows, saved in a session. You can detach from that session and come back later, and all your windows and programs running on it will still be alive, and share sessions.
  
-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.+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://sdf.org/?join#meta|MetaARPA]] member in order to use Tmux on SDF You'll need to be a [[http://sdf.org/?join#meta|MetaARPA]] member in order to use Tmux on SDF
Line 19: Line 19:
 ''$ tmux new-session -s session_name'' ''$ tmux new-session -s session_name''
  
-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:+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:
  
 ''$ tmux attach -t session_name'' ''$ tmux attach -t session_name''
Line 25: Line 25:
 ===== Multiple windows ===== ===== 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 number, where number is the number of a window. CTRL-b n and CTRL-b p are both shortcuts to, respectively, the next and previous window.+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 "number"**, where "numberis the number of a window. **CTRL-b n** and **CTRL-b p** are both shortcuts to, respectively, the next and previous window.
  
 ===== Multiple sessions ===== ===== Multiple sessions =====
Line 37: Line 37:
 ''$ tmux new-session -t existing_session -s new_session_name'' ''$ tmux new-session -t existing_session -s new_session_name''
  
-It is possible to split windows in a session with CTRL-b " or CTRL-b %, respectively, for horizontal or vertical orientation. Each one of these split windows is called a pane. In fact, a window in Tmux terminology is a collection of panes, so a window with no splits also contains an unique pane.+It is possible to split windows in a session with **CTRL-b "** or **CTRL-b %**, respectively, for horizontal or vertical orientation. Each one of these split windows is called a pane. In fact, a window in Tmux terminology is a collection of panes, so a window with no splits also contains an unique pane.
  
 ===== Sharing screen sessions ===== ===== Sharing screen sessions =====
Line 57: Line 57:
 Tmux is configured by a file located at $HOME/.tmux.conf, and a sample configuration file is presented below. Tmux is configured by a file located at $HOME/.tmux.conf, and a sample configuration file is presented below.
  
-      # makes window's indexes start from 1 +<file config $HOME/.tmux.conf>
-      set -g base-index 1+
  
-      resize windows only when a smaller client is using a session +makes window's indexes start from 1 
-      setw -g aggressive-resize on+set -g base-index 1
  
-      disables panel selection using mouse +resize windows only when a smaller client is using a session 
-      set -g mouse-select-pane off+setw -g aggressive-resize on
  
-      open a man page in a separated split pane +disables panel selection using mouse 
-      bind m command-prompt -p "man page:" "split-window -h 'exec man %%'"+set -g mouse-select-pane off
  
-      # set default terminal +# open a man page in a separated split pane 
-      set -g default-terminal "screen-256color"+bind m command-prompt -p "man page:" "split-window -h 'exec man %%'" 
 + 
 +# set default terminal 
 +set -g default-terminal "screen-256color" 
 + 
 +</file>
  
 ===== Reset Lost Sessions ===== ===== Reset Lost Sessions =====
Line 79: Line 83:
  
 ''$ tmux attach'' ''$ tmux attach''
 +
 +===== 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//.
 +
 +<file>
 +
 +# Initialize alphanumerical registers to avoid the problem with 'delete-buffer'
 +run "tmux set-buffer -b a \"$(echo ' ')\""
 +run "tmux set-buffer -b b \"$(echo ' ')\""
 +run "tmux set-buffer -b c \"$(echo ' ')\""
 +run "tmux set-buffer -b d \"$(echo ' ')\""
 +run "tmux set-buffer -b e \"$(echo ' ')\""
 +run "tmux set-buffer -b f \"$(echo ' ')\""
 +run "tmux set-buffer -b g \"$(echo ' ')\""
 +run "tmux set-buffer -b h \"$(echo ' ')\""
 +run "tmux set-buffer -b i \"$(echo ' ')\""
 +run "tmux set-buffer -b j \"$(echo ' ')\""
 +run "tmux set-buffer -b k \"$(echo ' ')\""
 +run "tmux set-buffer -b l \"$(echo ' ')\""
 +run "tmux set-buffer -b m \"$(echo ' ')\""
 +run "tmux set-buffer -b n \"$(echo ' ')\""
 +run "tmux set-buffer -b o \"$(echo ' ')\""
 +run "tmux set-buffer -b p \"$(echo ' ')\""
 +run "tmux set-buffer -b q \"$(echo ' ')\""
 +run "tmux set-buffer -b r \"$(echo ' ')\""
 +run "tmux set-buffer -b s \"$(echo ' ')\""
 +run "tmux set-buffer -b t \"$(echo ' ')\""
 +run "tmux set-buffer -b u \"$(echo ' ')\""
 +run "tmux set-buffer -b v \"$(echo ' ')\""
 +run "tmux set-buffer -b w \"$(echo ' ')\""
 +run "tmux set-buffer -b x \"$(echo ' ')\""
 +run "tmux set-buffer -b y \"$(echo ' ')\""
 +run "tmux set-buffer -b z \"$(echo ' ')\""
 +    
 +</file>
 +
 +<file>
 +
 +# Copy to user-selected register
 +bind -T copy-mode r command-prompt -1 -p '(register)' 'delete-buffer -b %1 ; send -X copy-pipe "tmux set-buffer -n %1"'
 +# Paste from user-selected register
 +bind -T prefix C-] command-prompt -1 -p '(register)' 'paste-buffer -b %1'
 +    
 +</file>
 +
 +The way it works is this: when in //copy-mode// you get an additional key binding //r// which prompts you for a single-letter named register in which to store the marked region. In normal mode you get a prefix command //C-b C-]// which prompts for the name of the register whose contents will be pasted at the cursor. You can also list the contents of all buffers by running //C-b :list-buffers//. Manual initializing of all the buffers seems necessary, because otherwise //delete-buffer// complains about trying to delete a nonexistent buffer when used for the first time for a given letter.
 +
 +===== Troubleshooting Colors =====
 +
 +If colors are not working in your tmux session try running tmux with the -2 flag.
 +
 +''$ tmux -2''
 +
 +To persist 256color support in your terminal you can add the following line to your ~/.bashrc
 +
 +''TERM=screen-256color''
  
 ===== Resources ===== ===== Resources =====
Line 86: Line 147:
   * [[https://wiki.archlinux.org/index.php/Tmux| https://wiki.archlinux.org/index.php/Tmux]]   * [[https://wiki.archlinux.org/index.php/Tmux| https://wiki.archlinux.org/index.php/Tmux]]
   * [[http://robots.thoughtbot.com/post/2641409235/a-tmux-crash-course| http://robots.thoughtbot.com/post/2641409235/a-tmux-crash-course]]   * [[http://robots.thoughtbot.com/post/2641409235/a-tmux-crash-course| http://robots.thoughtbot.com/post/2641409235/a-tmux-crash-course]]
-  * [[http://en.wikipedia.org/wiki/Tmux| http://en.wikipedia.org/wiki/Tmux]]+  * [[wp>Tmux|https://en.wikipedia.org/wiki/Tmux]]
  
 ---- ----
  
-$Id: tmux.html,v 1.6 2014/06/09 06:08:42 ike Exp $ [[http://sdf.org/?tutorials/tmux|Tmux: multiple terminals; terminal multiplexer]] - legacy link+$Id: tmux.html,v 1.6 2014/06/09 06:08:42 ike Exp $ [[http://sdf.org/?tutorials/tmux|Tmux: terminal multiplexer; multiple terminals]] - traditional link (using [[wp>Revision_Control_System|RCS]])
  
tmux.1615407194.txt.gz · Last modified: 2021/03/10 20:13 by hc9