Vim Tutorial: Features, Advantages and Disadvantages

In this article, we will discuss about Vim Text Editor in detail with its features, commands, modes, advantages and disadvantages. Here, you will also learn how to install Vim on Windows and Linux (Ubuntu) Operating system.

What is Vim?

Vim is a short form of Vi IMproved. This editor is one of the most famous text editor in today’s era.
It is an open-source software and everyone can use it freely. Vim editor is released under a license, which is suitable with the GNU General Public License.
This text editor is used for the command-line, which creates and views the text files. This text editor is an advanced version of Vi. Like the Vi editor, this software is also a command-centric editor.
It is introduced by Bram Moolenaar on 2nd November in the year of 1991. This text editor is developed in C programming language and Vim Script. It is developed to allow the efficient text editing. It is also designed to use as a standalone application in a GUI ( Graphical User Interface ).
This text editor is also especially suited for editing the programs of a computer. It is available on the following platforms:
1. Windows
2. Linux
3. Mac OS
4. Unix
In the year of 2006, this software is voted as a most popular text editor. And in the year of 2019, it became the 5th most popular development environment.

Why Use Vim?

Following are the various why you should use Vim as a text editor:
1. You can easily remember the commands of Vim editor using simple mnemonics. Some commands like i, d, and q which are used to insert, delete and quit. These commands are easy to learn as compared to commands in other editors.
2. This text editor includes the syntax highlighting.
3. You can easily use the Vim with GUI as well as TUI.
4. Vim text editor is cross-platform. Means, it is available on Linux, Windows, Unix, and Mac operations systems. If we have learnt once how to use Vim, then we can easily run it on any platform.
5. Vim allows users to do things quickly and simply. If you know that how it works, then you can easily and quickly make complex edits.
6. The main and important reason to use is Ubiquitous.

Features of Vim

