vim

Vim Reload Vimrc Without Closing

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.

$ vim

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.

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.

$ sudo apt install vim

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.

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)“.

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.

$ touch file.txt

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

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.

$ vim test.txt

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.

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.

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

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

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’.

:wq

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.

:source ~/.vimrc

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.

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

:vs ~/.vimrc

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.

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

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.