在不同的Mac终端之间通过键盘复制并粘贴vim?

发布于 2024-12-15 18:04:38 字数 326 浏览 5 评论 0原文

谁能帮我解决这个问题: 我试图弄清楚如何在不同终端上的两个不同的 vim 实例之间复制和粘贴文本(使用 iterm2 或 mac 终端)。如果我执行“:set mouse = a”,我可以使用鼠标来完成此操作,但我希望能够使用键盘来完成此操作。

我用谷歌搜索了一下,它说你可以使用“*”或“+”寄存器从系统剪贴板复制/粘贴,但是当我在 vim 中输入 * 或 + 时,mac 会发出以下声音之一:不能做某事。我也做了“:set Clipboard = unnamed”,但这也不起作用。

我使用的是 Mac OSX 10.7 (Lion) 和 iTerm2 或 Mac 终端。

感谢您的帮助

Can anyone help me with this:
I'm trying to figure out how to copy and paste text between 2 different instances of vim on different terminals (using iterm2 or mac terminal). I can do it using the mouse if I do ":set mouse=a" but I'd like to be able to do it using the keyboard.

I've googled around and it says you can use the "* or "+ registers to copy/paste to/from the system clipboard, but when I type * or + in vim, the mac makes one of those sounds it makes when you can't do something. I've also done ":set clipboard=unnamed" but that hasn't worked either.

I'm using Mac OSX 10.7 (Lion) and iTerm2 or Mac terminal.

Thanks for the help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

左耳近心 2024-12-22 18:04:38

您可以添加 :version 的输出吗?

我可以在 Terminal.app 窗口 A 中运行的一个 Vim 实例中使用 yyy 进行拉取,然后使用 pP 在 Terminal.app 窗口 B 中运行的另一个 Vim 实例中,在我的 ~/.vimrc 中使用此行:

set clipboard+=unnamed

不使用特定的剪贴板寄存器(*+< /代码>)。

为什么有两个 Vim 实例在不同的终端中运行? SSH/本地?如果一台计算机处于 SSH 会话中,则拉取/放置将不起作用,因为两台计算机(本地/远程)不共享相同的剪贴板。

编辑

我怀疑 Vim 没有使用正确的标志进行编译。显然是这样的。

由于您使用的是 Mac OS X 的默认 Vim,我的观点是您不需要重新编译它,甚至不需要编译任何东西,因为它通常会导致比其价值更多的问题。

相反,下载最新的 MacVim 版本并使用 MacVim 捆绑包中的 (CLI) Vim 可执行文件:它具有与 MacVim 相同的功能(当然,在 CLI 的限制内)。

将此行添加到您的 ~/.bashrc~/.profile 或您用来放置别名和自定义 bash 函数的任何位置:

alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'

Could you add the output of :version?

I can yank with yy or y in one Vim instance running in Terminal.app window A and put with p or P in another Vim instance running in Terminal.app window B with this line in my ~/.vimrc:

set clipboard+=unnamed

without using specific clipboard registers (* or +).

And why do you have two Vim instances running in different terminals? SSH/local? If one is in an SSH session yanking/putting won't work because the two machines (local/remote) don't share the same clipboard(s).

EDIT

I suspected that Vim wasn't compiled with the right flag(s). Apparently that's the case.

Since you are using Mac OS X's default Vim my opinion is that you shouldn't need to re-compile it or even compile anything as it often leads to more problem's than it's worth.

Instead, download the latest MacVim build and use the (CLI) Vim executable within MacVim's bundle: it has all the same functionalities as MacVim (within the constraints of the CLI, of course).

Add this line to your ~/.bashrc or ~/.profile or wherever you are used to put aliases and custom bash functions:

alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'
泪眸﹌ 2024-12-22 18:04:38

如果您想将整个文件复制到目标文件中。

在 vim 中打开目标文件。

将光标放在您想要的位置并键入以下内容:

:r /p​​ath_to_file/file.ext

这会将整个文件复制到光标所在的位置...

If you want to copy an entire file into your target file.

Open your target file in vim.

Put your cursor where you want it and type the following:

:r /path_to_file/file.ext

This will copy an entire file to where your cursor is...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文