https://stackoverflow.com/questions/10101488/cut-to-the-system-clipboard-from-vim-on-ubuntu
Your version of Vim doesn’t support X, which is required for clipboard access. By default, Ubuntu ships several builds of vim and only the GUI variant supports clipboard access. 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). It’s really very easy to do:
git clone 有时候需要翻墙
# Get the compile-dependencies of vim
sudo apt-get -y build-dep vim
# Install python dev
sudo apt-get -y install python-dev
# Install xorg dev
sudo apt-get -y install xorg-dev
# Install git
sudo apt-get -y install git
# Get the source
git clone https://github.com/vim/vim.git vim_source
# Remove ./configure cache in case we have to run this twice due to permissions
# related issues.
rm vim_source/src/auto/config.cache
# Compile it
cd vim_source
make clean
./configure \
--enable-perlinterp=dynamic \
--enable-pythoninterp=dynamic \
--enable-rubyinterp=dynamic \
--enable-cscope \
--enable-gui=auto \
--enable-gtk2-check \
--enable-gnome-check \
--with-features=normal \
--with-x \
--with-compiledby="DevNull <darkstar@/dev/null>" \
--with-python-config-dir=/usr/lib/python2.7/config-$(uname -m)-linux-gnu
# Build quickly (8 parallel jobs, hope your system doesn't get overwhelmed)
make -j8
# Need root to install
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.
You’ll end up with two vim’s: /usr/bin/vim and /usr/local/bin/vim. You can always run the old one with the explicit path. I’m not sure what you think is likely to be broken though: you can compile in any features that you need, but this configure script puts most stuff in. See ./configure –help for more options.
I should clarify my comment: you’ll also end up with two gvims: /usr/bin/gvim (from vim-gtk) and /usr/local/bin/gvim (a symlink to /usr/local/bin/vim that will open in GUI mode by default rather than the one names ‘vim’ that will open in console mode). It will support clipboards whether or not you’re in GUI mode (and even do so over ssh if you ssh -X with an X-server on the ssh client machine).