tmux安装、配置、使用

一、tmux安装

1.tmux安装之前需要先安装yum install ncurses-devel和libevent2

yum install ncurses-devel

libevent-2.0.20-stable.tar.gz

tar -xzf libevent-2.0.20-stable.tar.gz

cd libevent-2.0.20-stable

./configure --prefix=/tmp/libevent

make 

make install

2.tmux安装

tmux-1.7.tar.gz

tar -xzf tmux-1.7.tar.gz

cd tmux-1.7

CFLAGS="-I/tmp/libevent/include" LDFLAGS="-L/tmp/libevent/lib" ./configure --prefix=/usr/local/tmux

make

sudo make install

在.baserc 文件中加入  PATH=/usr/local/tmux/bin:$PATH

3.启动时发现错误error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory 这个错误提示。

解决类似问题的步骤我相信我的做法可以通用。

1. 首先 find / -name libevent-1.4.so.2 找到缺少的链接文件到底在那儿。

2. LD_DEBUG=libs /usr/local/tmux/bin/tmux -v

3. 从Debug信息中就知道程序去哪里找链接库了。我这边程序去 trying file=/usr/lib/libevent-1.4.so.2 而我的链接库的实际存储位置是 /usr/local/lib/libevent-1.4.so.2

4. 做一个软连接 ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2

5. 搞定。

二、配置

一下是我的一个配置样例供大家参考

## general
set-option -g history-limit 65535
 
## time
set-option -g display-time 5000 # message display time in (ms), should long enough
set-option -g repeat-time 1000 # lasting time (ms) between a repeatable command
set-option -sg escape-time 1 # waiting time (ms) after prefix, small for more responsitive
set-option -g default-terminal "screen-256color"
 
## style
set-option -g status-keys vi
set-window-option -g mode-keys vi
set-window-option -g utf8 on
 
## modify prefix to activate tmux
set-option -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix
 
# control sessions
bind-key z kill-session
 
## split window
unbind '"'
bind - splitw -v # vertical split (prefix -)
unbind %
bind | splitw -h # horizontal split (prefix |)
 
## select pane (move like vim)
bind -r k select-pane -U # above (prefix k)
bind -r j select-pane -D # below (prefix j)
bind -r h select-pane -L # left (prefix h)
bind -r l select-pane -R # right (prefix l)
 
## resize pane
bind -r ^k resizep -U 10 # upward (prefix Ctrl+k)
bind -r ^j resizep -D 10 # downward (prefix Ctrl+j)
bind -r ^h resizep -L 10 # to the left (prefix Ctrl+h)
bind -r ^l resizep -R 10 # to the right (prefix Ctrl+l)
 
## easy to swich window, like byobu
bind-key -n F2 new-window
bind-key -n F3 previous-window
bind-key -n F4 next-window
 
## color
set -g status-fg white
set -g status-bg black
setw -g window-status-fg cyan
setw -g window-status-bg default
setw -g window-status-attr dim
setw -g window-status-current-fg white
setw -g window-status-current-bg red
setw -g window-status-current-attr bright
set -g pane-border-fg green
set -g pane-border-bg black
set -g pane-active-border-fg white
set -g pane-active-border-bg yellow
set -g message-fg white
set -g message-bg black
set -g message-attr bright
 
## status bar
set-option -g status-utf8 on
set -g status-interval 60
set -g status-left "#[fg=green]Session: #S #[fg=yellow]Window: #I #[fg=cyan]Pane: #P"
set -g status-left-length 30
set-option -g status-right "#[fg=cyan]#(date +%H:%M' ')" # right part: time lisk 23:59
set-option -g status-right-length 10 # more space left for center part (window names)
set -g status-justify centre

三、使用

tmux #开启tmux

tmux ls #显示已有tmux列表(C-b s

tmux attach-session -t 数字 #选择tmux

C-b c 创建一个新的窗口

C-b n 切换到下一个窗口

C-b p 切换到上一个窗口

C-b l 最后一个窗口,和上一个窗口的概念不一样哟,谁试谁知道

c-b w 通过上下键选择当前窗口中打开的会话

C-b 数字 直接跳到你按的数字所在的窗口

C-b & 退出当前窗口

C-b d 临时断开会话 断开以后,还可以连上的哟:)

C-b " 分割出来一个窗口

C-b % 分割出来一个窗口

C-b o 在小窗口中切换

C-b (方向键)

C-b ! 关闭所有小窗口

C-b x 关闭当前光标处的小窗口

C-b t 钟表

C-b pageup/pagedo



你可能感兴趣的:(tmux安装、配置、使用)