If you’re coming from macOS to Ubuntu, you might be familiar with the Vim text editor. Ubuntu 20.04 doesn’t come with Vim installed out of the box. You need to perform the standard procedure of updating your packages database, getting the Vim package, and then installing it.

Vim is an open-source and easy-to-use text editor. It is available on almost all of the Linux distributions available today. It comes with comprehensive documentation and an extensive community to help guide you through any questions you might have. You can view and edit the contents of any configuration file via Vim. It is extensible and customizable to a great extent, offering you functionality no one can compete with. It even comes with portable configurations that you can use on all your Linux Computers.

So, with the benefits out of the way, let’s take a look at how to install Vim in Ubuntu 22.04 and use it.

Installing Vim on Ubuntu

To start the process, you need to run:

$ sudo apt update

<img alt="Update packages" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-1.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="108" src="data:image/svg xml,” width=”682″>

Running this will update the packages database, and make it easier for the system to locate the Vim package for installation.

Once you get the prompt back, you are ready for the next step.

Depending on the available space, you can either install “vim” or “vim-tiny”. You can use respective commands to install both

$ sudo apt-get install vim
$ sudo apt-get install vim-tiny

For this guide, I will be installing the “vim” package.

<img alt="Install Vim" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-2.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="435" loading="lazy" src="data:image/svg xml,” width=”716″>

Vim will take up 34.6 MB space on your hard drive after installation. Once you confirm that you want to proceed, Ubuntu will start fetching and installing the package components. As always, once you get the prompt back, it indicates that the installation has completed.

Verifying the installation

Once the installation has completed, you can go and run the following to get more information about the version installed:

$ vim –-version

<img alt="Get version number of installed Vim package" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-3.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="27" loading="lazy" src="data:image/svg xml,” width=”318″>

You can see the version and the included patches:

<img alt="Vim version" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-4.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="91" loading="lazy" src="data:image/svg xml,” width=”617″>

This detail is followed by all of the included options that you can use with your Vim installation.

Starting Vim Editor

To start Vim, you can type:

$ vi

And it will launch the text editor.

<img alt="Launch Vim" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-5.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="437" loading="lazy" src="data:image/svg xml,” width=”735″>

When you start typing, it will start composing a new document for you.

Opening a file in Vim

Suppose you want to open a text file in Vim. For instance, I have a “test” text file on my desktop.

<img alt="Open text file in Vim" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-6.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="338" loading="lazy" src="data:image/svg xml,” width=”182″>

In a similar scenario, you need to run the following command:

$ vim test

<img alt="Start Vim" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-7.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="76" loading="lazy" src="data:image/svg xml,” width=”360″>

When you press Enter it will open up your text file in Vim.

<img alt="Vim Editor" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-8.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="493" loading="lazy" src="data:image/svg xml,” width=”741″>

Changing a text file using Vim

Now that we have our file open, we can change it. Click on the terminal window and press “i”. You will be notified of the changed status at the bottom.

<img alt="Vim text insert mode" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-9.png" decoding="async" ezimgfmt="rs rscb10 src ng ngcb10" height="40" loading="lazy" src="data:image/svg xml,” width=”115″>

You are now in edit mode. You can edit the text to anything you prefer and fill up the file. For instance:

<img alt="Insert text" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-10.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="485" loading="lazy" src="data:image/svg xml,” width=”731″>

Saving a file in Vim

Now when you want to save your file, press “Esc” and it will bring you out of the edit mode. Now type:

:w

<img alt="Save file" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-11.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="502" loading="lazy" src="data:image/svg xml,” width=”755″>

This will save your changes to the file. If you want to save and close the file, you can type:

:wq

Executing this will save the changes to the file and close the vim editor.

<img alt="Save file and quit editor" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-12.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="95" loading="lazy" src="data:image/svg xml,” width=”457″>

Exiting without saving

You can discard your changes and exit the file without saving anything. This is our current content in the file:

<img alt="Exit Vim" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-13.png" decoding="async" ezimgfmt="rs rscb10 src ng ngcb10" height="97" loading="lazy" src="data:image/svg xml,” width=”290″>

Now let’s add a line:

<img alt="Quit Vim" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-14.png" decoding="async" ezimgfmt="rs rscb10 src ng ngcb10" height="129" loading="lazy" src="data:image/svg xml,” width=”277″>

Now press the “Esc” key and type:

:q!

Now when you open up the file again with “vim test” it will not have the added line:

<img alt="Quit force" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-15.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="107" loading="lazy" src="data:image/svg xml,” width=”383″>

Editing Configuration Files with Vim

Vim is one of the many versatile tools in the belt of a system admin. I wanted to add this section to highlight the fact that you can open up and edit configuration files with Vim. If you have found yourself asking this question on the internet “Which text editor can be used on Ubuntu 22.04 to view and edit the contents of a configuration file?”, Vim has everything that you need. Vim is a very versatile text editor which supports almost all of the text file types out there. Let’s check how to open up a configuration file.

Simply fire up your terminal and type the following to open up any configuration file (Let’s open up the sysctl file for this guide):

$ sudo vim /etc/sysctl.conf

Note that we are opening up a system configuration file, so Vim needs elevated privileges through sudo.

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-16.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="30" loading="lazy" src="data:image/svg xml,” width=”408″>

After providing the password, you will get the file

<img alt="Edit config file" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-17.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="576" loading="lazy" src="data:image/svg xml,” width=”747″>

You can update and save this file using the same commands as before.

Uninstalling Vim

If, for any reason, you want to remove Vim from your system, you can execute the following to remove any traces of Vim from your system:

$ sudo apt-get remove vim

<img alt="Remove vim" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-18.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="348" loading="lazy" src="data:image/svg xml,” width=”720″>

Seeing this prompt is the equivalent of getting asked, “Are you sure?” in Windows. Once you confirm the operation, it will proceed to completely remove Vim and all of its dependencies it. Once you get the prompt back, the uninstall operation has succeeded.

You can even run “vim” to confirm this.

<img alt="Vim uninstalled" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/04/echo/word-image-19838-19.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="64" loading="lazy" src="data:image/svg xml,” width=”424″>

Conclusion

If you have followed these steps, you now know the complete lifecycle of Vim text editor in Ubuntu 22.04. To explore Vim further, navigate to their website at https://www.vim.org/. It contains all the documentation needed and guides for extending and developing plugins.