Select all in Vim / Vi

Glory Kim
Glory KimSoftware Engineer, Loom
Published: August 13, 2024

To perform the command traditionally known as “ctrl + a” to select all in Vim, do ggVG.

Breaking it down:

  1. Check that you are in normal mode - hit the ESC key.
  2. Move the cursor to the beginning of the file - gg.
  3. Enter visual mode which lets you see the highlight portions - V

Pressing V enters line visual mode while pressing lower case v will enter character visual mode. Being in v mode will cause the below command to highlight until the first character of the last line in the file.

  1. Select from the current cursor position to the end of the file - G

At this point, you can scroll up and down or use Vim commands to de-select lines.

Vim copy all lines

After performing the select all sequence above, you can use this command to copy the whole entire file: y. This will yank and copy the selected lines.

Vim copy all to clipboard

Using yank alone only copies the portion to the default register (i.e. Vim). It won’t copy to the clipboard. So if you wanted to copy the selected code to use outside the terminal you’ll need to use gg"\yG

  • Move the cursor to the beginning of the file - gg
  • Copy it to the clipboard from current position - "\y
  • Move the cursor to the end of the file - G

Vim paste all

In order to paste what you’ve copied, you can hit p to paste after the cursor and P to paste before the cursor.

Read more about copy/pasting text in Vim.

Vim delete all lines

To clear all the lines of a file: :%d

  • Go to normal mode - ESC
  • Enter command mode - :
  • Select All - %
  • Delete - d

Learn more about deleting lines in Vim.

Make a mistake? If you want to undo an accidental deletion, you can use the u command (:u) to undo in Vim, and the lines that were deleted will show up again.

Written by
Glory Kim
Glory KimSoftware Engineer, Loom
Filed under

Related articles


Go To End of File in Vim / Vi

Select and delete to the end of a file in Vim

Copy & Paste in Vim / Vi

Copy (Yank), Paste (Put) and Cut (Delete) in Vim

Copy & Paste in Vim / Vi

Copy (Yank), Paste (Put) and Cut (Delete) in Vim

Searching in Vim

Search forward, backward, case insensitive, and more

Show & Hide Line Numbers in Vim / Vi

Toggle absolute and relative line numbers

Undo & Redo in Vim / Vi

Keyboard shortcuts and summary of how Vim tracks changes

Vim Go To End/Start of Line

Go to the end or beginning of a line in Vim

Go To Line In Vim

Variety of approaches to go to lines

Go To Top of File in Vim

Learn how to jump the top of the file in Vim, then navigate, search, highlight, and delete.

Vim Modes

Learn about seven of Vim’s modes

Vim / Vi Page Up and Down Controls

Quick reference for Vim's page up and down controls

How to delete lines in Vim / Vi

The best answer depends on which mode you use