Multiple file delete in VIM

ยท

1 min read

To remove all content in a file using Vim, follow these quick methods:

๐Ÿš€ Method 1: Using Normal Mode

  1. Press Esc to ensure you're in Normal Mode.

  2. Type this command:

     gg
     dG
    
    • gg โ†’ Moves the cursor to the top of the file.

    • dG โ†’ Deletes from the current line to the end of the file.

Or combine it into one command:

ggdG

โšก Method 2: Using Command Mode

  1. Press Esc to switch to Normal Mode.

  2. Type : to enter Command Mode, then:

     %d
    
    • : โ†’ Opens the command line.

    • % โ†’ Refers to the entire file.

    • d โ†’ Deletes the content.


๐Ÿ’พ Save Changes After Deletion:

wq
  • :wq โ†’ Save and exit.

  • Or just :x for the same effect.

If you want to exit without saving:

q!

Let me know if it worked or if you need more help! ๐Ÿš€

ย