10

I'm using the latest version of vim 8.2.148 on the latest version of arch linux 5.5.6-arch1-1 with the latest version of Openbox window manager version 3.6.1.

I have written a document in vim and need to yank parts of it and paste them into a web form.

Is there a command in vim to yank to the system wide / openbox clipboard so that I can paste into the chromium web form?

Yank seems to work inside vim only.

Kes
  • 663
  • 1
  • 8
  • 18
  • 2
    Welcome to Vi/Vim SE. I'm sure I've seen answers here before that cover this. Did you try the Search box up top? If you found some but they were missing some critical detail please note that. – B Layer Mar 08 '20 at 01:31

1 Answers1

14

First get into an appropriate visual mode. v selects the standard visual mode, SHIFT-v selects visual-line mode, and CTRL-v selects visual block mode. Next, select the text that you want to select. Finally, "+y.

  • " means register.

  • + specifies the system clipboard register.

  • y is yank.

So "+y yanks into the system clipboard register.

more info on registers:

JMW
  • 280
  • 2
  • 8
  • I has to install neovim to get this to work. My native vim install did not support copy to system wide clipboard. – Kes Mar 08 '20 at 17:33
  • 1
    You might want to check your vimrc and plugins on your native vim install. Some sort of misconfiguration could be interfering. It should work out of the box. However, nvim is better anyway. – JMW Mar 08 '20 at 18:12
  • tried this on a fresh install of Linux Mint 20.1 and doesn't work. No custom .vimrc. ¯\_(ツ)_/¯ – lacostenycoder Apr 28 '21 at 19:08
  • 1
    vim-gtk package on ubuntu contains the +clipboard fyi – Goblinhack May 28 '21 at 07:59
  • 1
    @Goblinhack I saw that + was not in the registers when using :reg and installing that thing solved it – Minsky Jan 08 '22 at 12:40
  • This is an idiosyncracy that comes from using binary packages. If you want different options (like X11 and clipboard support) you have to install a different package. Ubuntu may have to support a non-X11 version of VIM so that some installation cd or rescue cd can work without xorg. You might consider investigating a source based package manager like Gentoo where you can control USE flags for packages. Opaque binary package management is inflexible and brittle and doesn't provide the best linux experience IMHO. – JMW Jan 09 '22 at 02:55
  • A tip: the "+ register will only work if vim is compiled with clipboard or xterm_clipboard This can be double checked with vim --version|grep clipboard if the result is -clipboard then it will not work if it' s +clipboard then the register will work. Usually vimx and neovim has this support enable – isca Sep 29 '23 at 13:08