How does Vim empty files

In Vim, the contents of a file can be emptied with the following command:

  1. vim filenameOpen the file to be emptied: Enter open file in the terminal , where filenameis the name of the file you want to edit.

  2. EscEnter command mode: Make sure you are in Vim's command mode by pressing the key on your keyboard . (that is, a colon in the lower left corner)

  3. Empty file content: In command mode, enter the following command:

   :1,$d

This command means to delete the content from the first line to the last line. :It means to enter the command mode, 1,$means to select the range from the first line to the last line, and dmeans to delete.

  1. Save and exit: Press the key on the keyboard Escto enter command mode, then enter to :wqsave and exit the file.

In this way, you have successfully cleared the contents of the file. Please note that the file cannot be recovered after being emptied, please proceed with caution.

Guess you like

Origin blog.csdn.net/weixin_45277161/article/details/132627360