天天看点

tmux配置小谈

基本配置:

在配置文件(

~/.tmux.conf

)中加入下面这条语句:

#设置前缀为Ctrl + a
set -g prefix C-a
           

与此同时,取消默认的前缀按键:

#解除Ctrl+b 与前缀的对应关系
unbind C-b
           

配置完以后,重启tmux起效,或者先按C+b,然后输入

,进入命令行模式,在命令行模式下输入:

你也可以跟我一样,在配置文件中加入下面这句话,以后改了只需要按前缀+r了。

#将r 设置为加载配置文件,并显示"reloaded!"信息
bind r source-file ~/.tmux.conf \; display "Reloaded!"
           

关于前缀,很多人都喜欢改成Ctrl+a,不过我个人更喜欢Ctrl+x,如果你是vim用户,你一定懂的。还有就是面板的切换很不方便,需要先按前缀,再按方向键,还记得vim里面怎么切换各个面板的吗?tmux也可以,因为它支持映射。把前缀映射改成Ctrl+x,再加入如下几条语句,现在切换窗口就和vim一摸一样了,顿时觉得亲切了很多。

#up
bind-key k select-pane -U
#down
bind-key j select-pane -D
#left
bind-key h select-pane -L
#right
bind-key l select-pane -R
           
#select last window
bind-key C-l select-window -l
           

现在我的l键可不能随便按了,Ctrl+x l是切换面板,Ctrl+x Ctrl+l切换窗口,Ctrl+l清屏。

#copy-mode 将快捷键设置为vi 模式
setw -g mode-keys vi
           
备胎构建:      
推荐安装                tpm (Tmux Plugin Manager)做tmux插件管理,再通过tpm安装continuum等插件:      
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm      
编辑~/.tmux.conf,在文件末尾加入以下几行:      
# Set default shell to zsh
# set-option -g default-shell /bin/zsh


# Use the following line to fix OS X tmux problems
# set-option -g default-command "reattach-to-user-namespace -l zsh"


# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'


# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin '[email protected]/user/plugin'
# set -g @plugin '[email protected]/user/plugin'


# Enable automatic restore
set -g @continuum-restore 'on'


# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
      
如果你的默认shell是         zsh                ,请把这句的注释去掉:
      
set-option -g default-shell /bin/zsh
      
如果你用的是Mac OSX,把这句的注释也去掉:
      
set-option -g default-command "reattach-to-user-namespace -l zsh"
      
这主要是         tmux                在OSX下水土不服(更详细的问题描述可以看这篇文章:Reattach-to-user-namespace: The Fix for Your Tmux in OS X Woes),需要用reattach-to-user-namespace黑科技,所以你最好也用MacPorts或者Homebrew装下这个工具:
      
port install tmux-pasteboard
      
brew install reattach-to-user-namespace
      
在终端下执行以下命令更新         tmux                配置,运行         tpm                :
      
tmux source ~/.tmux.conf       
大家如果想对该工具有进一步的了解,可以参考第三个链接!      
参考链接:      
http://blog.csdn.net/robertbaker/article/details/42172203      
https://segmentfault.com/a/1190000006232298
      
http://liam0205.me/2016/09/10/tmux-plugin-resurrect/
      

继续阅读