Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I had some trouble with copy-pasting text from vim in terminal to Google Docs (aka Drive) document (hereafter GDd) in FF browser (with Vimperator).


  • I have a file opened in Vim 7.2 in terminal
  • :version displays both +clipboard and +xterm-clipboard
  • I'm on Ubuntu 10.04 LTS, so I don't think that's Unity-related
  • I want to use Vim, not GVim, nor gedit...
  • I'm avid fan of mouseless navigation, so solution with mouse was not what I wanted.
  • I have the solution, but I need understanding.

What I tried and where it gets me:

  • Yanking whole file text via: ggvGy allows me to:
    • paste it via mouse middle button, NOT with Ctrl+v or Shift+Insert
      1. here, in text area for entering question text
      2. in gedit
      3. but NOT in GDd where I want it pasted, even if I switch Vimperator to pass-through mode with Insert
    • does NOT show in XClip after xclip -o
    • From gedit, I can copy-paste the text into GDd (Vimperator's pass-through mode not required).
  • :%! !xclip -i (or :first, last)
    1. reports whole file (all lines, to be precise) as filtered, though shell returns 1
    2. `xclip -o' returns nothing (is empty) or returns previously copied value
    3. with 2. no surprise, but I can't paste at all not only to GDd but also to gedit or here
  • setting clipboard (:set clipboard=unnamed) to unnamed doesn't help
  • using "+y or "*y on whole file text actually does the trick

So, the question (it's actually three, say "split" and I will):

  1. why middle mouse button pastes different things than Ctrl+v and how to know what will be pasted with each?
  2. why just yanking (without registers) works with mouse but not with keyboard / XClip?
  3. why didn't unnamed register help? After setting, it should make unnamed and * registers same?
share|improve this question

2 Answers 2

up vote 2 down vote accepted

By default, the clipboard gets filled only if you do visual selection (using v, or, equivalently, your mouse). (In all the following, we are talking about the "old" X clipboard, the primary buffer). To affect the clipboard using "y" even without visual selection, you need to :set clipboard=unnamed. I do not know why, in your first example, the xclip -o shows no contents; it should. I have a hypothesis about that, however, see below.

I have 10.04. I start vim.

:set clipboard

I type some random text:

asd fa sdf

Now I do ggVGy. In another terminal window, I type

xclip -o

xclip shows me, correctly, the contents of the file. I can paste it wherever with the middle mouse button, for example here:

asd fa sdf

Same if I just start visual selection with "v", move around, and yank with "y". However, if I do "yy" (yank the current line, without visual selection), the clipboard is not updated.

OK, now I do

:set clipboard=unnamed

I do ggyy (go to the first line, yank to unnamed register without using visual selection). Now xclip -o shows "asd fa sdf" and I can paste it with my middle mouse button; the X clipboard got filled in with the yank command.

Bottom line

Without touching vimperator, it works on my system as expected. Please repeat the above (without using vimperator, see below) to make sure that when you do ggVGy, xclip -o show the contents (unlike in your example).

My hypothesis is that vimperator, for some reason, resets the X clipboard. Try to separate the regular vim session from vimperator:

  1. If you select something in terminal with your mouse (left button, without Ctrl-Shift-C), can you paste it with middle button to vimperator?

  2. If you visually select something with vi, can you paste it with middle mouse button in gedit (apparently you can) and see it with xclip -o (you say you can't, but I don't believe it :-); otherwise, middle mouse button would not work )?

share|improve this answer
Xclip mystery explained with another terminal. My thanks for that! In another terminal xclip shows all that it's supposed to. :-) Both in your example as in mine. Vimperator however is not the guilty party - the copying works everywhere but in GDd. Therefore I'd say it's the fact that GDd somehow cannot access the mouse clipboard (primary selection). Thank you very much January, your explanation was very easy to understand. –  LIttle Ancient Forest Kami Sep 23 '12 at 20:43
  1. Linux has two clipboards (called "primary buffer" and "secondary buffer"). One is used for mouse copy/paste and another is for Ctrl-C/Ctrl-V. So, if you select something (say, in order to delete it) the contents of what you put in clipboard using Ctrl-C are still there intact.

  2. If you want to copy without yanking try to select your text desired to copy and press CTRL+SHIFT+C then CTRL+SHIFT+V to copy/paste it

I hope this would help

share|improve this answer
Upvoted for clear distinction between Linux clipboards. I found excellent explanation of it in this question's accepted answer. –  LIttle Ancient Forest Kami Sep 23 '12 at 19:13
Forgot to add! As for terminal copying, thanks, though this hinders me in using Vim motions, doesn't it? Also, this copies to primary buffer (mouse one). Nadal jednak dzięki, Kamilu. :-) –  LIttle Ancient Forest Kami Sep 23 '12 at 19:25

Your Answer


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.