How do I select all text in Vi/Vim?

Using VI tool for editing config files.

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


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.


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.


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.


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