macos 如何将选择复制到 OS X 剪贴板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/677986/
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
How to copy a selection to the OS X clipboard
提问by ???u
I have an area selected in Vim. How can I copy it into the OS X clipboard?
我在 Vim 中选择了一个区域。如何将其复制到 OS X 剪贴板中?
(The OS X clipboard can be written to via a pipe to /usr/bin/pbcopy
)
(OS X 剪贴板可以通过管道写入到/usr/bin/pbcopy
)
采纳答案by Chris AtLee
Depending on which version of Vim I use, I'm able to use the +
register to access the clipboard.
根据我使用的 Vim 版本,我可以使用+
寄存器访问剪贴板。
"Mac OS X clipboard sharing" may have some ideas that work for you as well.
“ Mac OS X 剪贴板共享”可能也有一些适合您的想法。
回答by George V. Reilly
回答by rampion
If the clipboard is enabled, you can copy a selected region to the clipboard by hitting "*y
如果启用了剪贴板,您可以通过点击将选定区域复制到剪贴板 "*y
To see if it is enabled, run vim --version
and look for +clipboard
or -clipboard
. For example, it's not enabled by default on my 10.5.6 box:
要查看它是否已启用,请运行vim --version
并查找+clipboard
或-clipboard
。例如,它在我的 10.5.6 盒子上默认没有启用:
% which vim /usr/bin/vim % vim --version VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Nov 11 2008 17:20:43) Included patches: 1-22 Compiled by [email protected] Normal version without GUI. Features included (+) or not (-): ... -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments ...
If it had been compiled with +clipboard
, I'd be able to use the "*
register to access the system clipboard.
如果它是用 编译的+clipboard
,我就可以使用"*
寄存器来访问系统剪贴板。
I downloaded the 7.2 sourceand compiled it (easy as tar xjf vim-7.2.tar.bz && cd vim72 && ./configure && make && sudo make install
), and the clipboard was enabled:
我下载了7.2 源代码并编译它(简单如tar xjf vim-7.2.tar.bz && cd vim72 && ./configure && make && sudo make install
),并且启用了剪贴板:
% which vim /usr/local/bin/vim % vim --version VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Mar 24 2009 17:31:52) Compiled by [email protected] Normal version with GTK2 GUI. Features included (+) or not (-): ... +clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments ...
However, even after compiling, I couldn't copy to the clipboard when running vim in Terminal.app, only in X11.app.
但是,即使在编译后,我在 Terminal.app 中运行 vim 时也无法复制到剪贴板,只能在 X11.app 中。
回答by user242065
You can visually select text and type :w !pbcopy<CR>
您可以直观地选择文本并键入 :w !pbcopy<CR>
Or you can include the below key mappings in your ~/.vimrc
file. They cut/copy text in visual mode to the operating system's clipboard.
或者您可以在您的~/.vimrc
文件中包含以下键映射。它们以可视模式将文本剪切/复制到操作系统的剪贴板。
vmap <C-x> :!pbcopy<CR>
vmap <C-c> :w !pbcopy<CR><CR>
回答by Paul Tomblin
double-quote asterisk ("*) before any yank command will yank the results into the copy buffer. That works for Windows and Linux too.
"*任何 yank 命令之前的双引号星号 ( ) 会将结果拉入复制缓冲区。这也适用于 Windows 和 Linux。
回答by nikola
On macos 10.8, vim is compiled with -clipboard
so to use "*y
you'll need to
recompile. Luckily brew install vim
would compile a new version easily for you
and it will be +clipboard
.
在 macos 10.8 上,vim 是用编译的,-clipboard
所以要使用"*y
你需要重新编译。幸运的是brew install vim
会为您轻松编译一个新版本,它将是+clipboard
.
回答by James Scriven
Visually select the text and type:
目视选择文本并键入:
ggVG
!tee >(pbcopy)
Which I find nicer than:
我觉得比以下更好:
ggVG
:w !pbcopy
Since it doesn't flash up a prompt: "Press ENTER or type command to continue"
由于它没有出现提示:“按 ENTER 或输入命令继续”
回答by Matt Hughes
If you are using MacPorts you can upgrade your VIM to include clipboard support via:
如果您使用的是 MacPorts,您可以通过以下方式升级您的 VIM 以包含剪贴板支持:
port install vim +x +x11
Now you use the "+
register to yank your text directly to your Mac clipboard. Works like a charm.
现在,您可以使用"+
寄存器将文本直接拖到 Mac 剪贴板中。奇迹般有效。
回答by Telmo Dias
In my case I just had to do :
就我而言,我只需要这样做:
:set mouse=v
回答by Jose Alban
If you are on MacOS X:
如果您使用的是 MacOS X:
$ brew install vim
$ vim --version
VIM - Vi IMproved 7.4 [...]
Then, add to your .vimrc:
然后,添加到您的 .vimrc:
set clipboard=unnamed
Now you just need to be in vimand do :%y
, to have all the content copied to your clipboard.
现在您只需要在vim 中执行操作:%y
,即可将所有内容复制到剪贴板。