How to Select All Text in Vim/Vi editor


If you want to copy all text in a file using Vi/Vim console-based text editor, you can make use of the following command


For Vim Editor

  1. Open file using vim editor.
  2. Now make sure you are not in insert mode.
  3. Enter the text ggVG
    • gg: To move the cursor at the first line of the file.
    • V: To enter visual mode.
    • G: To move the cursor at the last line of the file.
VIM Select All Text

For Vi Editor

  1. Open file using Vi editor.
  2. Now make sure you are not in insert mode.
  3. Enter the text %y
    • %: To select the text of the entire file.
    • y: To copy the selected text into the buffer.

This should work with all operating systems that support VIM - macOS, Ubuntu Linux, Kali, Windows e.t.c

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap