我经常使用 tmux 和 vim。
我一直想做但还没有找到方法的一件事是能够与 tmux 窗格交互,就好像它是 vim 缓冲区一样。我不知道这是否可能(?)。
基本上,我想要的是:
我可以使用 Ctrl-B + [ 来关闭 2) 和 3),这可以让我浏览我的 tmux 历史记录,但是:
知道 1)这是否可行,2)如何做到?
您可以进行一些调整,.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.
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.