Cyber Month Deal - up to 36% OFF

How to Install and Use Vim on Ubuntu | Step-by-Step

Published on Oct 26, 2023 Updated on Aug 13, 2024

Vim is cherished by developers, system administrators, and power users for its adaptability and extensibility. This step-by-step guide shows how to install Vim on Ubuntu 22.04. Besides navigating the installation of Vim on the latest version of Ubuntu, we provide a comprehensive exploration of Vim basics and customizations.

What is Vim?

Vim, short for Vi IMproved, stands out as an exceptionally versatile, powerful, and efficient text editor. First released in 1991 by Dutch software engineer Bram Moolenaar, Vim is focused on efficiency through modal editing and extensive customization options.

Vim's lightweight and customizable nature and its powerful features make it a powerful editor of choice for many Linux users and administrators. Follow the below steps to learn how to install Vim on Ubuntu as well as how to use Vim in various ways.

Prerequisites

You will need the latest Ubuntu to follow along with this tutorial.

1. How to install Vim on Ubuntu?

Let’s begin and install Vim on Ubuntu 22.04 in three steps:

Step 1: Update the package list

Before installing any software, we will update the package list using the following command in your terminal:

sudo apt update

You might be prompted to enter your password for authentication.

Step 2: Install Vim

To install Vim, enter the following command:

sudo apt install vim -y

This command will retrieve and install Vim and its necessary components.

Step 3: Verify the installation

Once the installation is complete, verify that Vim has been properly installed by running:

vim --version

You'll be presented with information regarding the Vim version you've installed, along with its compiled features.

2. How to use Vim: Basic

Here are some basic steps to get started with Vim:

Section 1: Creating a file

To create a new empty file, enter the vimcommand:

vim example.txt

vim

Press i to enter insert mode and start wiring. We will now proceed to the next sections, where you will learn about Vim modes and how to save and exit the application.

Section 2: Modes

Vim has three modes: Normal mode, Insert mode, and Visual mode.

Normal mode: Vim opens in Normal mode by default. It is the ideal mode for text manipulation, and command execution. Press Esc to switch to this mode. Insert mode: Insert mode is used to write content in your document. To switch to Insert mode from Normal mode, pressi. Visual mode: Visual mode is used to select and edit text. You can switch to Visual mode from Normal mode by pressingv.

Section 3: Navigation

In Normal mode, navigation is done with the arrow keys or h, j, k and l. For instance, to move the cursor to the end of a line, strike $, and to move to the beginning, press 0. To navigate word by word, use w to move forward and b to move backward.

Section 4: Editing

Deleting a character is as simple as ABC. Hover over the character in Normal mode and hit x. To copy (yank) a line, position your cursor on the line and type yy. To paste the copied text, move the cursor to the desired location and press p.

Section 5: Saving and exiting

To save your content, switch to Normal mode and type :w. To save and quit, type :wq. If you need to quit without saving changes, type :q!.

3: How to use Vim: Advanced

Here are some more advanced ways to use Vim:

Section 1: Customizing Vim

Vim is known for its customizability, which is done mainly by editing .vimrc file in your home directory. For instance, you can enable syntax highlighting and add plugins.

Let's add line numbers in Vim. Open the configuration file:

vim ~/.vimrc

Insert the following configuration options in the file:

set number

Now, save and quit vim by typing :wq

set number

Section 2: Searching and replacing

Vim has a rich search and replace feature. In Normal mode, start a search by entering / followed by your search term. For instance, to locate occurrences of the word "example" in your document, key in /example and hit Enter.

To replace all instances of "old" with "new" throughout your document, use the following command:%s/old/new/g.

Section 3: Multiple windows and tabs

Vim lets you divide your workspace into multiple windows and organize it using tabs. To split your workspace horizontally, use :split, and for a vertical division, opt for :vsplit.

split vsplit

Vim also has a tab feature. To open a new tab, type:tabnew.

Toggle between tabs using :tabn and :tabp.

Conclusion

In this guide, we've covered how to install Vim on Ubuntu 22.04, the latest version of Ubuntu, and how to use Vim, in both basic and advanced ways. We have also seen how efficient and customizable Vim can be, especially in server environments where most of the work is done on a terminal. While using it can be daunting at first, a good mastery of the application will boost your productivity in text manipulation. You can learn Vim while playing a game using Vim adventure!

Cloud VPS - Cheaper Each Month

Start with $9.99 and pay $0.5 less until your price reaches $6 / month.

Share this article

Related Articles

Published on Jun 7, 2021 Updated on Jun 29, 2022

AlmaLinux Review: a CentOS Clone Supported by CloudLinux

AlmaLinux is an open-source Linux distribution focused on long-term stability, that is a 1:1 binary compatible fork of Red Hat Enterprise Linux (RHEL)

Read More
Published on Sep 14, 2021 Updated on Jun 29, 2022

Debian 11 "bullseye" Review: What‘s New?

Debian 11 “bullseye” was released on 14th of August 2021. This release contains over 11294 new packages out of 59551 packages overall in its repositories.

Read More
Published on May 31, 2022 Updated on May 5, 2023

A Complete Guide to Linux Bash History

Learn how to work with Bash history to become more efficient with any modern *nix operating system.

Read More
We use cookies to ensure seamless user experience for our website. Required cookies - technical, functional and analytical - are set automatically. Please accept the use of targeted cookies to ensure the best marketing experience for your user journey. You may revoke your consent at any time through our Cookie Policy.
build: 06ac5732e.831