Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Dec 30 '10 at 18:28

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

11 Answers 11

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

  • % to refer the next command to work on all the lines
  • y  to yank those lines
  • +  to copy to the system clipboard

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

share|improve this answer
+1 for the first method, another benefit is that it doesn't move the cursor position. – Andy E Mar 12 '13 at 12:41
@Tuxmentat can you please explain what each key does in :%y+ – Jas Jun 22 '14 at 9:41
This answer would be better if it explained what each key does for both sequences. – AsksAnyway Jul 27 '14 at 14:13
My best guess: the ':' means we're using an "ex mode" command (I think). Anyhow, it's a command. '%' is a special command-line range specifier which specifies the whole file. 'y' yanks everything, and '+' specifies the clipboard register. :help <command> helped me figure this out. – Hawkeye Parker Aug 27 '14 at 9:53
ggVG, then "+y is my fav, and then of course i dont use "+ because i mapped y to "+y (among others) that way i just have to do ggVG and then y – osirisgothra Sep 24 '14 at 11:47

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

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
Exactly what I was looking for, and it's nice to see that Ctrl+A isn't occupied in vim by default. Hope there are no side-effects. – Nikos Alexandris Apr 21 '15 at 13:54




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
I think it's the other way around: "* is selection and "+ is clipboard. – 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

USE ggVG. type "gg" to go at top of the test Then type VG.

share|improve this answer

For a Mac, use pbcopy (pasteboard copy):

cat file.txt | pbcopy

The contents of file.txt are now on the clipboard for pasting into another application (e.g. browser).

You can also paste the contents of the clipboard into a file using pbpaste:

pbpaste > file.txt

While this doesn't involve vi specifically it does achieve the same goal on a Mac.

share|improve this answer

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

Without using vi, you can upload text to google docs using their API and cURL.

share|improve this answer
that's the opposite of what OP wants -.- – Rápli András Oct 9 '14 at 18:27

See 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. – 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

Use the following command.

cat <your file name>

It will echo the content of file. Now select, scroll, copy, paste.
Game Over


cat bobis.txt
share|improve this answer

protected by Nifle Jan 8 '15 at 20:07

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?