Tmux 日常快捷键 及配置

使用Linux的人不管是开发人员、还是运维人员都不可避免的需要使用到终端模拟器(比如,gnome-terminal)去执行一些命令或者脚本。

tmux可以将终端模拟器方便的切分为不同的小窗口如下图如示 

 

 

tmux的官方介绍是

tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more. See the tmux(1) manual page and the README.

 

 

这里记录一下常用的快捷键, tmux默认使用 Ctrl-b 作为激活快捷键的开关, 激活后可以使用下列快捷键

% 将当前Panel(有人称之为窗格)沿纵轴切分

"   将当前Panel沿横轴切分

空格 重新排序Panel

ALT+上/下/左/右  改变Panel大小

Z 将当前Panel最大化, 在最大化时可以将当前窗口恢复到正常大小

C 创建一个新的TAB (也称为window)

N 在TAB之间切换

[  启动上下滚动同时进入vim状态

] 退出上下滚动同时进入vim状态

Pageup/Pagedown 快速翻译滚动同时进入vim状态

 

由于Ctrl-b 需要用到两个手指,且相距较远, 通过配置文件我将其对应到了`按键(大写键上面一个, 经过长时间的使用, 不影响键盘的使用),  以及Ctrl+\ (只需要右手)两种激活方式

以下是配置方式

vi ~/.tmux.conf 

unbind-key C-b
set-option -g prefix `
set-option -g prefix2 'C-\' 
setw -g mode-keys vi
set-option -g history-limit 65535
bind -n C-k clear-history
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"

 

另外为了避免每次启动terminal后都要手动运行tmux, 可以在~/.bashrc中增加一行, 这样就可以在打开终端时默认启动tmux了

let shell use tmux as default environment 

[[ $TERM != "screen" ]] && exec tmux

以便每次打开terminal时, 默认就进入tmux环境

 

posted @ 2018-03-20 16:31  keyleo  阅读(4414)  评论(0编辑  收藏  举报