修复Vim + Tmux yank/粘贴未命名的寄存器。

时间:2023-01-23 19:17:53

While using vim inside a tmux session I cannot yank or paste to the unnamed register. Going to a named register works fine, but unnamed never works.

在tmux会话中使用vim时,我不能删除或粘贴到未命名寄存器。去一个命名寄存器工作得很好,但是不命名从来都不行。

Error is:

错误:

E353: Nothing in register *

Without tmux, vim works fine using my current settings. How do I fix it so I can use y then p without errors and without specifying the register?

没有tmux, vim使用我的当前设置就可以正常工作。我如何修正它,使我可以使用y然后p没有错误,没有指定寄存器?

4 个解决方案

#1


95  

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).

从错误消息(在寄存器*中没有),当您做一个普通的时候,它会出现。p,您的Vim实例使用的是*寄存器,而不是未命名寄存器*。这可能是因为您的剪贴板选项包含未命名的值。当这样配置时,Vim将在默认情况下使用*寄存器,而不是未命名的寄存器来进行提取、删除、更改和放置操作(即,除非您指定另一个带有“前缀”的寄存器;如。“ap从a寄存器输入)。”

*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.

*未命名的寄存器实际上被命名为“(双引号)”。它只是“未命名”,因为使用它不需要命名(它是默认值)。也就是说,你不需要从未命名寄存器中输入p,只需输入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:

剪贴板的默认值不包含未命名的,因此它可能来自您的一些配置(或插件)。命令:详细设置剪贴板?将显示设置当前值的脚本。如果这是在配置文件中完成的,那么在tmux下运行时,您可能不希望这样做。例句:

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-inside-tmux的实例访问GUI选择/剪贴板(因此可以使用*寄存器和/或剪贴板中未命名的实例)。如果您正在运行Mac OS X,您可能想看看我的工作区包装器,它重新启用在tmux会话中运行的进程的剪贴板访问。如果您正在使用一些其他操作系统或GUI,然后你需要找出Vim通常会跟GUI和为什么它不工作(如错误的显示值在X11,可能由于附加一个旧会话运行shell的过时的值)。

#2


48  

Here is what works for me in vim/tmux/osx:

以下是在vim/tmux/osx中对我有效的方法:

  1. Install Homebrew
  2. 安装自酿酒
  3. Install reattach-to-user-namespace: brew install reattach-to-user-namespace
  4. 安装reattachto -user命名空间:brew安装reattachto -user命名空间
  5. in .vimrc: set clipboard=unnamed
  6. 在. vimrc:设置剪贴板=未具名
  7. Tell tmux to use the system clipboard: In .tmux.conf: set-option -g default-command "reattach-to-user-namespace -l bash"
  8. 告诉tmux使用system剪贴板:In .tmux。conf: set-option -g default-command“reattachto -user-namespace -l bash”

Source: https://coderwall.com/p/j9wnfw

来源:https://coderwall.com/p/j9wnfw

#3


4  

The fakeclip plugin makes the clipboard register behave as expected in many terminals and has support for tmux/screen. Are you using it? It may resolve your issue.

fakeclip插件使剪贴板寄存器在许多终端上的行为与预期一致,并支持tmux/screen。你使用它吗?它可能会解决你的问题。

As well, you may be interested in this tip... It's not applicable to your question, but related. Depending on what type of system/terminal you're running tmux in, you may need some tweaks in your .tmux.conf. For example here's an excerpt of my .tmux.conf on OS X (with some instructions in comments):

同样,你可能对这条建议感兴趣……这不适用于你的问题,但有关系。根据您运行tmux的系统/终端类型,您可能需要在.tmux.conf中进行一些调整。例如,这是我的。tmux的摘录。在OS X上的conf(在注释中有一些说明):

# 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"

#4


0  

Late answer, but it also might be that your .tmux.conf contains the following line:

迟到的回答,但也可能是你的。tmux。conf包含以下一行:

set -g set-clipboard off

设置- g set-clipboard掉

combined with a .vimrc containing

与含有.vimrc的

set clipboard=unnamed

设置剪贴板=不知名的

this will lead to vim trying to use a clipboard that is not there.

这将导致vim尝试使用不存在的剪贴板。

#1


95  

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).

从错误消息(在寄存器*中没有),当您做一个普通的时候,它会出现。p,您的Vim实例使用的是*寄存器,而不是未命名寄存器*。这可能是因为您的剪贴板选项包含未命名的值。当这样配置时,Vim将在默认情况下使用*寄存器,而不是未命名的寄存器来进行提取、删除、更改和放置操作(即,除非您指定另一个带有“前缀”的寄存器;如。“ap从a寄存器输入)。”

*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.

*未命名的寄存器实际上被命名为“(双引号)”。它只是“未命名”,因为使用它不需要命名(它是默认值)。也就是说,你不需要从未命名寄存器中输入p,只需输入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:

剪贴板的默认值不包含未命名的,因此它可能来自您的一些配置(或插件)。命令:详细设置剪贴板?将显示设置当前值的脚本。如果这是在配置文件中完成的,那么在tmux下运行时,您可能不希望这样做。例句:

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-inside-tmux的实例访问GUI选择/剪贴板(因此可以使用*寄存器和/或剪贴板中未命名的实例)。如果您正在运行Mac OS X,您可能想看看我的工作区包装器,它重新启用在tmux会话中运行的进程的剪贴板访问。如果您正在使用一些其他操作系统或GUI,然后你需要找出Vim通常会跟GUI和为什么它不工作(如错误的显示值在X11,可能由于附加一个旧会话运行shell的过时的值)。

#2


48  

Here is what works for me in vim/tmux/osx:

以下是在vim/tmux/osx中对我有效的方法:

  1. Install Homebrew
  2. 安装自酿酒
  3. Install reattach-to-user-namespace: brew install reattach-to-user-namespace
  4. 安装reattachto -user命名空间:brew安装reattachto -user命名空间
  5. in .vimrc: set clipboard=unnamed
  6. 在. vimrc:设置剪贴板=未具名
  7. Tell tmux to use the system clipboard: In .tmux.conf: set-option -g default-command "reattach-to-user-namespace -l bash"
  8. 告诉tmux使用system剪贴板:In .tmux。conf: set-option -g default-command“reattachto -user-namespace -l bash”

Source: https://coderwall.com/p/j9wnfw

来源:https://coderwall.com/p/j9wnfw

#3


4  

The fakeclip plugin makes the clipboard register behave as expected in many terminals and has support for tmux/screen. Are you using it? It may resolve your issue.

fakeclip插件使剪贴板寄存器在许多终端上的行为与预期一致,并支持tmux/screen。你使用它吗?它可能会解决你的问题。

As well, you may be interested in this tip... It's not applicable to your question, but related. Depending on what type of system/terminal you're running tmux in, you may need some tweaks in your .tmux.conf. For example here's an excerpt of my .tmux.conf on OS X (with some instructions in comments):

同样,你可能对这条建议感兴趣……这不适用于你的问题,但有关系。根据您运行tmux的系统/终端类型,您可能需要在.tmux.conf中进行一些调整。例如,这是我的。tmux的摘录。在OS X上的conf(在注释中有一些说明):

# 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"

#4


0  

Late answer, but it also might be that your .tmux.conf contains the following line:

迟到的回答,但也可能是你的。tmux。conf包含以下一行:

set -g set-clipboard off

设置- g set-clipboard掉

combined with a .vimrc containing

与含有.vimrc的

set clipboard=unnamed

设置剪贴板=不知名的

this will lead to vim trying to use a clipboard that is not there.

这将导致vim尝试使用不存在的剪贴板。