[英]Cut to the system clipboard from Vim on Ubuntu
I am using Ubuntu 12.04 Beta and Vim that has come with it.我正在使用它附带的 Ubuntu 12.04 Beta 和 Vim。 I am trying to use Vim to copy the content of a text file to Chrome browser.我正在尝试使用 Vim 将文本文件的内容复制到 Chrome 浏览器。 I have tried +
, *
y
and all its variants.我已经尝试过+
、 *
y
及其所有变体。 I have tried to :set clipboard=unnamed
and :set clipboard=unnamedplus
.我试过:set clipboard=unnamed
和:set clipboard=unnamedplus
。 Not working.不工作。 I am not trying to use xclip, or GVim or any of that.我没有尝试使用 xclip、GVim 或其中任何一个。 I tried with xclip (not a standard package in Ubuntu 12.04), but that too does not work, also too much effort.我尝试使用 xclip(不是 Ubuntu 12.04 中的标准 package),但这也行不通,也太费力了。
How do I copy the text to the clipboard and then paste anywhere, like Chrome?如何将文本复制到剪贴板,然后粘贴到任何地方,例如 Chrome?
Your version of Vim doesn't support X, which is required for clipboard access.您的 Vim 版本不支持 X,而 X 是访问剪贴板所必需的。 By default, Ubuntu ships several builds of vim and only the GUI variant supports clipboard access.默认情况下,Ubuntu 发布了 vim 的几个版本,只有 GUI 变体支持剪贴板访问。 I always recompile vim from source so that a single vim (with symlinks for gvim etc) supports everything required (including :gui
to switch from command line to GUI version).我总是从源代码重新编译 vim,以便单个 vim(带有 gvim 等的符号链接)支持所需的一切(包括:gui
从命令行切换到 GUI 版本)。 It's really very easy to do:这真的很容易做到:
# Get the compile-dependencies of vim
sudo apt-get build-dep vim
# If you haven't got mercurial, get it
sudo apt-get install mercurial
# Get the source
hg clone https://vim.googlecode.com/hg/ vim_source
# Compile it
cd vim_source
./configure \
--enable-perlinterp=dynamic \
--enable-pythoninterp=dynamic \
--enable-rubyinterp=dynamic \
--enable-cscope \
--enable-gui=auto \
--enable-gtk2-check \
--enable-gnome-check \
--with-features=huge \
--with-x \
--with-compiledby="Your Name <youremail@domain.com>" \
--with-python-config-dir=/usr/lib/python2.7/config
make && sudo make install
That will install it in /usr/local
, so make sure that's in your PATH
before /usr
and it will be used instead of the Ubuntu versions.这会将它安装在/usr/local
中,因此请确保它位于 / /usr
之前的PATH
中,并且将使用它而不是 Ubuntu 版本。
The output from vim --version
should show something like this:来自vim --version
的 output 应该显示如下内容:
Huge version with GTK2-GNOME GUI. Features included (+) or not (-):
and further down in the output you should see stuff like +Xll:在 output 的更下方,您应该会看到类似 +Xll 的内容:
+vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset +xim
+xsmp_interact +xterm_clipboard -xterm_save
That means your console vim can copy/paste to/from the X11 clipboard.这意味着您的控制台 vim 可以从 X11 剪贴板复制/粘贴。
Try apt-get install vim-gtk
试试apt-get install vim-gtk
Install the package vim-gnome
instead of vim
.安装 package vim-gnome
而不是vim
。 It comes with clipboard
enabled.它带有启用的clipboard
。
You can also add shortcuts to your vimrc你也可以给你的 vimrc 添加快捷方式
# Copy and paste
vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa
It will allow you to Copy by Ctrl + C and Paste by Ctrl + V它将允许您通过Ctrl + C复制并通过Ctrl + V粘贴
If you have run configure
as explained by @DrAl but you still can't get the GUI compiled in and you see this in the output of your ./configure
如果您按照@DrAl 的说明运行了configure
,但仍然无法编译 GUI,您会在./configure
的 output 中看到它
checking for X... (cached) no
Then you may have to delete the cache file that configure
created.然后您可能必须删除configure
创建的缓存文件。
find . -name config.cache -delete
Then re-run configure
and make
and check src/vim --version
again - it should show that gui is included now.然后重新运行configure
和make
并再次检查src/vim --version
- 它应该显示现在包含了 gui。
You can do it;你能行的; just pipe to xclip.只是 pipe 到 xclip。
gg
V
G
:'<,'>w !xclip
from here: in vim with xclip, yank to clipboard从这里开始: 在 vim 中使用 xclip,拉到剪贴板
I would open the file in the browser using a file URL:我将使用文件 URL 在浏览器中打开文件:
file:///home/dave/some-file
Not super elegant but it works.不是超级优雅,但它有效。
I really enjoy this set of shortcuts:我真的很喜欢这组快捷方式:
" Add shortcut for clipboard registers
noremap <leader>p "*p
noremap <leader>y "+y
noremap <leader>d "+d
It is just an easier way then type "* and "+ every time.这只是一种比每次都输入“*”和“+”更简单的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.