Vim and Vi are both text editors available in Linux. Vi stands for Visual since it is a visual editor. Vim is short for Vi Improved. The two editors are very similar to each other. However, Vim offers some additional functionalities over the Vi editor.
In this tutorial we will look at the differences and similarities between the two.
Table of Contents
- 1 What’s similar in VIM and the VI editor
- 2 Improvements in Vim – The differences between VIM vs VI
- 3 Conclusion
What’s similar in VIM and the VI editor
Let’s look at the points of similarities between the two editors.
Opening a file VIM vs VI
The way to open a new or an existing file is the same for the two. The syntax is as follows.
To open a new file in Vi editor use:
To open a new file in Vim editor use:
Editor Interface VIM vs VI
Both the editors are similar in their appearance.
Vi editor screen looks like as shown.
The screen in Vim editor looks like as shown.
You can see that there is no difference in the appearance of the two.
Modes in VIM vs VI
Both the editors are mode based, that is you need to enter INSERT mode to edit and COMMAND mode to perform actions like saving and undo.
The three modes are as follows:
- Normal (Default): For navigation
- Insert: For inserting and modifying text
- Command: For Operations like saving, exiting, etc.
By default, you are in Normal mode. In normal mode, you can just view your text and navigate through it (more on that later).
Insert mode allows you to make changes to your content.
The command mode is for specifying commands to exit, save your work, and perform other operations.
To enter command-line mode hit the “Escape” key and then type in the colon ‘:’. To enter insert mode, hit the “Escape” key and type in ‘i’. To enter Normal mode press Escape.
Shortcuts for navigating within VIM vs VI are the same.
|h||Move the cursor to left by one position|
|i||Move the cursor to right by one position|
|j||Move the cursor to downward direction by one line|
|k||Move the cursor to upward direction by one line|
Searching for text
Both the editors provide the option to search for text in the file.
To search in the file you must be in command line mode. So start by pressing colon (:).
To search for a word use forward slash followed by the word to search followed by enter.
Improvements in Vim – The differences between VIM vs VI
Vim editor differs from Vi editor since it provides a lot of improvements over the latter. The command to display the points of difference within the Vim editor is:
You can scroll through the list to go over the differences.
In this tutorial, we are going to look at some of the major improvements offered by Vim.
Multiple Undo in VIm
Vi editor only offers the option to perform one undo. This can be very limiting in the case of a large text file.
Vim editor on the other hand offers the ability to perform multiple undo.
Vim provides a multi-level undo which by default goes up to 1,000 changes.
The command to perform undo is :
Portability and Cross-Platform Availability
Vi is only available on Unix. Whereas, Vim works on MS-Windows, Macintosh, Amiga, OS/2, VMS, QNX, and other systems. Vim also works on every Unix system.
This portability of Vim makes it much more popular as compared to the Vi editor.
Vim offers the ability to highlight syntax in the buffer. This improvement over Vi comes in handy for programmers using Vim to write/edit code.
To enter syntax highlighting mode in Vim first enable command mode using colon (:).
Then type the following:
To disable syntax highlighting type :
Flexible insert mode
Vi editor does not allow navigation using arrow keys while in insert mode. That makes Vi editor inconvenient to navigate around in insert mode.
Vim editor on the other hand allows navigation using arrow keys in inset mode.
Vi editor does not give you the option to go through commands you have executed.
Whereas Vim editor lets you go through command history, redo the commands or edit then redo the command.
Visual mode lets you highlight a piece of text and then perform operations on it.
To start Visual mode in Vim editor use v or V.
Vi editor does not have a visual mode.
This tutorial was about the differences and similarities between Vim and Vi editor. To learn more about the differences read this official document. Check this writeup to learn some of the interesting VIM commands.