如何将vi中的代码复制到剪贴板

发布于 2024-10-30 13:54:06 字数 162 浏览 4 评论 0原文

我知道如何在VI中复制。但我未能将其复制到其他应用程序中。这意味着我未能将它们复制到剪贴板中。 我该怎么做?

PS为了更精益。我还想问如何将剪贴板中的内容复制到vi。

编辑: 我正在使用 MacO。运行 Vim。

看来 *yy 在这里不起作用。还有其他办法吗?

I know how to copy in VI. but I failed to copy it into other application. That means I failed copy those into clipboard.
How can I do this?

P.S. In order to lean more. I also want to ask how to copy content from clipboard to vi.

Edited:
I am using MacOs. running Vim.

It seems *yy doesn't work here. Any other ways?

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

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

发布评论

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

评论(4

孤蝉 2024-11-06 13:54:06

您需要使用剪贴板寄存器,即*,因此要将一行文本复制到剪贴板中:

"*yy

从剪贴板粘贴一行文本:

 "*p

You need to use the clipboard register, which is *, so to copy a line of text into clipboard:

"*yy

To paste a line of text from the clipboard:

 "*p
安静 2024-11-06 13:54:06

仅当您的 vim 支持 xterm_clipboard 时,"+y"*y 才有效。 Xterm 是 X11 的终端模拟器。尝试 vim --version 看看是否支持。如果您看到+xterm_clipboard,它应该可以工作,如果您看到-xterm_clipboard,它就不会。现在有许多 Linux 版本在其存储库中仍然禁用 xterm_clipboard 支持。通过剪贴板进行拉动是不可能的。请注意,您仍然可以使用老式的 Unix 风格的拉取/粘贴,即选择要拉取的文本,然后在要粘贴的位置单击鼠标中键。这应该始终有效,并且是 vim 中拉取/粘贴的首选方式。确保处于插入模式并输入 set Paste(如果它搞乱了缩进)。 设置 nopaste 以离开粘贴模式。

要使用 xterm_clipboard 获取 vim,只需下载源代码,创建 ./configure --with-x,然后创建 make。现在 vim 应该支持 xterm_clipboard 并且从剪贴板中拖拽和粘贴也应该可以完美地工作。

"+y or "*y works only if your vim supports the xterm_clipboard. Xterm is a terminal emulator for X11. Try vim --version to see if it is supported. If you see +xterm_clipboard it should work, if you see -xterm_clipboard it won't. Now there are many Linux flavours which still have the xterm_clipboard support deactivated in their repositories. Yanking via clipboard is then impossible. Note that you still have the good old unix style of yank/paste, namely select the text you'd like to yank and middle-click on the mouse where you want to paste. This should work always and is the preferred style of yank/paste in vim. Be sure to be in insert mode and type set paste if it screws up the indentation. set nopaste to leave paste mode.

To get vim with xterm_clipboard, simply download the source, make a ./configure --with-x and then a make. Now vim should support xterm_clipboard and yanking and pasting should work flawlessly also from the clipboard.

海之角 2024-11-06 13:54:06
"+yy or "*yy to copy to clipboard
"+p or "*p to paste from clipboard

" 会将其放入 + 寄存器中。

甚至比您想知道的还要多:
http://vim.wikia.com/wiki/Accessing_the_system_clipboard

"+yy or "*yy to copy to clipboard
"+p or "*p to paste from clipboard

The " will put it into the + register.

For even more than you wanted to know:
http://vim.wikia.com/wiki/Accessing_the_system_clipboard

仅冇旳回忆 2024-11-06 13:54:06

vi 的复制是在 vi 自己的内部剪贴板中完成的,因为它源自 unix 命令行,而 windows 风格的剪贴板不存在。后来出现了命令行的鼠标指针,这意味着您可以使用它作为更像 Windows 样式进行复制,但如果您想从 vi 复制到 Windows 剪贴板,则需要使用 *yy 和 *p,而不是 yy 和 p vi 中的内部剪贴板(这也是为什么拉动和粘贴不会影响您的 Windows 剪贴板)

The copy of vi is done within vi's own internal clipboard, as its descended from the unix command line where the windows style clipboard didnt exist. Later came the mouse pointer for command line which meant you could copy using that as a more like windows style, but if you want to copy from vi to windows clipboard, you need to use *yy and *p, not yy and p which are the internal clipboard within vi (which is also why yanking and pasting dont effect your windows clipboard)

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