Tmux

tmux的简单操作。

Basic

Creating Named Sessions

1
tmux new-session -s basic

or

1
tmux new -s basic

Detaching Sessions

CTRL-b, then d

Reattaching to Existing Sessions

1
tmux new-session -s basic

or

1
tmux ls
  1. If there is only session, then tmux attach.
  2. If there are multiple sessions, then tmux attach -t second_session. BTY, you can also use this when you only have one session.

Killing Sessions

  • In sesssion, use exit.
  • Kill specific session when not in session,
1
tmux kill-session -t basic

BTY, if there is no sessions, after typing tmux ls, you will get

1
failed to connect to server: Connection refused

Creating and Naming Windows

  • In terminal

    -n: the name of new window.

    1
    
    tmux new -s windows -n shell
    
  • In session

    PREFIX c

    PREFIX , will rename the new window.

Moving Between Windows

  • next and previous window

    PREFIX n and PREFIX p

  • default id of window

    PREFIX 0 to PREFIX 9

  • find a window

    PREFIX f

  • window list

    PREFIX w

Close a Window

  • type exit after command finish executed.
  • PREFIX &

If you want to quit a tmux session, you’ll have to close all windows.

Panes

  • vertically: PREFIX %
  • horizontally: PREFIX "
  • switch between them:
    • cycle through: PREFIX o
    • PREFIX UP, PREFIX DOWN, PREFIX LEFT, or PREFIX RIGHT

Pane Layouts

types:

  • even-horizontal
  • even-vertical
  • main-horizontal
  • main-vertical
  • tiled

cycle through these types by pressing PREFIX SPACEBAR.

Closing Panes

  • exit
  • PREFIX X. If there is only one pane in current window, it will close this window at the same time.

Command Mode

press PREFIX : to enter command mode.

  • create new window with a name,
1
new-window -n console
  • create new window with a name and a command,
1
new-window -n processes "top"

top will execute immediately after new window created. What’s really cool is that this window close instantly when you press q to close top.

Quick Reference

创建会话

命令描述
tmux new-session创建一个未命名的会话。可以简写为 tmux new 或者就一个简单的 tmux
tmux new -s development创建一个名为“development”的会话
tmux new -s development -n editor创建一个名为“development”的会话并把该会话的第一个窗口命名为“editor”
tmux attach -t development连接到一个名为“development”的会话

会话、窗口和面板的默认快捷键

快捷键功能
PREFIX d从一个会话中分离,让该会话在后台运行。
PREFIX :进入命令模式
PREFIX c在当前tmux会话创建一个新的窗口,是 new-window 命令的简写
PREFIX 0...9根据窗口的编号选择窗口
PREFIX w显示当前会话中所有窗口的可选择列表
PREFIX ,显示一个提示符来重命名一个窗口
PREFIX &关闭当前窗口,带有确认提示
PREFIX %把当前窗口垂直地一分为二,分割后的两个面板各占50%大小
PREFIX "把当前窗口水平地一分为二,分割后的两个面板各占50%大小
PREFIX o在已打开的面板之间循环移动当前焦点
PREFIX q短暂地显示每个面板的编号
PREFIX x关闭当前面板,带有确认提示
PREFIX SPACE循环地使用tmux的几个默认面板布局

References

  1. [tmux-Productive-Mouse-Free-Development_zh(https://github.com/aqua7regia/tmux-Productive-Mouse-Free-Development_zh)
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus