当我从tmux会话中运行Vim并将一些文本复制到剪贴板时,每行都会在右边填充空格.
例如,假设我有一个这样的文本文件:
^some$ ^text$
注意:我已经使用^和$分别标记一行的开头和结尾.它们不是文件内容的一部分.
我启动tmux并在Vim中打开此文件.我按Shift键(阻止Vim处理鼠标点击)并按住鼠标左键标记完整文本.然后我用Shift Ctrl c将它复制到剪贴板.
剪贴板中的结果如下:
^some $ ^text $
注意额外的空格.空格数取决于终端宽度.
如果我在没有tmux的情况下启动Vim,或者如果我只是捕获文件内容然后复制它,则没有多余空格.所以它必须与Vim tmux的组合有关.我在不同的Linux风格上看到了这一点,即在Ubuntu和Mint上.我在那里使用默认终端(Gnome Terminal 3.6.2).
那我怎么能阻止这个呢?
编辑:我的tmux.conf
set-option -g prefix C-a set-option -g mouse-utf8 off set-option -g status-keys vi set-window-option -g mode-keys vi set-window-option -g mode-mouse on set-option -g terminal-overrides 'xterm*:smcup@:rmcup@' bind-key C-a last-window bind-key C-h select-pane -L bind-key C-l select-pane -R # colors: set-option -g status-bg black set-option -g status-fg white set-option -g status-left '#[fg=green]#H' set-window-option -g window-status-current-bg red
编辑2:我也试过没有上面的.tmux.conf,使用tmux’默认设置 – 没有区别.
解决方法
嗯,我找到了一个解决方法,将屏幕上的TERM更改为xterm:
TERM=xterm vim
或者在/ .tmux.conf中使用以下内容
set -g default-terminal “xterm”
上面我在GNOME终端的本地shell和SecureCRT的远程shell中进行了测试.
如果这仍然不起作用,也许你可以检查你的/ .vimrc或其他全局设置中没有“set t_ut =”,因为我发现这打破了我的解决方法.
但是在“man tmux”中,它说
“The TERM environment variable must be set to “screen” for all programs running inside tmux. New windows will automatically have “TERM=screen” added to their environment,but care must be taken not to reset this in shell start-up files.”
和
“Set the default terminal for new windows created in this session – the default value of the TERM environment variable. For tmux to work correctly,this must be set to ‘screen’ or a derivative of it.”
我不知道这个的副作用.