Creating a file using VIM editor

Published on and updated on
by

In this article we will show you how to create a new file using Vim. Vim is a text editor that is widely used by programmers and developers.

In this article we will show you how to create a new file using Vim. Vim is a text editor that is widely used by programmers and developers. It is a powerful tool that allows you to create and edit files in a variety of ways.

Install Vim

The first step in order to create a new file in Vim is to install Vim text editor on your system.

Installing Vim on Debian based Linux OS

To check if Vim exists in your Debian based Linux operating system type the following command in your terminal:

vim --version

Check if the output looks like this:

$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jun 23 2022 04:01:15)

Otherwise, run the following command to install Vim:

$ sudo apt-get install vim

Installing Vim on Windows

  1. Visit the Vim's official download page. Then click on gvim90.exe it will automatically start the downloading.
  2. Then open the executable file.
  3. Click on Okay
  4. Then click on Next and select the terms and conditions checkbox and click again on Next.
  5. Then Next
  6. And follow the remaining steps to install the vim text editor. Once it's done the final installation window will look something like this:

Creating a file using Vim

On Unix/Mac/GNU+Linux

  1. Open terminal from the menu.
  2. Now move to the directory where you want to create a file using vim.
  3. Run the following command <filename> change this with your own filename.
    vim sample_file.txt
  4. Type i to start editing your file.
  5. To save your text file. First of all, close the editing mode by pressing escape esc key. Then type :wq (write and quite) and hit enter.
  6. Now if you run the list files command in your terminal using ls. You can see the text file if you have just created:

On Windows

If you're using a bash terminal on Windows like Putty or Git Bash. Then you can follow the above same otherwise follow the steps below to create a file using vim on Windows.

  1. Open Start Menu and type Vim.
  2. Once you see the vim's executable program, then click on that to open it up.
  3. Then simply type i to start editing your file.
  4. To save your text file. First of all, close the editing mode by pressing escape esc key. Then type :wq <filename> (write, quite, and replace <filename> with your own filename) and hit enter.
  5. Now, the vim editor will close and your file will saved in the Windows user directory:

In conclusion, Vim is a powerful text editor that can be used to create new files. To create a new file using Vim, simply open Vim and use the :wq command. This command will save the file and exit Vim.