{"id":188,"date":"2015-07-25T23:55:43","date_gmt":"2015-07-25T15:55:43","guid":{"rendered":"https:\/\/vinta.ws\/code\/?p=188"},"modified":"2026-03-17T01:21:22","modified_gmt":"2026-03-16T17:21:22","slug":"tmux-a-terminal-multiplexer","status":"publish","type":"post","link":"https:\/\/vinta.ws\/code\/tmux-a-terminal-multiplexer.html","title":{"rendered":"tmux: The terminal multiplexer"},"content":{"rendered":"<p>tmux is a command-line tool that can create multiple virtual terminals in one terminal.<\/p>\n<p>ref:<br \/>\n<a href=\"https:\/\/tmux.github.io\/\">https:\/\/tmux.github.io\/<\/a><\/p>\n<h2>Install<\/h2>\n<pre class=\"line-numbers\"><code class=\"language-bash\"># on Ubuntu\n$ sudo apt-get install tmux\n\n # on macOS\n$ brew install tmux\n\n$ tmux -V\ntmux 2.6<\/code><\/pre>\n<h2>Configurations<\/h2>\n<p>in ~\/.tmux.conf<\/p>\n<pre class=\"line-numbers\"><code class=\"language-bash\"># prefix: Control + a\nset -g prefix C-a\n\n# kill-session: Control + a &gt;&gt; X\nbind X confirm-before \"kill-session -t ''\"\n\n# select-pane: Option + arrow key\nbind -n M-Left select-pane -L\nbind -n M-Right select-pane -R\nbind -n M-Up select-pane -U\nbind -n M-Down select-pane -D\n\n# start numbering at 1\nset -g base-index 1\nset-window-option -g pane-base-index 1\n\n# allow for faster key repetition\nset -s escape-time 0\n\n# rather than constraining window size to the maximum size of any client\n# connected to the *session*, constrain window size to the maximum size of any\n# client connected to *that window*. Much more reasonable.\n# CAUTION: not compatible with iTerm2\nsetw -g aggressive-resize off\n\nset -g status-left-length 40\n\nset -g mouse on\n\n# list of plugins\nset -g @plugin 'tmux-plugins\/tpm'\nset -g @plugin 'tmux-plugins\/tmux-sensible'\n\n# initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)\nrun '~\/.tmux\/plugins\/tpm\/tpm'<\/code><\/pre>\n<p>After adding new plugins, you need to press <code>Control + A &gt;&gt; I<\/code> to fetch and install them.<\/p>\n<p>ref:<br \/>\n<a href=\"https:\/\/github.com\/tony\/tmux-config\/blob\/master\/.tmux.conf\">https:\/\/github.com\/tony\/tmux-config\/blob\/master\/.tmux.conf<\/a><\/p>\n<h2>Usage<\/h2>\n<pre class=\"line-numbers\"><code class=\"language-bash\">$ tmux\n\n$ tmux new -s your_project\n\n$ tmux ls\n\n$ tmux attach\n\n$ tmux attach -t your_project\n\n# list all windows with their layouts\n$ tmux list-windows\n\n$ tmux kill-session -t your_project\n\n# kill all sessions\n$ tmux kill-server\n\n# reload settings\n$ tmux source ~\/.tmux.conf<\/code><\/pre>\n<h2>Shortcut Keys<\/h2>\n<pre class=\"line-numbers\"><code class=\"language-bash\">Control + a &gt;&gt; Shift + ?\nlist all shortcut keys\n\nControl + a &gt;&gt; Shift + \"\"\nsplit window horizontally\n\nControl + a &gt;&gt; Shift + %\nsplit window vertically\n\nControl + a &gt;&gt; Arrow keys\nCommand + Option + Arrow keys\nmove the cursor between panels\n\nControl + a &gt;&gt; d\ndetach\n\nControl + a &gt;&gt; c\ncreate a new window\n\nControl + a &gt;&gt; p\nswitch to the previous window\n\nControl + a &gt;&gt; n\nswitch to the next window\n\nControl + a &gt;&gt; w\nControl + a &gt;&gt; 0-9\nswitch to window 0-9\n\nControl + a &gt;&gt; [\nenable copy mode, you can use Option + Up or Option + Down to scroll\n\nControl + a &gt;&gt; Shift + &amp;\nkill the current window\n\nControl + a &gt;&gt; X\nkill the current session<\/code><\/pre>\n<p>ref:<br \/>\n<a href=\"http:\/\/manpages.ubuntu.com\/manpages\/zesty\/en\/man1\/tmux.1.html\">http:\/\/manpages.ubuntu.com\/manpages\/zesty\/en\/man1\/tmux.1.html<\/a><\/p>\n<h2>Tools<\/h2>\n<h3>tmuxp<\/h3>\n<pre class=\"line-numbers\"><code class=\"language-bash\">$ pip install tmuxp<\/code><\/pre>\n<p>A sample config:<\/p>\n<p>in ~\/.tmuxp\/your_project.yaml<\/p>\n<pre class=\"line-numbers\"><code class=\"language-yaml\">session_name: swag\nwindows:\n- window_name: swag\n  layout: main-horizontal\n  focus: 'true'\n  options:\n    automatic-rename: 'off'\n    main-pane-height: 35\n  start_directory: ~\/Projects\/swag-server\n  shell_command_before:\n    - clear\n  panes:\n  - shell_command:\n    - make up\n  - shell_command:\n    focus: 'true'\n  - shell_command:\n    - cd ..\/swag-bot\n    - clear<\/code><\/pre>\n<pre class=\"line-numbers\"><code class=\"language-bash\">$ tmuxp load swag<\/code><\/pre>\n<p>Layouts<br \/>\n<a href=\"https:\/\/tmuxp.git-pull.com\/en\/latest\/examples.html\">https:\/\/tmuxp.git-pull.com\/en\/latest\/examples.html<\/a><\/p>\n<p>ref:<br \/>\n<a href=\"https:\/\/github.com\/tony\/tmuxp\">https:\/\/github.com\/tony\/tmuxp<\/a><br \/>\n<a href=\"https:\/\/github.com\/tony\/tmuxp-config\">https:\/\/github.com\/tony\/tmuxp-config<\/a><\/p>\n<h3>tmux-resurrect<\/h3>\n<pre class=\"line-numbers\"><code class=\"language-bash\">Control + a &gt;&gt; Control + s\nsave tmux env\n\nControl + a &gt;&gt; Control + r\nrestore tmux env<\/code><\/pre>\n<p>ref:<br \/>\n<a href=\"https:\/\/github.com\/tmux-plugins\/tmux-resurrect\">https:\/\/github.com\/tmux-plugins\/tmux-resurrect<\/a><\/p>\n<h3>Integration with iTerm2<\/h3>\n<p>You must create tmux session with <code>-CC<\/code> argument to integrate with iTerm2.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-bash\">$ tmux ls &amp;&amp; read session &amp;&amp; tmux -CC attach -t ${session:-default} || tmux -CC new -s ${session:-default}<\/code><\/pre>\n<p>ref:<br \/>\n<a href=\"https:\/\/gitlab.com\/gnachman\/iterm2\/wikis\/TmuxIntegration\">https:\/\/gitlab.com\/gnachman\/iterm2\/wikis\/TmuxIntegration<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>tmux is a command-line tool that can create multiple virtual terminals in one terminal.<\/p>\n","protected":false},"author":1,"featured_media":317,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[101,74],"class_list":["post-188","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-about-devops","tag-cli-tool","tag-linux"],"_links":{"self":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":0,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts\/188\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/media\/317"}],"wp:attachment":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/media?parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/categories?post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/tags?post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}