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?
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.
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?
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
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 3: Now, click on the gvim_9.0.0000.exe file which is a current version for Windows as shown below.
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.
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 ).
sudo apt-get install Vim
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
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
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
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
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
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. |