How to select all in Vim
In Normal mode, press gg to go to the first line, V to start selecting lines and G to extend to the last: ggVG. Then y copies everything, d deletes it and > indents it.
Indent the whole snippet
These lines are moving inside a function, so every one of them needs one more level of indentation. Select them all with ggVG, then indent with >.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | What it does |
|---|---|
| ggVG | Select every line (and see it highlighted). |
| ggVG, then y / d / > / = | Copy / delete / indent / reindent everything. |
| ggVG, then "+y | Copy everything to the system clipboard. |
| ggyG | Copy everything, without selecting. |
| ggdG | Delete everything, without selecting. |
| gg=G | Reindent the whole file. |
:%y ↵ | Copy every line, wherever the cursor is. |
:%y+ ↵ | Copy every line to the system clipboard. |
:%d ↵ | Delete every line. |
How ggVG works
It's three commands in a row. gg moves to the first line. V starts Visual Line mode, which selects whole lines, so it doesn't matter which column you're in. G moves to the last line, and the selection follows. Nothing has happened to the text yet: the next key decides what does. y copies it, d deletes it, > indents it one level, = reindents it with the rules for the file type, and Esc cancels.
Often you don't need to select
The selection is there so you can see what's about to change. When you already know it's the whole file, skip it: an operator followed by a motion from the top does the same thing. ggyG copies everything, ggdG deletes everything, gg=G reindents everything.
On the command line, % means every line, so :%y copies the whole file and :%d deletes it, and neither moves the cursor. :%y+ copies it to the system clipboard, the quickest way to get a whole file into another program.