Following are the various features or characteristics, which are provided by the Vim text editor:
1. You can easily undo the last change by using the u command in the command mode.
2. The % (percentage) feature which helps the programmers in the different ways.
3. You can easily repeat the last change in the normal mode by using the (.) command.
4. It also allows a programmer to open the multiple windows for opening the multiple files at the same time.
5. In the normal mode, CTRL + W option allows you to open the same file in another split window.
6. It also allows you to execute the terminal commands from the vim without closing a file.
7. Sometimes, there is a need to find the next or previous occurrences of a word in the text file. So, vim text editor also provides the two different commands (# or *) for finding the next or previous occurrences.

Installation of Vim

You can easily install the Vim on a different platforms or operating systems. Here, we will describe the installation of Vim on Windows system and Ubuntu-based Linux operating system step-by-step.

Installation of Vim on Windows

This software does not need any particular requirement, so you can start installation using the following steps which help to run Vim on Windows operating system:

Step 1: First you have to download the Vim from the following site:
Step 2: Then, click on the download option which is available in the left pane of the site as shown in the above screenshot.
Step 3: Now, click on the gvim_9.0.0000.exe file which is a current version for Windows as shown below.
Step 4: Now, the .exe file starts to download. And, after downloading, open .exe file from the Downloads folder.
Step 5: Now, you have to follow the instructions to complete the installation. So, first click the Run button. Then, you have to click Next button to start installation.
Step 6: In this step, you have to accept the license by clicking on the I Agree button.
Step 7: Now, select all options from the given drop-down list.
Step 8: After selecting, you have to select that directory in the computer where you want to keep or store the Vim folder. You can achieve this by clicking on the Browse button. Then, click on the Install button.
Step 9: Now, the vim installation will start.
Step 10: After the installation, there is a pop up on the screen which asks you to see the readme file. If you want to see that file then click Yes otherwise click No. Now, you can easily run Vim from the cmd, i.e., command prompt. To run Vim text editor type the following command in command Prompt:
Vim

Installation of Vim on Ubuntu-Based Linux System

If you want to install the Vim text editor on Ubuntu 18.04 operating system, you have to follow the steps which are given below:
Step 1: First you have to open the terminal using the keyboard shortcut key ( Ctrl + Alt + T ).

Step 2: After then, you have to type the following command with the Sudo privileges:
sudo apt-get install Vim
Step 3: Now, you have to type the password of your system. And, you have to type ‘Y’ each time when it asks during installation.
Step 4: After installation, you can search Vim with the help of search bar and open it.
Step 5: At last, you will notice that Vim is successfully installed in your system.

Commands of Vim Editor

Following are the various type of commands which helps us easy to use the Vim editor in the systems:
1. Basic Vim Commands
2. Commands for Cursor Movements
3. Commands for Editing
4. Commands for Inserting and Appending
5. Commands for Searching and Replacing Text
6. Visual Commands
7. Commands for Working with Multiple Files
8. Other Useful Commands

Basic Vim Commands

These type of commands helps users for opening and closing the documents or files and allows them saving them also. These commands are so simple.

Commands

Description

:e <file_name>

This command opens the specified txt file in Vim editor. If the file does not exist in the system then it creates a new file with the given name.

:help <keyword>

This command shows the relevant information for the keyword which is entered in the command.

:w

This command save that file which is currently working.

:w <filename>

This command allows us to save the current file with a specific name.

:wq or 😡

This command saves the current file and then exits the Vim editor.

:q

This command exits the current window of Vim.

:q!

This command allows us to quits the Vim text editor without saving.

ZQ

This command also quits the Vim editor without checking the changes. It is also same as q!.

Commands for Cursor Movements

These following commands help us to move the cursor in the entire file or document. These all commands are used in the command mode.

S.No.

Commands

Description

1.

b

This Vim command moves the cursor at the starting of the previous word. This command cannot move the cursor at the start, if the word contains punctuation marks.

2

B

This command moves the cursor at the beginning of word if the word contains punctuation marks.

3.

e

This Vim command moves the cursor at the last of the next word. It cannot moves the cursor at the end, if the word contain punctuation marks.

E

This Vim command also moves the cursor at the last of the current word but if the word contains punctuation marks.

fx

This command moves the cursor forwards to the first occurrence of the letter ‘x’ in the same line.

Fx

This command moves the cursor backwards to the first occurrence of the letter ‘x’ in the same line.

G

This Vim command moves the cursor at the starting of the last line in the current document or file.

gg

This command moves the cursor at the starting of the first line in the document or file.

g_

This command moves the cursor in the current line to the last character which is non-blank.

10.

h

This Vim command moves the cursor to the left of next letter.

11.

H

This Vim command moves the cursor at the first line of the current screen.

12.

j

This command moves the cursor down only one line.

13.

k

This Vim command moves the cursor to the upper line on the exact position.

14.

l

This Vim command moves the cursor to the right of next letter.

15.

L

This Vim command moves the cursor at the last line of the current screen.

16.

M

This Vim command moves the cursor to the middle or midline of the current screen.

17.

w

This command moves the character at the beginning of the next word. This command cannot move the cursor at the start of the next word if the current word contains punctuation marks.

18.

W

This Vim command moves the cursor at the beginning of the next word when the word contains punctuation marks only.

19.

0

This Vim command moves the cursor at the beginning of the current line.

20.

^

This vim command moves the cursor in the current line to the first character which is non-blank.

21.

$

This Vim command moves the cursor to the last character in the current line if the character is either blank or non-blank.

22.

)

This Vim command moves the cursor to the begin of the next sentence.

23.

