Vim is one of the most powerful and popular Linux text editors accessible through a command-line interface. It is an improved version of the old Unix editor ‘vi’ pre-installed on most Linux distributions.
Similar to other command-line-based text editors, it is easy to use and offers more functionality with standard features such as syntax highlighting, search, split editing, multi-level undo/redo, among others.
On Debian and Ubuntu, install Vim with
$ sudo apt install vim
yum on Redhat Enterprise Linux (RHEL) based systems like CentOS, Rocky Linux, Alma Linux.
$ sudo yum install vim
On OpenBSD, FreeBSD, install with
$ doas pkg_add vim
On Arch Linux, use
$ sudo pacman -S vim
Vim offers four modes of operation, the normal, insert, visual, and command-line modes, with different functions accessible with each.
In this mode, basic operations like copying, pasting, changing, and deleting text can be achieved.
Press ESC on your keyboard to enter normal mode.
This mode allows you to edit files, and insert new text in the editor. In this mode, every keyboard character you enter will be added to the file.
There are several ways to enter insert mode, and these are:
Visual selection, highlighting, manipulation of text, and all normal mode commands can be used in this mode.
To enter visual mode, use
v for basic cursor selections, then:
V – To enter visual line mode with an entire line selected.
Ctrl + v – Enter visual block mode with double text selection expandable to multiple lines.
This mode allows you to issue function commands using a colon
After the colon
:, add a command to execute any function in the editor. Below are some of the most common commands to manage files:
To open files, simply run
vim with the filename as an argument.
$ vim [file_name]
Also, you can open multiple files, and use
bp navigation commands to switch between files.
$ vim [file_name] [file_name] [file_name]
insert mode by pressing
i to edit the file and enter text.
Other editing functions can be performed in normal mode, such as deleting, copying, and pasting text with single or double-character commands.
It’s possible to navigate in Vim using keyboard arrow keys, but with navigation commands available in normal mode, you can swiftly move the cursor around, and below are the common keys.
You have successfully installed Vim on your cloud server. For further documentation, run
vimtutor in your server console for more powerful techniques on how to use the text editor.