Vim is indeed a popular text editor widely used in the command-line interface of Linux operating systems. Since Linux makes heavy use of configuration documents, you’ll have o modify them regularly, and Vim has become an excellent tool for doing so. Vim seems to have a distinct operational technique, with two key modes. One of them is command mode, and the other one is a merge of all additional modes. In this discussion, we will discuss the process of creating a Vim file using the Vim text editor in the Linux System.

Prerequisites:

Make sure to have any Linux distribution installed on your operating system, e.g., we are using Ubuntu 20.04 for this example. Also, ensure to have a root account created in the Linux system. Login from the Linux root account to start working on Vim without any problem.

Install Vim Utility:

Right after you login from your root account or any account of the Linux system, go to the upper left corner in the Activity area. You will have a search bar there. Type the word “terminal” in this search area and hit the “Enter” using your keyboard. You can also use the shortcut key Ctrl Alt T to open it. Now, you must check whether the Vim text editor is already installed on your Linux system or not. For that, you have to try out the below “vim” command in the terminal. The output screen shows that it is not installed yet and also provides some of the commands to install it. Hence, you have to install it first to work on it.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-260.png" data-lazy- height="185" src="data:image/svg xml,” width=”611″>

So, to install the Vim editor on your Linux distribution, you have to try out the below-mentioned command in your command terminal. The installation process needs the password of the root account to make changes to the system. Therefore, you need to type the password next to the line: [sudo] password for account_name, and press the “Enter” via keyboard. It will start the installation process.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-261.png" data-lazy- height="53" src="data:image/svg xml,” width=”520″>

Meanwhile, it will affirm the installation action by throwing a question in the middle of the installation process, e.g., Do you want to continue? [Y/n]. To install the Vim editor, type the “Y” key from the keyboard, or hit the “N” button to stop execution. As we pressed the “Y” key, it starts working again on the installation of Vim.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-262.png" data-lazy- height="39" src="data:image/svg xml,” width=”409″>

Sit back and relax while the setting up has been accomplished. The completion of the Vim installation can be similar to the output shown in the image underneath.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-263.png" data-lazy- height="55" src="data:image/svg xml,” width=”720″>

Again try out the “vim” command as below.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-264.png" data-lazy- height="16" src="data:image/svg xml,” width=”369″>

You can see that it has been properly installed as below.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-265.png" data-lazy- height="418" src="data:image/svg xml,” width=”623″>

Create Vim File:

To create a new Vim file, you have to use the vim command and the name of a file you want to create. This file can be of any type and extension. Make sure to navigate towards the directory where you want to save this file. Suppose, you want to create a file “new.html” in the Home directory of your Linux system using the vim command having “html” as an extension. Type the below command to create it via Vim editor and hit on the “Enter” button.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-266.png" data-lazy- height="15" src="data:image/svg xml,” width=”474″>

Right after hitting the “Enter” button, you will get a new window as shown in the below snapshot. This new window is an interface of the newly created file “new.html”. The lower side of the header shows the name of this file as “new.html”. You will see that you would not be able to do anything on it because you have a normal mode opened at the moment. To add some data or text to it, you have to jump to its “Insert” mode by pressing the “i” key from the keyboard.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-267.png" data-lazy- height="566" src="data:image/svg xml,” width=”709″>

The insert mode is something like the picture in the snapshot below. You can see that the insert mode allows you to write something in this file. You can also see a mode writer’s name at the most left corner of the vim file.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-268.png" data-lazy- height="579" src="data:image/svg xml,” width=”711″>

Now, you have to add some data or text in this file to see if it’s working in an insert mode. Suppose, we have added the below text in this file as presented in the picture. After editing, you have to save this text in the “new.html” vim file. For that, you need to jump to a normal mode again. That is why you need to press the “Esc” key from your typewriter to exit from the Insert mode of Vim editor. This will navigate you to the normal mode, and you will see that the “INSERT” keyword will be removed from the bottom part of the Vim file.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-269.png" data-lazy- height="112" src="data:image/svg xml,” width=”495″>

You need to save this data into this vim file, e.g. “new.html” and also quit the file. For this purpose, we need to add the “wq” command along with the colon “:” sign as shown below. In this command, “w” stands for writing the data and “q” stands for quit the file. So, add the below “:wq” command and hit the “Enter” key to save and quit the file. You can see this command at the most left bottom side of the Vim editor.

:wq

<img data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-270.png" height="19" src="data:image/svg xml,” width=”199″>

Finally, you are out of the Vim editor, and your vim file “new.html” has been saved into the Home directory. You can check for your vim file in the Home directory. The below image shows the newly created vim file in the Ubuntu 20.04 Linux distribution’s Home directory. You can open it using any browser to see how its code works.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/word-image-271.png" data-lazy- height="119" src="data:image/svg xml,” width=”612″>

Conclusion:

We have efficaciously set up the Vim editor in our Ubuntu Linux system and perform all the necessary steps to create a Vim file using the Vim editor in this tutorial.

About the author

<img alt="Aqsa Yasin" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/Author-Image-150×150.jpg607e25cfa7d6c.jpg" height="112" src="data:image/svg xml,” width=”112″>

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.