tmux 和 vim 如何和谐共处? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
tracyone
V2EX    Vim

tmux 和 vim 如何和谐共处?

  •  
  •   tracyone 2016-03-10 09:27:16 +08:00 7838 次点击
    这是一个创建于 3553 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一个困扰就是 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 )?

    31 条回复    2016-05-20 09:36:08 +08:00
    wyntau
        1
    wyntau  
       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
    wyntau
        2
    wyntau  
       2016-03-10 09:36:02 +08:00
    hei1000
        3
    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
        4
    mengzhuo  
       2016-03-10 09:54:42 +08:00
    我的 tmux 用 ctrl+b
    vim 的 ctrl+a 楼主你确定不是 emacs ……
    yangtukun1412
        5
    yangtukun1412  
       2016-03-10 09:56:52 +08:00
    ctrl + a 估计是用 screen 留下的习惯...
    tracyone
        6
    tracyone  
    OP
       2016-03-10 09:59:10 +08:00
    @Jeremial 我意思是不开 vim 的情况下,在各个 panel 之间跳转只能按 prefix+hjkl 来跳,没有打开 vim 的情况下来得直接?难道你不是?
    tracyone
        7
    tracyone  
    OP
       2016-03-10 09:59:28 +08:00
    @mengzhuo ctrl-a 距离短啊...
    tracyone
        8
    tracyone  
    OP
       2016-03-10 10:00:06 +08:00
    jiezhi
        9
    jiezhi  
       2016-03-10 10:01:56 +08:00   1
    加上这行:

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

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

    +1

    需要 Ctrl-a 的时候可以在 TMUX 里按 Ctrl-a 然后放掉 Ctrl 再按一次 a
    tracyone
        16
    tracyone  
    OP
       2016-03-10 10:14:26 +08:00 via Android
    @Jeremial ok 我研究下你的配置。
    tracyone
        17
    tracyone  
    OP
       2016-03-10 10:15:07 +08:00 via Android
    @jiezhi 3q 有空翻墙看看
    hei1000
        18
    hei1000  
       2016-03-10 10:15:38 +08:00
    hei1000
        19
    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.

    # 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
        20
    tracyone  
    OP
       2016-03-10 10:17:40 +08:00 via Android
    @hei1000 o 就是哦的意思==!
    tracyone
        21
    tracyone  
    OP
       2016-03-10 10:36:45 +08:00
    @raptor 现在是这样的效果。
    tracyone
        22
    tracyone  
    OP
       2016-03-10 10:44:49 +08:00
    @Jeremial 可以在 tmuxpane 之间方便跳转了,漏看了 tmux 的配置。
    easing
        23
    easing  
       2016-03-10 10:54:19 +08:00
    我用 ctrl-\来做 prefix, 因为其它的都被 emacs 占了。。。
    chagel
        24
    chagel  
       2016-03-10 11:25:11 +08:00
    set -g prefix `
    快捷要多键不能忍 :)
    livelazily
        25
    livelazily  
       2016-03-10 13:31:24 +08:00
    针对 pane 之间的跳转, 你需要这个插件: https://github.com/tmux-plugins/tmux-pain-control
    johnnyb
        26
    johnnyb  
       2016-03-10 13:36:54 +08:00
    我用 ctrl-]
    比 ctrl-\ 近一点
    jamesxu
        27
    jamesxu  
       2016-03-10 18:24:39 +08:00
    改成 Ctrl-X
    SpicyCat
        28
    SpicyCat  
       2016-03-11 14:09:45 +08:00
    推荐 byobu
    arakashic
        29
    arakashic  
       2016-03-22 12:48:17 +08:00
    LZ 你要是觉得 Ctrl-a 很顺手的话,试试 Ctrl-q 没准也很顺手。
    Ge4Los
        30
    Ge4Los  
       2016-04-15 19:40:56 +08:00
    prefix 是 ctrl-s , 似乎 byobu 的键位。
    ctrl-a 和 ctrl-b 在命令行以为的时候会用到, ctrl-s 基本没用到。
    griffinqiu
        31
    griffinqiu  
       2016-05-20 09:36:08 +08:00
    ctrl-a 没有别的推荐的
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3231 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 00:38 PVG 08:38 LAX 16:38 JFK 19:38
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86