Vim is a versatile, fully accessible text editor that is also Vi-compatible. It is being used to make changes to any form of document. It comes in handy when modifying C/Perl/Python programs. It can also be used to modify configuration documents in Linux/Unix systems. /.vimrc is a document that you can use to configure and launch Vim. This article will show you how to update and reload the vimrc document in Linux despite rebooting the Vim editor.

Prerequisites:

Make sure you have any Linux distribution installed on your operating system, and you must have sudo privileges to use it. We have Ubuntu 20.04 installed and configured on which we will perform the Vim reload.

Install Vim:

Log in from the Ubuntu 20.04 Linux system and navigate the activity area where you will get a search bar. Type the word ‘terminal’ in it to get a command-line shell terminal. Upon showing the terminal app, click it to launch. Now the terminal app is opened, you have to check for the ‘Vim’ utility. We have to use the Vim command to check if it is already installed on your system or not. To do so, let’s try the simple Vim command as below.

The output image shows that the Vim utility is not installed on the system and their latest available version that you can install on the Ubuntu Linux system will be shown. So, we have to install it on our Ubuntu 20.04 first.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image1-20.png" data-lazy- height="184" src="data:image/svg xml,” width=”571″>

We choose the first command listed in the above snapshot to install Vim on our Ubuntu 20.04 Linux distribution. Hence, execute the below sudo apt command in the shell along with the keyword install and name ‘vim’. It will require your root user password to start the installation process of the Ubuntu 20.04 Linux system. Add your password and hit the ‘Enter’ button from your keyboard. The below snapshot image shows that it starts installing.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image3-17.png" data-lazy- height="91" src="data:image/svg xml,” width=”509″>

Between the installation process, it will ask you a question, “Do you want to continue? [Y/n]”. If you want to install the Vim utility on your Linux distribution, you have to press ‘Y’ for yes otherwise, press ‘n’ from the keyboard to answer it. So we pressed ‘Y’ to proceed with the installation of Vim on Ubuntu 20.04 Linux distribution. Relax and wait for some time to get it installed because it takes time.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image2-17.png" data-lazy- height="73" src="data:image/svg xml,” width=”713″>

In the end, the installation of Vim will be completed showing the below output in the snapshot image saying “Processing triggers for man-db (2.9.1-1)“.

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

Launch Vim:

After the successful installation of Vim, it’s time to create a new file. We will be using the “touch” command to create a text file named “test.txt” as presented in the snapshot image below.

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

After the file is created, you can find your file ‘test.txt’ in the Home folder of your directories, as seen below.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image7-13.png" data-lazy- height="189" src="data:image/svg xml,” width=”496″>

Now, we will start the Vim editor using the Vim command in the shell, followed by the file name ‘test.txt’ as shown in the below snapshot.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image6-13.png" data-lazy- height="18" src="data:image/svg xml,” width=”421″>

It will open a Vim editor, and you will get a new screen window as shown in the image having the file name ‘test.txt’ in the below header of it. We have to be in Normal mode to start working, and for that, press the ‘Esc’ key from your keyboard to get into a normal mode.

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

It is time for us to load the configuration file of the Vim editor using the “vs” command. First, in the normal mode, you have to press the colon button “:” to add colon for some commands. Next to the colon sign, you have to add the “vs” command with the navigation sign and backslash sign along with the vimrc keyword next to them. Press the ‘Enter’ key to get into the configuration file.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image8-12.png" data-lazy- height="18" src="data:image/svg xml,” width=”333″>

The vimrc file will be opened as displayed in the appended image. You can see its header having a file name there.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image12-9.png" data-lazy- height="554" src="data:image/svg xml,” width=”716″>

If you want to add some commands to perform some actions, you have to get into an Insert mode of Vim editor. For that, you have to press “i” from your keyboard,and your editor will be inediting mode. Now, you have to add some commands to perform some actions. We have added the below commands in its insert mode to do so. The first line is used for indentation, the second line is used to set numbers to every line, and the last line is used to highlight the syntax.

  • filetype indent plugin on
  • set number
  • syntax on

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image10-11.png" data-lazy- height="101" src="data:image/svg xml,” width=”701″>

This time, you have to save these changes into the configuration vimrc file. Therefore, type the below “:wq” command to write and quit the Vim editor. Your queries are now saved in the vimrc file, and you are back to the Vim editor of file ‘test.txt’.

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image11-9.png" height="43" src="data:image/svg xml,” width=”235″>

Reload Vim:

We don’t need to quit the Vim editor to reload the contents of the ‘Vimrc’ file and apply the changes. You just need to add a simple command to reload it. So, click on the colon “:” button and add the below-source command to reload the vimrc file. Tap on the ‘enter’ button to reload the vimrc file.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image13-7.png" data-lazy- height="25" src="data:image/svg xml,” width=”315″>

Right after you hit the ‘Enter’ button, your vim editor will get updated, and you will see changes in it, as shown in the snapshot beneath.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image14-6.png" data-lazy- height="85" src="data:image/svg xml,” width=”717″>

You can also see the changes using the same “vs” command in the Vim editor as below.

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image15-4.png" height="22" src="data:image/svg xml,” width=”279″>

The configuration file along with the Vim file editor will be opened, and you can see the changes on the right side of the editor window.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/image16-4.png" data-lazy- height="109" src="data:image/svg xml,” width=”719″>

Conclusion

We have done the reload of the Vimrc file without closing the Vim editor. Hopefully, you can easily reload the vimrc file without closing the vim editor by following this guide.

About the author

<img alt="Aqsa Yasin" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/04/echo/Author-Image-150×150.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.