tmux-让你完全脱离鼠标的终端神器

什么是tmux

开发中,经常需要多个任务同时进行,因此需要多个终端标签页,如:一个用于vim编辑器,一个操作数据库,一个操作shell,一个连接远程服务器等。多个终端会话的切换并不方便,也容易分神。而且一断开就得重来。

如果有一种工具,可以在一个终端下完成以上操作,那该多好!

以上的各种困扰,tmux都能做到,而且做得比我们想象的还要更好!

概括来说,tmux就是一个终端复用器(terminal multiplexer)。入门文档请看 tmux: Productive Mouse-Free Development 中文版

以下主要介绍如何安装及配置插件,让tmux更加好用

《tmux-让你完全脱离鼠标的终端神器》 image.png

安装tmux

环境:ceontos7

tmux版本:2.3

虽然yum源中有tmux,但版本较旧,是1.8版本,在2.1版本后有很大改变,因此还是使用新版的更好

准备工作

# remove old pkgs
yum remove libevent libevent-devel libevent-headers

# install ncurses
yum install ncurses-devel

# download libevent src
cd /usr/local/src
curl -L https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz -o libevent-2.0.21-stable.tar.gz
tar xvzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure && make
make install
ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

安装tmux

cd /usr/local/src
curl -L https://github.com/tmux/tmux/releases/download/2.3/tmux-2.3.tar.gz -o tmux-2.3.tar.gz
tar -xvzf tmux-2.3.tar.gz
cd tmux-2.3
./configure && make
make install

查看tmux

$ which tmux
/usr/local/bin/tmux

$ whereis tmux
tmux: /usr/local/bin/tmux

$ tmux -V
tmux 2.3

插件安装

插件管理器

tmux有专门的插件管理器(2.1版本后才支持),通过插件管理器可以很方便地安装插件,如同vim的vundle一样

插件管理器tpm

安装过程很简单

下载仓库

$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

将以下代码粘贴到tmux的配置文件~/.tmux.conf中

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

# 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'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

更新配置

$ tmux source ~/.tmux.conf

其他插件

漂亮的主题

面板快捷键操作

其他配置

tmux默认的PERFIX前缀键是ctrl+b,不好按,可将其改为ctrl+a

以下是我的.tmux.conf内容,供你参考:

set -g prefix C-a 
unbind C-b 
set -sg escape-time 1
set -g base-index 1
setw -g pane-base-index 1
bind r source-file ~/.tmux.conf \; display "Reloaded!"

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-pain-control'
set -g @plugin 'seebi/tmux-colors-solarized'

# 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'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm' 
    原文作者:塞亚猫
    原文地址: https://www.jianshu.com/p/c13553ba6590
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