User Tools

Site Tools


other:tmux_terminal_multiplexing

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
other:tmux_terminal_multiplexing [2021/04/02 18:35]
nanodano
other:tmux_terminal_multiplexing [2022/03/23 16:27] (current)
nanodano
Line 1: Line 1:
 ====== Tmux Terminal Multiplexing ====== ====== Tmux Terminal Multiplexing ======
  
-[[https://github.com/tmux/tmux/wiki|Tmux]] is a terminal multiplexer that lets you have multiple virtual terminals and also split windows and have multiple panes and tabs. Another nice feature is if you are connecting over SSH and using Tmux, Tmux can keep your session going even if you disconnect and re-connect later.+[[https://github.com/tmux/tmux/wiki|Tmux]] is a terminal multiplexer that lets you have multiple virtual terminals and also split windows and have multiple panes and tabs. Another nice feature is if you are connecting over SSH and using Tmux, Tmux can keep your session going even if you disconnect and re-connect later. An alternative to Tmux is [[https://www.gnu.org/software/screen/|GNU Screen]].
  
 ===== Installing ===== ===== Installing =====
Line 46: Line 46:
 tmux list-commands tmux list-commands
 # Within tmux press ''CTRL-b ?'' # Within tmux press ''CTRL-b ?''
 +</code>
 +
 +===== Enabling mouse =====
 +
 +With mouse enabled, you can click between split windows and use the mouse to resize. You can also right click on panes and in the bottom left corner to switch windows and manage processes. It adds a lot of really nice functionality.
 +
 +You must specify ''setw -g mouse on'' in a tmux conf file. For example:
 +
 +<code - .tmux.conf>
 +# ~/.tmux.conf
 +
 +# Enable mouse
 +set -g mouse on
 +</code>
 +
 +<code bash>
 +# Then run tmux as normal
 +tmux
 +# OR to be explicit
 +tmux source-file ~/.tmux.conf
 </code> </code>
  
Line 52: Line 72:
 When you start tmux, you are creating a "session". You can have multiple sessions and they are identified by a number or a name. When you start tmux, you are creating a "session". You can have multiple sessions and they are identified by a number or a name.
  
-<code>+<code bash>
 # List active sessions # List active sessions
 tmux ls tmux ls
Line 61: Line 81:
 # Connect to a session by its numeric ID # Connect to a session by its numeric ID
 tmux attach -t 0 tmux attach -t 0
-If you want to create a named session you can do that like this: 
  
 # Create a new named session # Create a new named session
-tmux new -s "mysession"+tmux new -s mysession 
 + 
 +# Create a new named session + run vim in detached mode 
 +tmux new -s mysession -d "vim"
  
 # Connect to a session by name # Connect to a session by name
-tmux attach -t "mysession"+tmux attach -t mysession
 </code> </code>
  
 Once you are in a session and you want to disconnect,  Once you are in a session and you want to disconnect, 
  
-<code>+<code bash>
 # Use the shell command # Use the shell command
 tmux detach tmux detach
Line 78: Line 100:
 # Or use the keybinds # Or use the keybinds
 CTRL-b d CTRL-b d
 +</code>
 +
 +To kill a session, simply exit the shell like normal with ''exit'' or ''CTRL-d'', or you can send a tmux command to kill the session.
 +
 +<code bash>
 +# End a session by name
 +tmux kill-session -t myapp
 </code> </code>
  
 ===== Windows ===== ===== Windows =====
  
 +The top level object is a session. A session contains windows, and a window contains panes. Here are commands related to windows. Like most things in tmux, you can use the shell command, or the keybind.
 +
 +<code bash>
 tmux new-window tmux new-window
 tmux list-windows tmux list-windows
Line 91: Line 123:
  
 tmux swap-pane -\[UDLR\] tmux swap-pane -\[UDLR\]
 +</code>
  
 +Most of these keybinds must be preceeded with the ''CTRL-b'' chord.
  
-Create a new window - ''c'' +  * Create a new window - ''c'' 
-List window - ''w'' +  List window - ''w'' 
-Select a window - (the number of the window) +  Select a window - (the number of the window) 
-Rename windows - , +  Rename windows - '','' 
-Kill window - & +  Kill window - ''&'' 
-Next window - n +  Next window - ''n'' 
-Previous window - p +  Previous window - ''p'' 
-Last window - l +  Last window - ''l'' 
-Split window horizontally in two panes - " +  Split window horizontally in two panes - ''"'' 
-Split window vertically in to two panes - % +  Split window vertically in to two panes - ''%'' 
- +  Set even split horizontally - ''ALT-1'' 
-Set even split horizontally - ALT-1 +  Set even split vertically - ''ALT-2''
-Set even split vertically - ALT-2+
  
  
 ===== Panes ===== ===== Panes =====
  
 +A pane is the lowest level of hierarchy in screen organizing. The top level is the session, then the session has windows, and a window is made up of panes.
  
-Switch active pane - up/down/left/right arrow +Most of these need to be preceeded by ''CTRL-b'' followed by one of the following keybinds:
-Next pane - o +
-Previous pane - ; +
-Kill pane - x +
-Break out pane in to window - ! +
-Resize pane 1 unit - CTRL- plus left/right/up/down arrow +
-Resize pane 5 units - ALT- plus left/right/up/down arrow +
-Swap pane up/down - { or } +
-Rotate pane up/down - CTRL-o or ALT-o+
  
-===== Common keybinds =====+  * Switch active pane - ''up/down/left/right arrow'' 
 +  * Next pane - ''o'' 
 +  * Previous pane - '';'' 
 +  * Kill pane - ''x'' 
 +  * Break out pane in to window - ''!'' 
 +  * Resize pane 1 unit - ''CTRL'' plus ''left/right/up/down arrow'' 
 +  * Resize pane 5 units - ''ALT'' plus ''left/right/up/down arrow'' 
 +  * Swap pane up/down - ''{'' or ''}'' 
 +  * Rotate pane up/down - ''CTRL-o'' or ''ALT-o'' 
 + 
 + 
 + 
 +===== Send keystrokes to a session ===== 
 + 
 +You can use ''tmux send-keys'' to send keystrokes to a specific session. 
 + 
 +All keys including functions, alt, home, page up, arrow keys, and even mouse actions can all be emulated. Here is a full list of keys from the source code of tmux: 
 +[[https://github.com/tmux/tmux/blob/ec7f5305b1a6e5548f0769f988e76b01ec293dcc/key-string.c#L33-L100]] 
 + 
 +<code bash> 
 +# Send some vim commands to a session 
 +tmux send-keys -t mysession "i" "hello" Enter Escape ":w! test.txt" Enter 
 +</code> 
 + 
 + 
 +===== Other common tasks =====
  
 Every command is assumed to begin with the chord, which by default is ''CTRL-b''. Press ''CTRL-b'' and then release before pressing the next action key. Every command is assumed to begin with the chord, which by default is ''CTRL-b''. Press ''CTRL-b'' and then release before pressing the next action key.
Line 127: Line 178:
  
   * Toggle scrolling with ''CTRL-b [''   * Toggle scrolling with ''CTRL-b [''
-  * Switch to next pre-defined layout: ''SPACE''+  * Switch to next pre-defined layout: ''CTRL-b SPACE'' 
 + 
 + 
other/tmux_terminal_multiplexing.1617388540.txt.gz · Last modified: 2021/04/02 18:35 by nanodano