Jump to content

VIM-edition in terminal with support for clipboard

Go to solution Solved by Claryn,

I fixed this by installing vim-gtk. I thought my /usr/bin/vim would be untouched, and that I had to run gvim in order to have +clipboard and +xterm_clipboard... When gvim is installed, /usr/bin/vim has +clipbard and +xterm_clipboard, and you can still run it in the terminal with the vim-command.

 

Awesome. 

Hi.

 

I am running KDE Neon (Ubuntu 16.04) and the preinstalled version of vim (just vim). Sadly, it does not support yank/copy to/from system clipboard. I want a version of vim that does support it. 

I also want to run VIM in the terminal, so gvim is not an option. I have looked at neo-vim, but unsure if it is something to consider? It also grabs the .vim/ folder and .vimrc file from other paths. Is it possibe to change that???

Running Arch with i3-gaps on a Thinkpad X1 Extreme
Data Science Postgrad

 

Link to comment
Share on other sites

Link to post
Share on other sites

https://vi.stackexchange.com/questions/84/how-can-i-copy-text-to-the-system-clipboard-from-vim

 

Quote

For X11-based systems (ie. Linux and most other UNIX-like systems) there are two clipboards which are independent of each other:

  • PRIMARY - This is copy-on-select, and can be pasted with the middle mouse button.
  • CLIPBOARD - This is copied with (usually) ^C, and pasted with ^V (It's like MS Windows).

OS X and Windows systems only have 1 clipboard.

For X11 systems there are also number of tools that synchronize these clipboards for you; so if they appear to be the same, you may have one of them running.

Vim has 2 special registers corresponding to these clipboards:

  • * uses PRIMARY; mnemonic: star is select (for copy-on-select)
  • + uses CLIPBOARD; mnemonic: CTRL + C (for the common keybind)

On Windows & OS X there is no difference between + and *, since these systems only have a single clipboard, and both registers refer to the same thing (it doesn't matter which one you use).

You can use these registers as any register. For example, using the PRIMARY clipboard * with the y and p commands:

  • "*yy
  • "*p

You could maybe use this as more convenient keybinds:


noremap <Leader>y "*y
noremap <Leader>p "*p
noremap <Leader>Y "+y
noremap <Leader>P "+p

If you want to "automatically" interface with the system's clipboard instead of referring to it manually all the time, you can set the clipboard variable:

  • Set it to unnamed to use * (PRIMARY, on select)
  • Set it to unnamedplus to use + (CLIPBOARD, ^C)

Now, just using yy will go to the system's clipboard, instead of Vim's unnamed register, and p will paste the system's clipboard.

You can also assign to these registers just like any register with let:

  • :let @+=42
  • :let @*=42

The clipboard setting has some more options (such as exclude filters); but these are the basics. See :help 'clipboard' for the full story ;-)

 

...

No +clipboard?

Vim requires the +clipboard feature flag for any of this to work; you can check if your Vim has this by using :echo has('clipboard') from within Vim (if the output is 0, it not present, if it's 1, it is), or checking the output of vim --version.

Most Linux distributions ship with a "minimal" Vim build by default, which doesn't have +clipboard, but you can usually install it:

  • Debian & Ubuntu: Install vim-gtk or vim-gnome.
  • Fedora: install vim-X11, and run vimx instead of vim (more info).
  • Arch Linux: install gvim (this will enable +clipboard for normal vim as well).

You could also use xclip, xcopy, or xsel to copy text to the clipboard; see the following questions for solutions:

 

If I read that post right, VIM already has system clipboard support. It may require configuring to get it set up.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, M.Yurizaki said:

https://vi.stackexchange.com/questions/84/how-can-i-copy-text-to-the-system-clipboard-from-vim

 

 

If I read that post right, VIM already has system clipboard support. It may require configuring to get it set up.

Does not work. Tried it a million times. 

Running Arch with i3-gaps on a Thinkpad X1 Extreme
Data Science Postgrad

 

Link to comment
Share on other sites

Link to post
Share on other sites

28 minutes ago, M.Yurizaki said:

http://vim.wikia.com/wiki/Accessing_the_system_clipboard

 

If that doesn't work, then I'm going to guess it's because vim wants something you don't have setup in the system itself, not vim.

I have tried all of this. None of it works. The vim-package I have installed does NOT support clipboard or xterm_clipboard. I need another vim-package. 

Running Arch with i3-gaps on a Thinkpad X1 Extreme
Data Science Postgrad

 

Link to comment
Share on other sites

Link to post
Share on other sites

I fixed this by installing vim-gtk. I thought my /usr/bin/vim would be untouched, and that I had to run gvim in order to have +clipboard and +xterm_clipboard... When gvim is installed, /usr/bin/vim has +clipbard and +xterm_clipboard, and you can still run it in the terminal with the vim-command.

 

Awesome. 

Running Arch with i3-gaps on a Thinkpad X1 Extreme
Data Science Postgrad

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×