Mer*_*ial 3 tmux clipboard vi-mode
我是使用 Tmux 的新手。我发现在 Tmux 中复制粘贴非常困难。所以我寻找一种更简单的方法。有些网站建议我应该使用 vim 模式,因为我对 vim 非常熟悉。但是,vim 模式复制粘贴不起作用。我不知道我做错了什么。这是我的 ~/.tmux.conf 文件。
# Improve colors
set -g default-terminal 'screen-256color'
# Set scrollback buffer to 10000
set -g history-limit 10000
# Customize the status line
set -g status-fg green
set -g status-bg black
set -g mouse on
bind P paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
# remap prefix to Control + a
set -g prefix M-a
# bind 'C-a C-a' to type 'C-a'
bind M-a send-prefix
unbind C-b
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'
set -g @plugin 'jimeh/tmux-themepack'
set -g @themepack 'powerline/block/blue'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'
Run Code Online (Sandbox Code Playgroud)
我正在使用 Tmux 2.5。预先感谢您的帮助。
确保setw -g mode-keys vi你的conf文件中有
正如您所看到的,您的猛拉(也被发送到剪贴板)正在使用外部命令:xclip。因此,请确保安装了 xclip 或使用此脚本安装它。
确保使用 进入复制模式C-b [,然后v开始选择,然后y猛拉,最后C-b ]退出复制模式。
不确定这是否有什么不同,但你可以尝试:
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'r' send -X rectangle-toggle
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel
Run Code Online (Sandbox Code Playgroud)
您还可以通过在变量中捕获 tmux 版本并使用一些 if 语句来使 .tmux.conf 在版本之间更可移植。我个人有以下 .tmux.conf ,到目前为止对于不同版本都运行良好(虽然从未使用过 2.5),我还从不同来源缝合了它,所以我不能 100% 确定版本条件对于每个版本都确实如此:
#check version and put in variable
run-shell 'tmux setenv -g TMUX_VERSION $(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
setw -g mode-keys vi
if-shell -b '[ "$(echo "$TMUX_VERSION < 2.4" | bc)" = 1 ]' " \
bind-key -t vi-copy v begin-selection; \
bind-key -t vi-copy r rectangle-toggle; \
bind-key -t vi-copy y copy-pipe 'xclip -selection clipboard -in'"
#You would have to adapt here by changing ">" to ">="
#and maybe changing the key binding by what you
#already have if what you have indeed worked after
#checking the points I gave you earlier.
if-shell -b '[ "$(echo "$TMUX_VERSION > 2.5" | bc)" = 1 ]' " \
bind-key -T copy-mode-vi 'v' send -X begin-selection; \
bind-key -T copy-mode-vi 'r' send -X rectangle-toggle; \
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel 'xclip -selection clipboard -in'"
Run Code Online (Sandbox Code Playgroud)
如果有人可以检查/共享一个完全可移植的 vim .tmux.conf(例如带有 xclip 支持的复制/粘贴),这可能会对每个人都有帮助。