Linux tmux学习笔记


Linux tmux学习笔记
 
tmux号称screen的替代品,来看看为什么这么说: 
支持多个window之间的粘贴/复制,可以选择粘贴缓冲区,而这screen不支持。
分屏操作完胜。screen只支持简陋的上下分屏,分屏后还需要ctrl+a+c才能创建一个新的终端。screen直接创建一个终端,且支持屏幕之间的切换/relocate/重定义大小,以及提供了一些预置的layout  www.2cto.com  
tmux默认自带status bar,screen还需手动配置
tmux的配置比screen简单
vi和emac模式绑定                                                    
 
启动tmux: 
tmux ls: list tmux session 
tmux attach: attach a tmux session 
 
tmux启动参数: 
-c: shell-command, 比如 tmux -c vim
-f file: 指定配置文件,默认~/.tmux.conf,或者/etc/tmux.conf
-L socket-name: 制定tmux session的名字
-u: 支持utf-8
-V: version
  www.2cto.com  
tmux的一些概念: 
 
A session is a single collection of pseudo terminals under the management of tmux.  Each session has one or more 
     windows linked to it.  A window occupies the entire screen and may be split into rectangular panes, each of 
     which is a separate pseudo terminal (the pty(4) manual page documents the technical details of pseudo termi‐ 
     nals).  Any number of tmux instances may connect to the same session, and any number of windows may be present 
     in the same session.  Once all sessions are killed, tmux exits. 
 
session: 会话,一个服务器可以包含多个session 
window: 窗口,一个session可以包含多个window 
pane: 面板,一个window可以包含多个pane 
 
tmux 配置: 
tmux默认的bind-key是ctrl + b,可以修改为习惯的ctrl+a: 
set -g prefix ^a 
unbind ^b 
bind a send-prefix 
 
设置之后,ctrl+a+a可以在terminal中将光标一到行首 
 
Vim代码  
set-option -g display-time 4000                                                   
set-option -g status-keys vi                                                      
set-window-option -g mode-keys vi                                               
# set default bind-key to ctrl + a                                                
set-option -g prefix C-a                                                          
unbind-key C-b                                                                    
bind-key C-a send-prefix                                                     
 
# unbind '"'                                                                      
bind - splitw -v # 分割成上下两个窗口                                             
# unbind %                                                                        
bind | splitw -h # 分割成左右两个窗口                                                                                                                    
bind k selectp -U # 选择上窗格                                                    
bind j selectp -D # 选择下窗格                                                    
bind h selectp -L # 选择左窗格                                                    
bind l selectp -R # 选择右窗格                                                 
bind-key J resize-pane -D 10                                                      
bind-key K resize-pane -U 10                                                      
bind-key H resize-pane -L 10                                                      
bind-key L resize-pane -R 10                                                  
bind ^u swapp -U # 与上窗格交换 Ctrl-u                                            
bind ^d swapp -D # 与下窗格交换 Ctrl-d  
bind ^u swapp -U # 与上窗格交换 Ctrl-u                                            
bind ^d swapp -D # 与下窗格交换 Ctrl-d                                       
 
bind m command-prompt "splitw -h 'exec man %%'"                                                                                                       
#定制状态行                                                                       
#状态行左边默认就很好了,我对右边定制了一下,显示 uptime 和 loadavg:        
#set -g status-right "#[fg=green]#(uptime.pl)#[default] • #[fg=green]#(cut -d ' ' -f 1-3 /proc/loadavg)#[default]"  
                                                                            
# 下面两行设置状态行的背景和前景色:                                               
set -g status-bg black                                                            
set -g status-fg yellow                                                           
#默认启动应用                                                                     
#当 tmux 启动时,可以默认启动一些应用:                                           
#new -s work  # 新建名为 work 的会话,并启动 mutt                                 
#neww rtorrent # 启动 rtorrent                                                    
#neww vim # 启动 vim                                                              
#neww sh                                                                          
#selectw -t 1 # 默认选择标号为1的窗口  
 

相关内容

    暂无相关文章