Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 4561  / 2 Years ago, thu, may 19, 2022, 11:20:08

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).



Note:




  • 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?


More From » keyboard

 Answers
0

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
clipboard=autoselect,exclude:cons|linux


I type some random text:



asd fa sdf
asdf


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
asdf


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 )?



[#35410] Friday, May 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
looweets

Total Points: 52
Total Questions: 114
Total Answers: 111

Location: Turkmenistan
Member since Sat, Apr 16, 2022
2 Years ago
looweets questions
Fri, Apr 29, 22, 09:47, 2 Years ago
Thu, Nov 3, 22, 03:32, 2 Years ago
Sun, Mar 5, 23, 00:43, 1 Year ago
;