vim (Vi Improved) is a powerful text editor that is used for editing programs and config files written in Python, shell, C, Perl, C++, etc. It is great for the development environment.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux System queries.
In this context, we shall look into the process of installing vim, using it for editing and managing documents, and uninstalling it.
To begin, you need to update the system package database using:
$ sudo apt update
You will be asked for your password before the packages update, enter your password to proceed.
Next, search for vim packages using:
$ sudo apt search vim
You will see a long list of available packages you don't need to install all of them. We will be installing vim, vim-tiny can be installed instead as well.
To install vim, run:
$ sudo apt-get update
$ sudo apt install vim
You will be asked to confirm the installation, enter y.
You can check if vim installed by running:
$ vim --version
How to Open vim ?
To open the vim editor, run:
$ vim
You can see the vim version along with some helpful commands.
How to Create a file using vim ?
To create a new file, use:
$ vim {filename}
When you run the above command, the file opens in the vim editor.
When you try typing in anything in the editor, you won't be able to. That's because vim opens in normal mode. Vim has four modes, we will look at each.
Vim Normal mode
When you open vim it is in normal mode. You cannot enter text in this mode, you can only view the document. To enter normal mode, press Esc.
Vim Visual mode
This mode allows you to select and manipulate text. You can enter visual mode by pressing either one of the following keys:
Vim Insert mode
This lets you edit text. You can enter insert mode through the following keys:
Vim Command mode
This mode is used for saving documents, searching, quitting the program, etc. You can enter this mode using :.
Here a couple of common commands:
How to Edit a Document using Vim ?
Now that you are familiar with the modes, let’s edit our file.
Open the file using:
$ vim {filename}
Enter insert mode by pressing i. Enter your text.
To save and exit the editor, press the escape key, followed by :wq, and then hit enter.
The following commands will help you with editing:
You can also add text to your file when creating it. Use:
$ echo {your text} >> {filename}
How to Uninstall vim from Linux ?
To uninstall vim from your system, use:
$ sudo apt remove vim
You will be asked for your password before proceeding.
Next, you will need to enter y to confirm the uninstallation.
This article covers how to install vim, followed by some basics on using vim and then uninstalling it. Vim (Vi IMproved) is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing config files and programs written in shell, python, perl, c/c++ and more.
Among the various text editors in the world of Linux, Vim (or Vi IMproved) stands out for its versatility and for the functions it offers. In fact, Vim is able to speed up code writing, providing some shortcuts to perform all the operations of modification, deletion or replacement of the text.
Vim Text Editor also allows you to install different plugins through which transforming this simple text editor into a real IDE for programming in different languages.
How to Install vim using apt on Linux ?
1. Open terminal application. You can also press CTRL+ALT+T keyboard shortcut.
2. Update package database by typing the sudo apt update command.
3. Search for vim packages run: sudo apt search vim.
4. Install vim on Ubuntu Linux, type: sudo apt install vim.
5. Verify vim installation by typing the vim --version command.