与 tmux 窗格交互,就像它是一个 vim 缓冲区一样

Zor*_*b29 0 vim tmux

我经常使用 tmux 和 vim。

我一直想做但还没有找到方法的一件事是能够与 tmux 窗格交互,就好像它是 vim 缓冲区一样。我不知道这是否可能(?)。

基本上,我想要的是:

  • 1 在 tmux 中做一些工作
  • 2 使用 tmux 快捷方式
  • 3 现在我的 tmux 应该像 vim 一样工作,特别是能够导航、复制、粘贴

我可以使用 Ctrl-B + [ 来关闭 2) 和 3),这可以让我浏览我的 tmux 历史记录,但是:

  • 我无法使用通常的 vim 导航,我必须使用箭头
  • 我不能轻易地例如拉文本等

知道 1)这是否可行,2)如何做到?

Ham*_*cke 6

您可以进行一些调整,.tmux.conf让 vim 用户感觉 tmux 更自在。

导航

hjkl要像在 vim 中一样使用导航来切换 tmux 窗格,请将其添加到您的.tmux.conf

bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R
Run Code Online (Sandbox Code Playgroud)

With this, you can use e.g. Ctrl+b h to select the pane to the left.

Copy, Search, Select

tmux has a built-in vi-mode for copy mode. Enable it via

set-window-option -g mode-keys vi
Run Code Online (Sandbox Code Playgroud)

in your .tmux.conf.

Use Ctrl+b [ to enter copy mode. With vi mode enabled, you can now use hjkl-style navigation to move your cursor around, search forward and backward using / and ? respectively.

To make copying and pasting feel more at home, add these two lines to your .tmux.conf to enable v as a shortcut for text selection (similar to vi's visual mode) and y as a shortcut for copying/yanking selected text:

bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection
Run Code Online (Sandbox Code Playgroud)

You can use p to paste text, this is standard in vi mode in tmux.