(

This Vim command moves the cursor to the begin of the previous sentence.

24.

{

This Vim command moves the cursor to the beginning of the previous paragraph or a text block.

25.

}

This Vim command moves the cursor to the beginning of the next text block or a paragraph.

26.

Ctrl + e

This shortcut key moves the screen down only one line. It does not move the cursor.

27.

Ctrl + y

This shortcut key moves the screen up one line. This command

28.

Ctrl + d

This shortcut key scrolls or moves forward half (1/2) a terminal screen.

29.

Ctrl + u

This shortcut key scrolls or moves back half (1/2) a terminal screen.

30.

Ctrl + f

This shortcut key scrolls or moves forward full terminal screen.

31.

Ctrl + b

This shortcut key scrolls or moves back full terminal screen.

Commands for Editing

Vim text editor provides the various following features which allows users to edit their documents in an easy and effective way. The following table gives the various commands for editing:

S. No

Commands

Description

1.

. (dot)

This command is used to repeat that command which is recently executed.

2.

C

This Vim command deletes all the characters or words after the current position of the cursor and takes us to Insert Mode for inserting the new text.

3.

cc

This command deletes all the characters (whole line) in that line in which cursor is current present. And then, takes us to Insert Mode for inserting the new text.

4.

ciw

This Vim command deletes the entire word in which the cursor is currently see. And then, takes us to Insert Mode for inserting the new text.

5.

cw

This command deletes all the characters from the current position of the cursor till the last character of the word. And then, takes us to Insert Mode for inserting the new text.

6.

D

This Vim command removes all blank and non-blank characters from the current position of the cursor in the current line.

7.

dd

This Vim command deletes the entire line in which the cursor is currently available.

8.

ndd

This command deletes nth line.

9.

dw

This Vim command deletes the characters from the current position of the cursor till the begin of the next word.

10.

d-

This command deletes the current line and the line which is present above the current line.

11.

dfd

This Vim command deletes all the characters between the current position of the cursor and the first occurrence of the letter ‘d’. It also removes ‘d’ character and the character from the current position of the cursor.

12.

db

This Vim command deletes the characters from the starting of the word till the current position of the cursor.

13.

d^

This Vim command deletes the characters from the first non-blank character of the current line to the current position of the cursor.

14.

gJ

This command joins the below line at the end of the current line without giving space between them.

15.

J

This command joins the below line with the current line by giving one space between them.

16.

r

This Vim command replaces the current position of the cursor.

17.

s

This command deletes the character and substitute text. And, then takes us to the Insert Mode.

18.

S

This command works the same as cc command.

19.

u

This command is used for undo operation.

20.

X

This command deletes only one character from the left of the cursor.

21.

x

This command deletes the character from the current position of the cursor.

22.

Ctrl + r

This shortcut key is used for redo operation.

Commands for Inserting and Appending

Vim text editor provides the following commands which allow the users to insert and append the characters or words at the different positions in the current working document or file:

S. No

Commands

Description

a

This command appends the characters or words after the cursor.

A

This command appends the text to the end of the current line. When we use this command, Vim automatically takes to the Insert mode allows us to append the text. Press Esc command for terminating the Insert Mode.

ea

This command appends the text to the end of the current or next upcoming word in the current line of a file or document.

Esc

This command exits or terminates the Insert mode.

i

This command inserts the text at the current position of the cursor.

I

This command inserts the text at the beginning of the current line.

o

This command opens a new line for appending the text below the line in which cursor is currently present.

O

This command opens a new line for appending the text above the line in which cursor is currently present.

Commands for Searching and Replacing Text

S. No

Commands

Description

n

This command searches the item in the same direction of the last search.

N

This command searches the item in the opposite direction of the last search.

/word

This command searches the given word from top to bottom in the file or document.

?word

This command searches the given word from bottom to top in the file or document.

/j[ts]p

This command searches the word ‘jtp’ or ‘jsp’. This command specifies a word which is come first in searching.

/ \<or

This command searches the word like or, oracle, orange, etc in the file.

:%s/old/new/g

This command replaces all the given old words with the given new word throughout the file.

:%s/old/new/gc

This command asks for confirmation replaces all the given old words with the given new word throughout the file.

:s/old/new/gi

This command replaces all the old words or characters with the new given words or characters within a single line.

:1,10s/old_text/new_text/g

This command replaces all the old words or characters with the new given words or characters within a specified range of lines.

Visual Commands

The following table provides some visual commands. To move in a visual mode, we have to press v.

S. No

Commands

Description

>>

This command shifts the text right.

<<

This command shifts the text left.

~

This command changes the case of an individual character. Means, if the character is in lowercase, this command change into uppercase and vice-versa.

d

This command removes the marked text.

y

This command copies the marked text.

p

This command pastes the text which is copied by the ‘y’ command.

Commands for Working with Multiple Files

Vim also provides the following features which help users for editing multiple files at a time.

S. No

Commands

Description

:bd

This command deletes or closes the current buffer.

:bn or :bnext

This command allows us to move to the next buffer.

:bp or :brev

This command allows us to move to the previous buffer.

:e file

This command allows us to edit the file in the new buffer.

:ls

This command allows us to open the list of all buffers.

:sp file

This command allows us to open a file in the new buffer and splitting window.

:vsp file

This command allows us to open a file in new buffer and splitting window in vertical.

Ctrl + ws

This command is used for splitting the window screen.

Ctrl + ww

This command is used for switching the windows.

Ctrl + wq

This command exits or quits a window.

Ctrl + wv

This command is used for splitting the window vertically.

Ctrl+ wh

This command is used for moving the cursor to the left window when the window is vertically split.

Ctrl + wl

This command is used for moving the cursor to the right window when the window is vertically split.

Ctrl + wj

This command is used for moving the cursor to the below window when the window is horizontally split.

Ctrl + wk

This command is used for moving the cursor to the above window when the window is horizontally split.

Vim Modes

Vim text editor provides the following various modes, which help users to run the Vim software:
1. Command Mode (Normal Mode)
2. Insert Mode
3. Visual Mode

Normal Mode

This mode is also known as command mode. This mode is used for editing and saving the text file or document.
When we open the Vim, then this mode will be opened as a default mode. If we are in any other mode and we want to move to this mode then we have to press only the Escape ( Esc ) key from the keyboard.
If we are already in this mode, and we pressed the Escape key from the keyboard then Vim editor will beep and flash the screen.
This mode enables users to copy, paste, or delete a piece of text in the file or document. Using this mode, we can also use the last line commands which begin with the colon (:) sign. This mode also save the changes which are done by us in a file.

Insert Mode

This mode allows users for entering and editing the text. When we are in Insert Mode, then we can easily type or insert the character just like the other regular text editors.
If we are in any other mode and want to move on this mode then we have to press ‘i’ key from the keyboard. When we enter any character in this mode then that character is inserted as an input to the current working file. If we want to move to command mode, then we have to press the Esc key.

Visual Mode

This mode is the same as the command mode but in this mode, we can easily select the text and then run commands on the selected text. If we are in any other mode and want to move to this mode then we have to press only ‘v’  key from the keyboard.
Following are the three types of Visual mode:
1. Plain Visual Mode
2. Block Visual Mode
3. Line-wise Visual Model

Start Vim

If Vim is already installed in your system, then you can easily launch the Vim text editor using the following steps, otherwise, you have to install it on your ubuntu system.
Step 1: Open the terminal using Ctrl + Alt + T shortcut key.
Step 2: Now, type the following command to start the Vim text editor in terminal and you will see the below screen on your system:
Vim
Step 3: The above screen will open in a command mode by default. Now, you have to open the new file or existing file using the following command:
:e <file_name>
Step 4: The file is automatically open in the Command mode.
For inserting the text into the file you have to press the ‘i’ key, so that the file will open in an Insert Mode.
Step 5: Now, you have to insert the data or information into the file by key. Everything you have typed is inserted automatically in the file.
When the data is successfully inserted, press Esc button to move back to Command Mode. The following screen shows the command mode:
Step 6: In the command mode, you have to type the ‘:wq’ command to save the file in the system and to close Vim editor.
Step 7: You can see your file with the help of following cat command:
cat <file_name>

Advantages of Vim

Following are the various advantages or benefits of Vim text editor:
    • Open-source software: This software is not only a free, but it is also available for all the operating systems in any one of the Terminal mode or GUI mode. It is also suitable with the GPL charityware.
    • We can easily perform the complex tasks which are related to text with the few commands given by Vim.
    • This text editor is highly configurable.
    • This text editor is very popular in the Linux or Unix word.
    • As compared to other editors which are good in graphics like Sublime and Atom, it is fast. This text editor is also faster than Emacs.
    • This editor is also working in a terminal over SSH.
    • We do need to use the mouse and Ctrl/Alt keyboard buttons again, because it provides the mouse-free interface. It is keyboard-based and also supported by the trackpad.
    • If we want to log into SSH, we can easily run Vim with a terminal and also with the GUI.
    • It is light-weighted, compact and excellent performance, because, it easily and quickly replaces all the occurrences of the string in the files which are more than 100 MB.
    • In this text editor, everything is mnemonic, because there is a series of actions, or verbs or nouns. So, mnemonic makes it easy to use easily.
    • It provides the multiples distinct modes for the editing. Following are some editing modes:
        ◦ Normal Mode
        ◦ Command Mode
        ◦ Visual Mode
        ◦ Insert mode

Disadvantages of Vim

Following are the various disadvantages or limitations of Vim text editor:
    • This text editor is difficult to use for the beginners.
    • There is a difficulty to learn all the command and modes which are supported in Vim. So, we have spent a lot of time in learning.
    • This editor takes some minutes to open those files which contain a lot of very long lines, but other few text editors can load the same file in a few seconds.
    • In this text editor, when working with the large files there is no smooth scrolling.
    • It consumes the energy of the brain for editing, which should be basically used for the logics.
    • In this text editor, it is difficult to copy, paste and delete the text.

Leave a Comment