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. In other GUI based text or document applications the CTRL+A is used to select all text.

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$

Select and Delete All Lines

There is the % command which can be used to select all text and then run another command for action. The %d can be used to select and delete all lines with a single command.

:%d

Select and Copy All Lines

The %y command can be used to select and copy all lines with a single command.

:%y

Select All In Gvim

Gvim is a GUI frontend for the vim command line text editor. The GUI features can be used to select all lines or content. Just use the mouse cursor to select all in Gvim.

Select All In Gvim

Leave a Comment