tags:

views:

1726

answers:

7

Is there any way to copy all lines from open file to clipboard in VI editor. I tried yG but its not using clipboard to store those lines.

So is it possible?

+2  A: 

The clipboard is buffer +. To copy to clipboard, do "+y[movement]. So, gg"+yG.

Similarly, to paste from clipboard, "+p

Tordek
+6  A: 

You should yank the text to the * or + registers:

gg"*yG

Explanation:

  • gg
    • gets the cursor to the first character of the file
  • "*y
    • Starts a yank command to the register * from the first line, until...
  • G
    • go the end of the file
CMS
Nice...I never knew about the `<kbd>` tag...
Jason Punyon
How do you mark up the text so it looks like keys? I haven't seen that yet on SO.
Jergason
Ah, beaten to the punch.
Jergason
Hello... its not working?clipboard data remains unaltered. when I type gg cursor goes to first line... but when I type "*yG ..cpu beeps at * ..so is it normal or some problem with my vim? I am on Ubuntu..
Xinus
Do you have Deadkeys enabled? (e.g., when you hit 'a you get á) If so, you need to press space after `"`.
Tordek
Vim can only access the system clipboard if it is compiled with xterm_clipboard enabled. To find out whether you have this feature, run `:version` in vim, and look for the `+xterm_clipboard` flag. If it is preceded by a minus sign, then you won't have this functionality. If this is the case, you might want to compile vim yourself, or run gvim which usually has this feature enabled.
nelstrom
@nelstrom: you are right its not installed .. I cannot recompile vim now... I will give it a try.. maybe later .. thanks everyone :)
Xinus
+5  A: 
:%y+

to yank all lines

ldigas
+1  A: 

If you're using Vim in visual mode, the standard cut and paste keys also apply, at least with Windows.

  • CTRLA means "Mark the entire file.
  • CTRLC means "Copy the selection.
  • ESC means "De-select, so your next key press doesn't replace the entire file :-)

Under Ubuntu terminal (Gnome) at least, the standard copy also works (CTRLSHIFTC, although there doesn't appear to be a standard keyboard shortcut for select all (other than ALTE followed by A).

paxdiablo
But if you aren't using mswin.vim, then ctrl-a increments the next number on the current line.
Mark Rushakoff
@Mark, this behavior is from a standard Vim install so I assume that's the default. All bets are off if the environment is configured differently, though if that were the case, I suspect the OP would know what they're doing :-) In either case, OP stated in a comment they were on Ubuntu so the Windows part of my answer probably doesn't apply. The Gnome terminal stuff would.
paxdiablo
A: 

There wasn't a concept of "clipboard" in Bill Joy's vi so I don't think there is a built-in way to do it.

gVim's automatic copy-anything-highlighted-to-the-clipboard feature is easiest or use an external program via :!

For Cygwin's vim I use

:%!putclip
u

Maybe Ubuntu has a CLI app like putclip??

rshdev
A: 

Same question as : Yank Entire file

Luc Hermitte
A: 

This is what I do: ggVGy

EmilianoGNFNR
I'm afraid this does not answer the question, as you are yanking to the default register, not to the clipboard.
Conspicuous Compiler