Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

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

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

This question came from our site for professional system and network administrators.

7 Answers

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.

share|improve this answer
2  
+1 for the first method, another benefit is that it doesn't move the cursor position. –  Andy E Mar 12 '13 at 12:41
add comment

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.

share|improve this answer
1  
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
    
Is there any alternative to do this without creating a new file.if we are editing live on server we need to keep the backup code on local machine so that we can revert back. –  Infinity Jul 24 '13 at 4:51
add comment

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

share|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
add comment

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.

share|improve this answer
add comment

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.

share|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
add comment

Another way would be:

You press v key on your keyboard and turn VIM to VISUAL

Then select all text by scrolling down

^+ INSERT to copy

SHIFT +INSERT to paste the text wherever you want on Google Docs.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.