在 tmux 会话中使用 vim 时,我无法拉出或粘贴到未命名的寄存器。去一个命名的寄存器工作正常,但未命名的永远不会工作。
错误是:
E353: Nothing in register *
如果没有 tmux,vim 可以使用我当前的设置正常工作。如何修复它,以便我可以在没有错误且不指定寄存器的情况下使用ythen ?p
From the error message (Nothing in register *
), it appears that when you do a plain? p
, your instance of Vim is using the *
register instead of the unnamed register*. This is probably because your clipboard
option includes the value unnamed
. When configured this way, Vim will use the *
register instead of the unnamed register for yank, delete, change, and put operations by default (i.e. unless you specify another register with a "
prefix; e.g. "ap
to put from the a
register).
*The unnamed register is actually named "
(double quote). It is only “unnamed” in the sense that you do not have to name it to use it (it is the default). I.e. you do not have to say ""p
to put from the unnamed register, just p
.
The default value of clipboard
does not contain unnamed
, so it is probably coming from some bit of your configuration (or a plugin). The command :verbose set clipboard?
will show you the script that set the current value. If this is being done in your configuration file, then you might want to not do it when you are running under tmux. E.g:
if $TMUX == ''
set clipboard+=unnamed
endif
Alternatively, there may be some way to let instances of Vim-inside-tmux access the GUI selection/clipboard (thus work with the *
register and/or unnamed
in clipboard
). If you are running Mac OS X, you may want to look at my workaround wrapper that re-enables clipboard access for processes running inside a tmux session. If you are using some other OS or GUI, then you will need to find out how Vim would normally talk to the GUI and why it is not working (e.g. wrong DISPLAY value under X11, possibly due to attaching to an old session that is running a shell that has an out-of-date value).
这是在 vim/tmux/osx 中对我有用的:
brew install reattach-to-user-namespace
set clipboard=unnamed
set-option -g default-command "reattach-to-user-namespace -l bash"
fakeclip插件使剪贴板寄存器在许多终端中按预期运行,并支持 tmux/screen。你在用吗?它可能会解决您的问题。
同样,您可能对此提示感兴趣......它不适用于您的问题,但相关。根据您运行 tmux 的系统/终端类型,您可能需要在.tmux.conf
. 例如,这是我.tmux.conf
在 OS X 上的摘录(在评论中有一些说明):
# To use pbcopy and pbpaste on OS X, get this wrapper and install
# git clone https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard.git
# cd tmux-MacOSX-pasteboard/
# make reattach-to-user-namespace
# mv reattach-to-user-namespace /usr/local/bin
# After installing, the default command can be reset to use the 'reattach-to-user-namespace'
# wrapper that was compiled/installed as descripted above.
set -g default-command "reattach-to-user-namespace -l /bin/bash"
# #Next, create Ctrl-c and Ctrl-v mappings
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
bind C-v run "tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste-buffer"
将我在 OSX 上的经验添加到已接受的答案中:
set clipboard=unnamed
而不是set clipboard=unnamedplus
$ killall tmux
或$ tmux kill-session -a
)。重新加载 tmux 配置文件显示 default-command 已设置,但未授予 vim 访问系统剪贴板的权限。迟到的答案,但也可能是您.tmux.conf
包含以下行:
set -g set-clipboard off
结合一个.vimrc
包含
set clipboard=unnamed
这将导致 vim 尝试使用不存在的剪贴板。