I always use vi for editing config files.

Today I wanted to select all the text in a file (around 1000 lines), copy it, then paste into Google Docs. How can I do that?

link|improve this question
This is a superuser.com question – Aleksandr Levchuk Dec 30 '10 at 17:32
feedback

migrated from serverfault.com Dec 30 '10 at 18:28

This question came from our site for system administrators and desktop support professionals.

6 Answers

You can use cat file and then select output and copy and paste if you need to paste it into your browser.

For vi this is how you can select all text and write it into a new file:

shift v  -- visual mode
shift g -- jump to eof
"*y -- yank select text
:e my_new_file -- create a new file
"*p -- paste into a new file

In theory this should work on both Linux and Windows - I tried it on a Mac but it doesn't work.

link|improve this answer
To paste into the Web browser cat file is the way to go. The shift v method only copies to Vi's internal buffer. – Aleksandr Levchuk Dec 30 '10 at 17:31
not if you use the system clipboard which uses the * registry - but this works on X only and I heard on windows - so if you ssh you need the -X - to check if vim has support for this into vim -- :set clipboard+=unnamed – silviud Dec 30 '10 at 17:34
feedback

If you're using a linux desktop, you could load it into the clipboard using xclip or xsel. For something that size you might just want to use the upload feature in google docs.

link|improve this answer
feedback

gg"+yG

or

gg"*yG

depending on whether + or * is the system clipboard. (On many unixes, + is the mouse selection buffer for middle-mouse-clicking, and * is the system clipboard).

link|improve this answer
1  
I think it's the other way around: "* is selection and "+ is clipboard. vimdoc.sourceforge.net/htmldoc/gui_x11.html#x11-selection – Mikel Dec 30 '10 at 20:24
You're right. I knew that too, but typed the wrong thing. ☹ – frabjous Dec 30 '10 at 22:21
feedback

See http://vim.wikia.com/wiki/Accessing_the_system_clipboard for options on how to do this. (if compiled in "* should refer to the system clipboard). There are also instructions there for how to use xsel with vim.

link|improve this answer
"* is the what was selected and "+ is what was copied. vimdoc.sourceforge.net/htmldoc/gui_x11.html#x11-selection – Mikel Dec 30 '10 at 20:25
feedback

The simplest and fastest way is to use: : % y + and then go over to Google Docs (or wherever) and paste.

Another way is g g " + y G but you will likely admitt that the above is faster and easier.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown