无法粘贴到MacVim [英] Can't paste into MacVim

查看:121
本文介绍了无法粘贴到MacVim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Vim外部复制文本. otherV在其他应用程序中粘贴文本不会出现问题.在MacVim中,它不起作用.

I copy text from outside of Vim. ⌘V in other apps pastes text without problem. In MacVim, it doesn't work.

在插入模式下,什么都不会出现.在正常模式下,我得到E353: Nothing in register +.当set clipboard=unnamed打开或关闭时会发生这种情况.

In Insert Mode, nothing appears. In Normal Mode, I get E353: Nothing in register +. This happens when set clipboard=unnamed is on or off.

奇怪的是,这以前是可行的.怎么了?

Oddly enough, this was working before. What's wrong?

推荐答案

如果您使用的是 tmux ,有时您最初是通过mvim命令行启动 MacVim 程序,那么您可能会遇到促使我编写 reattach-to-user-namespace命令的问题.

If you are using tmux and sometimes you initially launch MacVim via the mvim command-line program, then you might be encountering the problem that prompted me to write the reattach-to-user-namespace command.

我的猜测是剪贴板访问是在以前的情况下起作用的,因为您碰巧通过常规" GUI方法(例如,扩展坞, Finder ,Spotlight,等等.).在您退出 MacVim 的先前实例并从 tmux 会话内部通过(例如)mvim重新启动后,剪贴板随后变得不可访问.

My guess is that clipboard access worked on prior occasions because you happened to have launched MacVim via a "normal" GUI method (e.g. the dock, Finder, Spotlight, etc.). The clipboard later became inaccessible after you had quit the prior instance of MacVim and relaunched it through (e.g.) mvim from inside a tmux session.

核心问题是,在某些情况下(即在 tmux 会话中)启动的程序最终会导致拒绝访问某些服务(例如OS X粘贴板)的环境.

The core problem is that programs launched in certain contexts (i.e. inside a tmux session) end up with an environment that denies them access to certain services (e.g. the OS X pasteboard).

初始启动在这里很重要.只要 MacVim 以前是通过通过"启动的,则由mvim -in- tmux 启动的新窗口(即使没有上述链接的包装程序)也应该可以访问剪贴板. GUI"(也许仍有一些 MacVim 窗口打开,或者即使没有打开任何窗口,您也已将 MacVim 配置为保持运行).相应地,要重新获得对剪贴板的访问权限,您需要关闭所有现有的 MacVim 窗口,退出应用程序,然后以可以访问剪贴板的方式重新启动它(例如,通过GUI或在包装纸"内.

The initial launch is the important one here. New windows started by mvim-in-tmux (even without the above-linked wrapper program) should have access to the clipboard as long as MacVim was previously started "via the GUI" (maybe there are still some MacVim windows open, or maybe you have MacVim configured to keep running even when there are no windows open). Correspondingly, to regain access to the clipboard you will need to close all your existing MacVim windows, quit the application, then restart it in a way that has access to the clipboard (e.g. via the GUI, or "inside" the wrapper).

一旦安装了上述链接的包装程序(也可以通过MacPorts和Homebrew获得),则可以使用reattach-to-user-namespace mvim之类的命令来确保 if 最终启动一个新的包装程序. MacVim 实例,那么该新实例将可以访问剪贴板.您可以使用别名,shell函数或脚本来确保始终总是``包装''mvim.

Once you have the above-linked wrapper program installed (it is also available through MacPorts and Homebrew), you can use a command like reattach-to-user-namespace mvim to ensure that if it ends up starting a new MacVim instance, then that new instance will have access to the clipboard. You might use an alias, shell function, or a script to make sure you always "wrap" mvim.

包装"(pbpastepbcopynohuplaunchctl(取决于您使用的是哪个子命令))也可以使其他几个命令受益,因此您可能需要包装"整个外壳而不是单个命令. 包装器"所修改的过程环境中的一部分是由子进程继承的,因此包装"您的外壳将影响您从其运行的大多数命令.如果您使用的是 tmux ,则可以将default-command配置为自动包装"默认的 tmux shell:

Several other commands also benefit from "wrapping" (pbpaste, pbcopy, nohup, launchctl (depending on which subcommand you are using)), so you may want to "wrap" your whole shell instead of the individual commands. The bit of the process environment that the "wrapper" modifies is inherited by child processes, so "wrapping" your shell will affect most commands you run from it. If you are using tmux, you could configure your default-command to automatically "wrap" your default tmux shells:

set-option -g default-command "reattach-to-user-namespace -l zsh"

这篇关于无法粘贴到MacVim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