Tech Bloster logo Tech Bloster

How to Create a File Using Vim Command?

To begin working with Vim, open a command line or terminal on your local machine. The terminal is where you will enter commands.

To create a new file using Vim, simply type the following command and press ENTER:

This command opens a new file named firstFile.txt in the Vim editor. You will be in normal mode initially.

Vim Command Interface

How to Enter Insert Mode in Vim?

When you open a file in Vim, it begins in normal mode. To type text into the file, you must enter insert mode. To do this, press the lowercase 'i' key on your keyboard. Now, you can start typing into the file.

Vim instert mode Command Interface

How to Add Text to a File in Vim?

Once you're in insert mode, start typing. For example, you might write a few sentences about how your day is going. If you make a mistake, simply use the backspace key to correct it, just like you would in any text editor.

Add Text to a File in Vim

How to Come back to Normal Mode in Vim?

After typing the initial text, you can continue by writing your code as per your requirements. Once you are done typing, press the Escape key to return to normal mode.

Come back to Normal Mode in Vim

How to Save a File in Vim?

To save your work, make sure you're in normal mode by pressing the Escape key. Then, type the following command to save the file and exit Vim:

Press [ENTER] to save and quit.

Save a File in Vim Command

How to Exit Without Saving?

If you're done viewing the file and don't want to make any changes, you can exit without saving by typing:

Press [ENTER], and Vim will close the file without making any changes.

Exit Without Saving Command