tmux配置小谈

16 篇文章 0 订阅

基本配置:

在配置文件(~/.tmux.conf)中加入下面这条语句:


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

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

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

配置完以后,重启tmux起效,或者先按C+b,然后输入,进入命令行模式,在命令行模式下输入:

source-file ~/.tmux.conf

你也可以跟我一样,在配置文件中加入下面这句话,以后改了只需要按前缀+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 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值