欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

A Simple TMUX Tutor

程序员文章站 2022-05-29 12:55:42
"Tmux Wiki" "Installation of CentOS7" "Introduction" "Key Bindings" "Configuring ~/.tmux.conf" "References" Tmux Wiki The follow contents is mainly re ......

tmux wiki

the follow contents is mainly reprinted of learn x in y minutes - tmux.

installation of centos7

# dependce packages
yum install ncurses-devel libevent-devel

# download source code package
wget https://github.com/tmux/tmux/releases/download/2.8/tmux-2.8.tar.gz

# extract & make & make install
tar -zxvf tmux-2.8.tar.gz
cd tmux-2.8
./configure --prefix=/opt/tmux
make && make install

# set path
export path=$path:/opt/tmux/bin

introduction

is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background then later reattached.

tmux conform c/s mode, including followed modules:

  • server - run tmux in terminal to start a server;
  • session - a server can include serveral sessions;
  • window - a session can include serveral windows;
  • pane - a window can include serveral panes.
directive description
tmux [command] run a command
'tmux' with no commands will create a new session
command/option
[new] create a new session
-s "session" create named session
-n "window" create named window
-c "/dir" start in target directory
[attach] attach last/available session
-t "#" attach target session
-d detach the session from other instances
[ls] list open sessions
-a list all open sessions
[lsw] list windows
-a list all windows
-s list all windows in session
[lsp] list panes
-a list all panes
-s list all panes in session
-t list all panes in target
[kill-window] kill current window
-t "#" kill target window
-a kill all windows
-a -t "#" kill all windows but the target
[kill-session] kill current session
-t "#" kill target session
-a kill all sessions
-a -t "#" kill all sessions but the target

key bindings

the method of controlling an attached tmux session is via key combinations called 'prefix' keys.

key description
c-b 'prefix' combination required to use keybings
m-1
system
? list all key bindings
: enter the tmux command prompt
r force redraw of the attached client
t show current time
d detach the current client
d choose a client to detach
[ enter copy mode to copy text or view history.
~ show info messages
s select a new session for the attached client
window
c create a new window
n change to the next window
p change to the previous window
l switch to last window
w choose the current window interactively
& kill the current window
0-9 select windows 0 to 9
, rename current window
. renumber current window no.
f find plain in all windows
pane
% split the current pane into two, left and right
" split the current pane into two, top and bottom
q show no. of splited panes
; switch to last pane
u/d/l/r change to the pane above, below, left, or right
! break the current pane out of the window.
x kill the current pane
o switch to next pane in current window
c-o rotate all panes anti-clockwise
m-o rotate all panes clockwise
c-u/d/l/r resize the current pane in steps of one cell
m-u/d/l/r resize the current pane in steps of five cells
space toggle in preset pane layouts including even-horizontal, even-vertical, main-horizontal, main-vertical, tiled
{ swap the current pane with the previous pane
} swap the current pane with the next pane
m-1 to m-5 arrange panes
m-1 even-horizontal
m-2 even-vertical
m-3 main-horizontal
m-4 main-vertical
m-5 tiled

configuring ~/.tmux.conf

tmux.conf can be used to set options automatically on start up, much like how .vimrc or init.el are used.

# example tmux.conf

### general

# scrollback/history limit
set -g history-limit 2048

# index start
set -g base-index 1

# mouse
set-option -g -q mouse on

# force reload of config file
unbind r
bind r source-file ~/.tmux.conf

### keybinds

# unbind c-b as the default prefix
unbind c-b

# set new default prefix
set-option -g prefix ` 

# return to previous window when prefix is pressed twice
bind c-a last-window
bind ` last-window

# allow swapping c-a and ` using f11/f12
bind f11 set-option -g prefix c-a
bind f12 set-option -g prefix `

# keybind prefrence
setw -g mode-keys vi
set-option -g status-keys vi

# moving between panes with vim movement keys
bind h select-pane -l
bind j select-pane -d
bind k select-pane -u
bind l select-pane -r

# window cycle/swap
bind e previous-window
bind f next-window
bind e swap-window -t -1
bind f swap-window -t +1

# easy split pane commands
bind = split-window -h
bind - split-window -v
unbind '"'
unbind %

# activate inner-most session (when nesting tmux) to send commands
bind a send-prefix

### theme

# statusbar color palatte
set-option -g status-justify left
set-option -g status-bg black
set-option -g status-fg white
set-option -g status-left-length 40
set-option -g status-right-length 80

# pane border color palette
set-option -g pane-active-border-fg green
set-option -g pane-active-border-bg black
set-option -g pane-border-fg white
set-option -g pane-border-bg black

# message color palette
set-option -g message-fg black
set-option -g message-bg green

# window status color palette
setw -g window-status-bg black
setw -g window-status-current-fg green
setw -g window-status-bell-attr default
setw -g window-status-bell-fg red
setw -g window-status-activity-attr default
setw -g window-status-activity-fg yellow

### ui

# notification
setw -g monitor-activity on
set -g visual-activity on
set-option -g bell-action any
set-option -g visual-bell off

# automatically set window titles
set-option -g set-titles on
set-option -g set-titles-string '#h:#s.#i.#p #w #t' # window number,program name,active (or not)

# statusbar adjustments
set -g status-left "#[fg=red] #h#[fg=green]:#[fg=white]#s#[fg=green] |#[default]"

# show performance counters in statusbar
# requires https://github.com/thewtex/tmux-mem-cpu-load/
set -g status-interval 4
set -g status-right "#[fg=green] | #[fg=white]#(tmux-mem-cpu-load)#[fg=green] | #[fg=cyan]%h:%m #[default]"

references