How To “Select All” In Vim/Vi?

You want to select all content of a file in Vim or Vi. As a command-line editor, the mouse pointer can not be used to select some or all of the content. You should use some command in order to select all content of a file from beginning to end.

Use ggVG To Select All

All content of a file can be selected by using the Visual Mode of Vim or Vi. First, we will press the ESC key to change normal mode. Then we will move to the start of the file by using the gg keys. Then enable the visual mode with the V key and the last step is pressing G which will select from the start of the file to the end of the file. In short, you can use the following key sequences to select all content.

Use ggVG To Select All

Use 99999yy To Select and Copy All

There is an alternative way that can be used to select and copy all content. The yy command is used to yank or copy the current line but providing the line count we can select and copy all lines. We will provide a very high number of 99999 to select and copy. First change to normal mode with the ESC. Then use gg to move the cursor to the start of the file. the last issue 99999yy command to copy to the end of the file.

gg99999yy

Use $yy To Select and Copy All

There is an alternative way that can be used to select and copy all content. The yy command is used to yank or copy the current line but providing the line count we can select and copy all lines. First change to normal mode with the ESC. Then use gg to move the cursor to the start of the file. the last issue y$ to copy from the current cursor location which is the start of the file to the end of the file.

ggy$
READ  Copy, Cut, and Paste In Vim / Vi

Leave a Comment