tmux 和 vim 如何和谐共处?

2016-03-10 09:27:16 +08:00
 tracyone

一个困扰就是 prefix 按键,我设置位 Ctrl-a 。

但是 Ctrl-a 对 vim 来说也是一个挺重要的按键,首先,一般模式下可以递增数字。

然后插入模式下可以映射 Ctrl-a 为跳到行首( Readline key bindings 参考tpope/vim-rsi

但是我也觉得 tmux 用 Ctrl-a 来做 prefix 是比较合理,比较距离比较短。


另外 vim 装了christoomey/vim-tmux-navigator这个插件之后,就可以方便使用 Ctrl-h,ctrl-j,ctrl-k,ctrl-l 来在各个 vim 和 tmux pannel 之间跳转了,但是为啥本身 tmux 不能做到呢(不开 vim )?

7064 次点击
所在节点    Vim
31 条回复
Jeremial
2016-03-10 09:35:29 +08:00
1. tmux 我使用的是默认的 ctrl-b
2. 按照 christoomey/vim-tmux-navigator 里面关于 vim 和 tmux 的配置, 我和 tmux 也可以正常的快速跳转, 你用的是什么版本的 tmux?

我的配置文件 https://githbu.com/Treri/dotfile
Jeremial
2016-03-10 09:36:02 +08:00
hei1000
2016-03-10 09:46:00 +08:00
我的 terminal 默认是 Emacs 快捷键,所以 C-a 是到命令行的行首, tmux 的 prefix 是 M-c ,使用 vim 就不加 M-c ,使用 tmux 就加 M-c ,我的完全没有冲突,当然也有可能是我的 vim 快捷键用的少,主要是用 Emacs
mengzhuo
2016-03-10 09:54:42 +08:00
我的 tmux 用 ctrl+b
vim 的 ctrl+a 楼主你确定不是 emacs ……
yangtukun1412
2016-03-10 09:56:52 +08:00
ctrl + a 估计是用 screen 留下的习惯...
tracyone
2016-03-10 09:59:10 +08:00
@Jeremial 我意思是不开 vim 的情况下,在各个 panel 之间跳转只能按 prefix+hjkl 来跳,没有打开 vim 的情况下来得直接?难道你不是?
tracyone
2016-03-10 09:59:28 +08:00
@mengzhuo ctrl-a 距离短啊...
tracyone
2016-03-10 10:00:06 +08:00
jiezhi
2016-03-10 10:01:56 +08:00
加上这行:

# Ensure that we can send Ctrl-A to other apps
bind C-a send-prefix

可参考: https://gist.github.com/Jiezhi/076543ff6141568c59bf
Jeremial
2016-03-10 10:03:01 +08:00
@tracyone 我就是说的不需要按 prefix, 开不开 vim 都一样
yuuko
2016-03-10 10:03:28 +08:00
tmux 现在支持 true color 了吗?
haoliang
2016-03-10 10:04:12 +08:00
1. <c-b>, <c-a> 这样的映射需要一只手来做,是不是有点影响效率, 也给加重了那只手的负担?
我在用的是 <c-y>, 它本来的映射对于我来说并不是很有用
Monad
2016-03-10 10:06:22 +08:00
我用的<C-K>作为 prefix
感觉这个是被占用最少的快捷键了吧(windows)
pynix
2016-03-10 10:09:21 +08:00
不太习惯 tmux
raptor
2016-03-10 10:10:57 +08:00
ctrl + a 估计是用 screen 留下的习惯...

+1

需要 Ctrl-a 的时候可以在 TMUX 里按 Ctrl-a 然后放掉 Ctrl 再按一次 a
tracyone
2016-03-10 10:14:26 +08:00
@Jeremial ok 我研究下你的配置。
tracyone
2016-03-10 10:15:07 +08:00
@jiezhi 3q 有空翻墙看看😳
hei1000
2016-03-10 10:15:38 +08:00
hei1000
2016-03-10 10:17:36 +08:00
@tracyone gist 不用翻墙了,内容如下

# Setting the prefix from C-b to C-a
set -g prefix C-a

# Free the original Ctrl-b prefix keybinding
unbind C-b

#setting the delay between prefix and command
set -sg escape-time 1

# Ensure that we can send Ctrl-A to other apps
bind C-a send-prefix

# Set the base index for windows to 1 instead of 0
set -g base-index 1

# Set the base index for panes to 1 instead of 0
setw -g pane-base-index 1

# Reload the file with Prefix r
bind r source-file ~/.tmux.conf \; display "Reloaded!"

# splitting panes
bind | split-window -h
bind - split-window -v

# moving between panes
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Quick pane selection
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+

# Pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# mouse support - set to on if you want to use the mouse
setw -g mode-mouse off
set -g mouse-select-pane off
set -g mouse-resize-pane off
set -g mouse-select-window off

# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"

# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on

# set the status line's colors
set -g status-fg white
set -g status-bg black

# set the color of the window list
setw -g window-status-fg cyan
setw -g window-status-bg default
setw -g window-status-attr dim

# set colors for the active window
setw -g window-status-current-fg white
setw -g window-status-current-bg red
setw -g window-status-current-attr bright

# pane colors
set -g pane-border-fg green
set -g pane-border-bg black
set -g pane-active-border-fg white
set -g pane-active-border-bg yellow

# Command / message line
set -g message-fg white
set -g message-bg black
set -g message-attr bright

# Status line left side
set -g status-left-length 40
set -g status-left "#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P"
set -g status-utf8 on

# Status line right side
# 15% | 28 Nov 18:15
set -g status-right "#(~/battery Discharging) | #[fg=cyan]%d %b %R"

# Update the status bar every sixty seconds
set -g status-interval 60 # Center the window list
set -g status-justify centre # enable vi keys.
setw -g mode-keys vi

# Open panes in the same directory using the tmux-panes script
unbind v
unbind n
bind v send-keys " ~/tmux-panes -h" C-m
bind n send-keys " ~/tmux-panes -v" C-m

# Maximize and restore a pane
unbind Up
bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp

# Log output to a text file on demand
bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"

最后附上我的 tmux 配置
https://github.com/c02y/dotfiles/blob/master/tmux/.tmux.conf
tracyone
2016-03-10 10:17:40 +08:00
@hei1000 o 就是哦的意思==!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/262397

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX