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

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

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

    
This is a superuser.com question –  Aleksandr Levchuk Dec 30 '10 at 17:32

8 Answers 8

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
1  
@Tuxmentat can you please explain what each key does in :%y+ –  Jas Jun 22 at 9:41
    
This answer would be better if it explained what each key does for both sequences. –  AsksAnyway 16 hours ago

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

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

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

Many given replies also yank the selection, which I was not looking for.

I'm using ggVG for this purpose (needs to be run on normal mode). This command only selects the whole text inside the document.

I've even remapped Ctrl+A for this purpose, since I don't really need to increment an integer with the shortcut (default Ctrl+A map).

Just add this into your .vimrc:

map <C-a> <esc>ggVG<CR>

It has <esc> first, to make sure the user is in normal mode.

share|improve this answer

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

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

Your Answer

 
discard

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