I Can't copy FROM vim. Can you diagnose my .vimrc file?

7

1

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/

DevX

Posted 2011-05-28T14:19:57.147

Reputation: 173

1Are you using vim or gvim? – Benoit – 2011-05-28T14:21:25.580

vim. i'm in ubuntu. – None – 2011-05-28T14:27:01.610

Answers

6

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.

garyjohn

Posted 2011-05-28T14:19:57.147

Reputation: 29 085

Seconding the problem with "set mouse=a" and usefulness of :finish. Thanks! – Stew – 2014-07-16T21:47:46.110

2The :finish command helped me to triage the problem. The "set mouse=a" line was the culprit. thanks! – DevX – 2011-05-29T02:09:26.483

1I 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 – 2011-05-29T18:07:01.893

5

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.

Daniel Torres

Posted 2011-05-28T14:19:57.147

Reputation: 151

1I've seen this suggestion in several places, but it doesn't work for me. – DevX – 2011-05-28T15:06:05.800

3

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.

ninjalj

Posted 2011-05-28T14:19:57.147

Reputation: 511

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 – 2011-05-28T15:08:48.437

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 – 2011-05-28T17:52:02.387

2

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

user76528

Posted 2011-05-28T14:19:57.147

Reputation:

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 – 2013-02-13T08:38:23.830

0

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.

pavium

Posted 2011-05-28T14:19:57.147

Reputation: 5 956

0

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.

abcd

Posted 2011-05-28T14:19:57.147

Reputation: 1

0

Comment the line

set mouse=a

in the .vimrc file.

user1514248

Posted 2011-05-28T14:19:57.147

Reputation: 1