Is it possible to configure vim (obviously with :set mouse=a) and/or gvim such that the visual selection modes automatically integrate with X's selection buffer?

I am aware of how to setup the copy registers to integrate with the clipboard, but I would like to integrate the selection system as well. Is it possible and, if so, how?

  • 2
    possible duplicate of How can I copy text to the system clipboard from Vim? .... This is covered in (my) accepted answer I think (unless I misunderstood the question): "if you use gVim, you can get copy-on-select behaviour when using :set guioptions+=a. This is enabled by default on X11 systems (copies to PRIMARY)" – Martin Tournoij Feb 13 '15 at 20:02
  • 2
    @Carpetsmoker Only part of this is covered in that (useful) post and I believe this somewhat different use case deserves specific treatment. Making this a duplicate will not make it easier to sort out for people with this specific goal in mind. – Caleb Feb 13 '15 at 20:54

I understand that you are set up with the features necessary for copy and pasting with the system clipboard, but I want to be a tad redundant as those registers can be a tad challenging to set up. It's all about the features that are enabled with your install of Vim. In OS X and Linux, the clipboard feature needs to be enabled, and Linux usually also requires the xterm_clipboard setting. You can tell if these are set by running vim --version and seeing if there is a + or - for on or off respectively next to the feature name. There are notes on how to do this with OS X here, and Ubuntu here. There is also a nice summary of this information on a blog here.

According to this superuser post, macvim (and most likely gvim in general) will (assuming the clipboard is set up properly) automatically copy selections into the system clipboard if set guioptions+=a is set. This seems to be the key to working with X's selection buffer. Quickly viewing the Vim documentation on guioptions, putting set guioptions+=a should do as you desire for gVim. For more info check out this post by Carpetsmoker here.

For console Vim I found this article on how to disable what you are after... it seems that putting the following in your .vimrc will result in happy days:

 set clipboard += autoselect

For me, this successfully copied visual selections into the + register.

| improve this answer | |
  • In my vim, set clipboard += autoselect fails with E518: Unknown option: autoselect. Version 8.0 on ubuntu 17.10. – kaleissin Jul 5 '18 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.