Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I based my vimrc file on a popular thread here on SO, and although it's great I have a real problem when it comes to copying text from vim to other linux applications. I suspect the error lies in this vimrc since I can copy when vim is loaded from a blank vimrc file.

What's wrong here?

Bonus question: how do i copy from my guest ubuntu to windows?

My vimrc file can be found here: http://dpaste.org/X4MY/

share|improve this question

migrated from stackoverflow.com May 28 '11 at 14:53

This question came from our site for professional and enthusiast programmers.

1  
Are you using vim or gvim? –  Benoit May 28 '11 at 14:21
    
vim. i'm in ubuntu. –  DevX May 28 '11 at 14:27

7 Answers 7

up vote 6 down vote accepted

Nothing in your .vimrc file strikes me as a problem except perhaps the line

set clipboard+=unnamed

The issue is that the exclude term of the 'clipboard' option, which is present by default if X is detected, must be the last term. By using +=, you have made unnamed the last term. A better setting would be

set clipboard^=unnamed

which places unnamed first in the option string.

Something else you might try, since an empty .vimrc works for you, is to do a binary prune of your .vimrc file. That is, put a :finish command as the first line in your .vimrc file, restart vim and verify that copying works, then move the :finish command about halfway down your .vimrc file, restart vim and try again. Repeat, trying to narrow down the region that contains the problematic command(s). Commenting-out lines works instead of the :finish command, too. You can keep your .vimrc file open in one Vim while restarting a different Vim to make the whole process go a little faster.

share|improve this answer
2  
The :finish command helped me to triage the problem. The "set mouse=a" line was the culprit. thanks! –  DevX May 29 '11 at 2:09
1  
I assume you're trying to copy/paste by selecting the text and then middle clicking in another window. If you're running vim in a terminal and have set mouse=a, vim gets the mouse clicks instead of your terminal application, so when you click and drag you're selecting text in vim's visual mode. This is very useful within vim, and you may not want to just disable it. If you want to select, you need to find a control key that causes the clicks to be handled by your terminal instead of vim. If you were using putty, you'd simply hold shift while selecting. What terminal program are you using? –  mkomitee May 29 '11 at 18:07
    
Seconding the problem with "set mouse=a" and usefulness of :finish. Thanks! –  Stew Jul 16 at 21:47

How do you copy things from Vim? Vim uses several registers where the +-Register is used to share information with the systems clipboard. For instance, to copy a whole line into systems clipboard use

"+Y

After that just use CTRL-V to paste like always.

share|improve this answer
1  
I've seen this suggestion in several places, but it doesn't work for me. –  DevX May 28 '11 at 15:06

Press the shift key when selecting text if you have mouse support enabled on vim. The normal selection (without shift) enables VISUAL mode. Using shift passes mouse events to your terminal emulator.

share|improve this answer
    
Ok, this is getting me closer to my goal. I can now copy when i hold down shift (previously copy command was disabled in context menu). The only problem is that it also copies my line numbers. i don't want that. any tips? –  DevX May 28 '11 at 15:08
    
If you press the shift key while copying or pasting, you are using the terminal's copy and paste functionality, not Vim's, so you will copy what the terminal "sees", which includes the line numbers. This is working around the problem, not solving it. –  garyjohn May 28 '11 at 17:52

From one of your comments:

I've seen this suggestion in several places, but it doesn't work for me.

Solution:

You probably don't have vim installed with the clipboard feature enabled, which is required for being able to copy/paste to/from the system clipboard.

If you type vim --version at the command line, you'll probably see -clipboard in the features list. Try compiling vim from source with the following option:

 ./configure --with-features=huge

(include other options you need) and then proceed with make and make install. Now you should see a +clipboard in your features list and you can yank to the system clipboard using

"+y

and paste from the system clipboard using

"+p
share|improve this answer
    
You might also be able to install extra packages rather than compiling from source. I installed vim-gui-common in Kubuntu 12.10. –  Jacob Dalton Feb 13 '13 at 8:38

About your bonus question: I know it's unsophisticated, but I tend to have apache running on all my machines - physical and virtual - and so I can copy files somewhere in the document tree and have them visible (and downloadable) from all the other machines.

share|improve this answer

But I like mouse support!

After hunting through the help docs I also found this little gem:

Note: When enabling the mouse in a terminal, copy/paste will use the “* register if there is access to an X-server. The xterm handling of the mouse buttons can still be used by keeping the shift key pressed.

Sure enough, holding shift allows regular old copy paste with PuTTY.

share|improve this answer

Comment the line

set mouse=a

in the .vimrc file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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