macos 在不同的 mac 终端之间通过键盘在 vim 中复制和粘贴?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8134647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy and paste in vim via keyboard between different mac terminals?
提问by Eddy
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.
谁能帮我解决这个问题:我想弄清楚如何在不同终端(使用 iterm2 或 mac 终端)上的 2 个不同 vim 实例之间复制和粘贴文本。如果我执行 ":set mouse=a",我可以使用鼠标来完成,但我希望能够使用键盘来完成。
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.
我搜索了一下,它说您可以使用“*”或“+”寄存器从系统剪贴板复制/粘贴到/从系统剪贴板中复制/粘贴,但是当我在 vim 中键入 * 或 + 时,mac 会发出其中一种声音不能做某事。我也做过 ":set clipboard=unnamed" 但这也没有用。
I'm using Mac OSX 10.7 (Lion) and iTerm2 or Mac terminal.
我使用的是 Mac OSX 10.7 (Lion) 和 iTerm2 或 Mac 终端。
Thanks for the help
谢谢您的帮助
采纳答案by romainl
Could you add the output of :version
?
你能添加输出: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
:
我可以使用在 Terminal.app 窗口 A 中运行的一个 Vim 实例yy
或y
在其中使用p
或P
放入另一个 Vim 实例中,或者在 Terminal.app 窗口 B 中运行的另一个 Vim 实例中,在我的以下行中~/.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).
为什么你有两个 Vim 实例在不同的终端上运行?SSH/本地?如果在 SSH 会话中,则 yanking/putting 将不起作用,因为两台机器(本地/远程)不共享相同的剪贴板。
EDIT
编辑
I suspected that Vim wasn't compiled with the right flag(s). Apparently that's the case.
我怀疑 Vim 没有使用正确的标志编译。显然是这样。
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.
由于您使用的是 Mac OS X 的默认 Vim,我的观点是您不需要重新编译它甚至编译任何东西,因为它通常会导致更多的问题而不是它的价值。
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).
相反,下载最新的 MacVim 版本并使用 MacVim 包中的 (CLI) Vim 可执行文件:它具有与 MacVim 相同的所有功能(当然在 CLI 的限制范围内)。
Add this line to your ~/.bashrc
or ~/.profile
or wherever you are used to put aliases and custom bash functions:
将此行添加到您~/.bashrc
或~/.profile
您用于放置别名和自定义 bash 函数的任何地方:
alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'
回答by DeWayne Whitaker
If you want to copy an entire file into your target file.
如果要将整个文件复制到目标文件中。
Open your target file in vim.
在 vim 中打开目标文件。
Put your cursor where you want it and type the following:
将光标放在您想要的位置并键入以下内容:
:r /path_to_file/file.ext
:r /path_to_file/file.ext
This will copy an entire file to where your cursor is...
这会将整个文件复制到光标所在的位置...