Did you know that Vi is part of the POSIX standard? Vi, with its numerous implementations, is by far the most distributed and used text editor. This post covers the key improvements of vim over the vi standard.
What are Vi, Ex, and Vim?
Ex stands for EXtended. It is a line editor. The need for the
ex command line came from the early days where computers where using printing terminals instead of screens. People were working with line numbers and editing individual lines as needed.
Vi stands for Visual. It is a text editor that is an early attempt to a visual text editor.
Vim stands for Vi IMproved. It is an implementation of the Vi standard with many additions. It is the most commonly used implementation of the standard. Most Linux distributions come with Vim already installed.
ex is essential to
vi as it is used for core functions like search and replace, for example when using
:%s/AAA/BBB/g. In Vi and Vim, the ex mode is similar to a command line mode which allows you to enter
Vi and Ex are part of the POSIX standard and a Unix implementation of that standard. Vim is the most commonly found implementation of the standard on Linux systems. Often, the command
vi will start the
vim command. Nowadays, Vim is also found on most Unix systems and macOS. The improvements in
vim are not part of the Vi/Ex POSIX standard although Vim is said to be 99% Vi compatible.
What are the differences between Vi and Vim?
In general, Vim will start by default in a Vi compatibility mode which can be disabled. To benefit fully from Vim improvements you may need to disable the Vi compatibility mode with the command
:set nocompatible or by starting
vim with the
-N option. The
compatible mode will be automatically turned off when a
.vimnrc configuration file is found.
Improved features of Vim over Vi
Below is a non-exhaustive list of the most notable improvements of Vim over Vi.
Somehow, Vi only implements one level of
undo using the command
u. Which means that you can only undo the most recent action you did. This is quite limiting. Vim provides a multi-level undo which by default goes up to 1,000 changes remembered. This value can be changed with the option
undolevels. With Vim, you can also
redo the changes using the Ctrl+r, and multiple levels of changes can be branched in an
undo-tree to go back to any state of a text without risk of a loss.
Undo and redo documentation for more about
Tabs, Multiple windows and buffers
Vim allows you to display files in separate windows and can be grouped in tabs. To open files in separate windows, you can use the
-o (horizontal split) or
-O (vertical split) options, for example
vim -O file1.txt file2.txt. Also, when starting Vim as
vim -p filename ... it will open each file in separate tabs.
See the Editing with multiple windows and buffers and Editing with windows in multiple tab pages documentations.
Flexible insert mode
When using Vi in insert mode, you cannot move around without first hitting Esc then again
a. Vim fixes this by allowing you to use the arrow keys to move around in a file while in insert mode.
Vim support macros which allow you to record a series of commands and repeat them any number of times. See
Vim supports a visual mode with highlighting. Once a section is highlighted, you can perform operations on this section only.
Online help system
Vim comes with a very detailed and complete help system. To get started, just type
:help. You can easily navigate between sections by positioning the cursor on a
|tag| and hitting Ctrl+]. You can also navigate directly to some command and sections, for example
Command-line editing and history
Vi does not come with command line history. This is quite a limiting factor. The Vim command-line editing and history allow you to search through your previous commands, repeat them, or edit them before executing them again.
Vi does not support command line completion while Vim allows you to use the Tab key to complete commands, options, and filenames as needed.
wrap option is turned off (
:set nowrap), long lines of text can be scrolled horizontally.
Unicode and internationalization improvements
Vim support for Unicode encoding and uses internally an utf-8 encoding. you can set encoding on a file using
Additionally Vim can also display text right to left (RTL) for languages that require it using
:set rightleft. You can reverse a text using
Vim Advanced user features
Beyond the generic features improvements, Vim also provides advanced features for power-users which can heavily increase your velocity, improve your development workflow, and your ability to customize Vim.
- Text formatting
- Completion in Insert mode
- Jump tags
- Automatic commands
- Mouse support
- Graphical User Interface (GUI)
- Scripting language
- Syntax highlighting for many programming languages
- Extended regular expressions
- Integrated Spell checking
- Diff mode
- Encryption using the blowfish algorithm
- Extensive customizable
- Edit-compile-edit speedup
- Indenting for many programming languages
- Searching for words in include files
- Advanced text objects
- ctags and cscope integration
- Integration of several programming languages
- Asynchronous I/O support
More differences between Vim and Vi
As we saw, Vim brings a lot of improvements over the standard Vi which makes Vim a powerful text editor. For a complete and detailed list of differences and improvements, read the official Differences between Vim and Vi document.
👉 If you need a refresher on the most useful Vi/Vim commands and shortcuts? Check my Vi and Vim Cheat Sheet.