What are the Differences Between Vi and Vim?

  • HOME
  • >
  • LINUX
  • >
  • What are the Differences Between Vi and Vim?
Last Updated: 
subscribe to my newsletter

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 ex commands.

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.

Multi-level undo

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.

See the Undo and redo documentation for more about undo, redo, and undo-tree.

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 i or a. Vim fixes this by allowing you to use the arrow keys to move around in a file while in insert mode.

Macros

Vim support macros which allow you to record a series of commands and repeat them any number of times. See :help complex-repeat.

Visual mode

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 :help :quit.

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.

Command-line completion

Vi does not support command line completion while Vim allows you to use the Tab key to complete commands, options, and filenames as needed.

Horizontal scrolling

When the 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 set encoding=utf8.

Additionally Vim can also display text right to left (RTL) for languages that require it using :set rightleft. You can reverse a text using :%!rev.

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
  • Viminfo
  • Mouse support
  • Graphical User Interface (GUI)
  • Scripting language
  • Plugins
  • Syntax highlighting for many programming languages
  • Extended regular expressions
  • Integrated Spell checking
  • Diff mode
  • Encryption using the blowfish algorithm
  • Extensive customizable
  • Packages
  • Edit-compile-edit speedup
  • Indenting for many programming languages
  • Searching for words in include files
  • Advanced text objects
  • Folding
  • ctags and cscope integration
  • Integration of several programming languages
  • Asynchronous I/O support
  • Timers

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.

Related linux posts that you may like...
How To Create Simple Menu with the Shell Select Loop?
The select loop is not a regular shell loop. It can be used in Bash to generate a simple menu from which a user can select numbered options.
What is the Right Way to Loop in Bash?
Looping over a list of numbers or words is a building block in shell scripts. Learn how to write Bash loops, including for loop, while loop, and until loop.
What is the Best Way to Count Files in a Directory?
Learn how to count the number of files in a directory using the Linux command line ls, find, and a native bash shell solution with globs and arrays.
5 Mistakes To Avoid For Writing High-Quality Bash Comments
Adding comments in your Bash scripts is necessary to ensure maintainability over time. This post covers 5 Bash comments mistakes to avoid in your shell scripts.