Difference Between VIM and vi


This is a summary of the differences between VIM and vi. It is not complete. see also Reference Manual, look for comments in {}, like "{not in Vi}".

Vim is mostly POSIX 1003.2-1 compliant. The commands known to be missing are "Q", ":append", ":change", ":insert", ":open" and ":z". There are probably a lot of small differences.

THE MOST INTERESTING ADDITIONS

Vi compatibility.
Although Vim is 99% Vi compatible, some things in vi can be considered to be a bug, or at least need improvement. Therefore Vim behaves a little bit different here and there by default. When the 'compatible' option is set, all options are given a vi-compatible value, Vim will behave like the "real" vi as much as possible. The 'cpoptions' option can be used to set vi compatibility on/off for a few specific items.

Support for different systems.
Vim can be used on:

Multi level undo.
'u' goes backward in time, 'ctrl-R' goes forward again. Set option 'undolevels' to the number of changes to be remembered (default 1000). Set 'undolevels' to 0 for a vi-compatible one level undo. Set it to -1 for no undo at all.

When all changes in a buffer have been undone, the buffer is not considered changed anymore. You can exit it with :q, without <!>.

Multiple windows and buffers.
Vim can split the screen into several windows, each editing a different buffer or the same buffer at a different location. Buffers can still be loaded (and changed) but not displayed in a window. This is called a hidden buffer. Many commands and options have been added for this facility.

Repeat a series of commands.
'q'<c> starts recording typed characters into named register <c> (append to the register if register name is upper case). A subsequent 'q' stops recording. The register can then be executed with the '@'<c> command. This is very useful to repeat a complex action.

Flexible insert mode.
The arrow keys can be used in insert mode to move around in the file. This breaks the insert in two parts as far as undo and redo is concerned.

CTRL-O can be used to execute a single command-mode command. This is almost the same as hitting <Esc>, typing the command and hitting 'a'.

Visual mode.
Visual can be used to first choose a piece of text and then give a command to do something with it. This is an (easy to use) alternative to first giving the operator and then moving to the end of the text to be operated upon. 'v' and 'V' are used to start Visual mode. 'v' works on characters and 'V' on lines. Move the cursor to extend the Visual part. It is shown highlighted on the screen. By typing 'o' the other end of the Visual text can be moved. The Visual text can be affected by an operator:
ddelete
cchange
yyank
> or <insert or delete indent
!filter through external program
=filter through indent
:start ":" command for the Visual lines.
Qformat text to 'textwidth' columns
Jjoin lines
~swap case
umake lowercase
Umake uppercase

Block operators.
With Visual a rectangular block of text can be selected. Start Visual with CTRL-V. The block can be deleted ('d'), yanked ('y') or its case can be changed ('~', 'u' and 'U'). A deleted or yanked block can be put into the text with the 'p' and 'P' commands.

Online help system.
Help is displayed in a window. The usual commands can be used to move around, search for a string, etc. Tags can be used to jump around in the help files, just like hypertext links. The ":help" command takes an argument to quickly jump to the info on a subject. <F1> is the quick access to the help system. The name of the help index file can be set with the 'helpfile' option.

Command line editing and history.
You can insert or delete at any place in the command line using the cursor keys. The right/left cursor keys can be used to move forward/backward one character. The shifted right/left cursor keys can be used to move forward/backward one word. CTRL-B/CTRL-E can be used to go to the begin/end of the command line.

The command lines are remembered. The up/down cursor keys can be used to recall previous command lines. The 'history' option can be set to the number of lines that will be remembered.

Command line completion.
While entering a command line (on the bottom line of the screen) <Tab> can be typed to complete
whatexample
command:e<Tab>
tag:ta no<Tab>
option:set sc<Tab>
option value:set hf=<Tab>
filename:e ve<Tab>
etc.

If there are multiple matches, CTRL-N (next) and CTRL-P (previous) will walk through the matches. <Tab> works like CTRL-N, but wraps around to the first match.

The 'wildchar' option can be set to the character for command line completion, <Tab> is the default. CTRL-D can be typed after an (incomplete) wildcard; all matches will be listed. CTRL-A will insert all matches. CTRL-L will insert the longest common part of the matches.

Horizontal scrolling.
If the 'wrap' option is off, long lines will not wrap and only part of them will be shown. When the cursor is moved to a part that is not shown, the screen will scroll horizontally. The minimum number of columns to scroll can be set with the 'sidescroll' option. The "zh" and "zl" commands can be used to scroll sideways.

Text formatting.
The 'textwidth' option can be used to automatically limit the line length. This supplements the 'wrapmargin' option of Vi, which was not very useful. The 'Q' operator can be used to format a piece of text ("Qp" formats the current paragraph). Commands for text alignment: ":center", ":left" and ":right".

Edit-compile-edit speedup.
The ":make" command can be used to run the compilation and jump to the first error. Alternatively Vim can be started with the "-e" option from the compiler. A file with compiler error messages is interpreted. Vim starts editing at the first error.

Each line in the error file is scanned for the name of a file, line number and error message. The 'errorformat' option can be set to a list of scanf-like strings to handle output from many compilers.

The ":cn" command can be used to jump to the next error. ":cl" lists all the error messages. Other commands are available (almost the same as with Manx's Z editor on the Amiga). The 'errorfile' option has the name of the file with error messages. The 'makeprg' option contains the name of the program to be executed with the ":make" command. The 'shellpipe' option contains the string to be used to put the output of the compiler into the errorfile.

Improved indenting for C programs
When the 'cindent' option is on the indent of each line is automatically adjusted. C syntax is mostly recognized. The indent for various styles can be set with 'cinoptions'. The keys to trigger indenting can be set with 'cinkeys'.

Comments can be automatically formatted. The 'comments' and 'nestedcomments' options can be set to the characters that start and end a comment. This works best for C code, but also works for e-mail (">" at start of the line) and other types of text. The "=" operator can be used to re-indent lines.

Searching for words in include files
The "[i" command can be used to search for a match of the word under the cursor in the current and included files. The 'include' option can be set the a pattern that describes a command to include a file (the default is for C programs). The "[I" command lists all matches, the "[ CTRL-I" command jumps to a match. The "[d", "[D" and "[ CTRL-D" commands do the same, but only for lines where the pattern given with the 'define' option matches.

Word completion in Insert mode
In insert mode "CTRL-N" and "CTRL-P" can be used to find match with the word before the cursor. This is useful to complete long words. "CTRL-X CTRL-I" can be used to complete the word before the cursor from the current and included files. "CTRL-X CTRL-K" can be used to complete the word before the cursor from a dictionary file, given with the 'dictionary' option

Automatic commands
Commands can be automatically executed when reading a file, writing a file, jumping to another buffer, etc., depending on the file name. This is useful to set options and mappings for C programs, documentation, plain text, e-mail, etc. This also makes it possible to edit compressed files.

Viminfo
The command line history, marks and registers can be stored in a file that is read on startup. This can be used to repeat a search command or command line command after exiting and restarting Vim. It is also possible to jump right back to where the last edit stopped with "'0". The 'viminfo' option can be set to select which items to store in the .viminfo file. This is off by default.

Mouse support
The mouse is supported in an xterm and for MS-DOS. It can be used to position the cursor, select the visual area, paste a register, etc.

Graphical User Interface (GUI)
Included support for GUI: menu's, mouse, scrollbars, etc. You can define your own menus. Better support for CTRL/SHIFT/ALT keys in combination with special keys and mouse. Currently only with Motif and Athena interface.

IMPROVEMENTS FROM VERSION 3.0 TO VERSION 4.0

Besides the big changes mentioned here there are an awful lot of small improvements. For a more complete list see new_features.

New on-line help system new_help Help is now displayed in a window. Tags can be used to jump around in all the documentation (like hypertext links).

Command line editing improved new_commandline Separate history for search commands. Improved command line completion.

Improved indenting for C programs
Added 'cindent' option for configurable C indent mode. The "=" operator can be used to indent lines. Formatting of comments (also for other languages and e-mail).

Searching for words in include files
Added commands to search for a word in the current file and in included files. List the first match, list all matches or jump to a match.

Word completion in Insert mode
Added commands to complete the word before the cursor in Insert mode. Matches can be found in the current file, included files and/or a dictionary.

Automatic commands
Execute commands for a specific file type. Can be used to set options to a different value for C code, plain text e-mail, etc.

Text objects
After an operator and in visual mode text object commands can be used to quickly select a word, line or paragraph.

Options
Added '&' after an option: reset to default value. Added '!' after a boolean option: invert value. A whole bunch of new options. Command line completion can be used to get the old value.

Support for editing one-line paragraphs
When a line is longer than the window width, it can be broken at a space or other convenient position. Commands have been added to move the cursor a screen line up/down.

Usage of key names
Special keys now all have a name like <Up>, <End>, etc. This name is used for mappings, in listings, and many other things. Added a number of new special keys.

Viminfo
The command line history, marks and registers can be stored in a file that is read on startup.

Compilation improvements
Autoconf is used to adjust to different Unix flavors, editing the Makefile is rarely required.

Tag support improved
Static tags and Emacs tag files are now supported. Tag completion works better.

Improved (error) messages
A lot of error messages include the reason for the error. The 'showcommand' includes partially typed mappings.

Swap file
Included checking of the actual file name in a swap file, avoids giving bogus "swap file exists" messages. Give more information about the swap file with the "swap file exists" message and when recovering. Included catching of deadly signals for Unix. Swap files for unmodified buffers are deleted, other swap files are preserved before exiting. Improved recovery when there are multiple swap files.

Mouse support
The mouse is supported in an xterm and for MS-DOS. It can be used to position the cursor, select the visual area, paste a register, etc.

Graphical User Interface (GUI)
Included support for GUI: menu's, mouse, scrollbars, etc. Currently only with Motif and Athena interface.

Support for Windows 95/NT
There is now a version of Vim for Windows NT and Windows 95. It supports long file names, uses all available memory and many more enhancements. There is also a protected mode version, compiled with DJGPP, that runs under Windows 3.1 and MSDOS. It supports long file names where available.

Miscellaneous new features
Implemented incremental search. A whole bunch of commands that start with "g": Goto declaration, show ascii value of character under the cursor, go back to end of word, reselect last Visual area, etc.. Added the ":retab" command. Can be used to change the size of a <Tab>, replace spaces with a <Tab> or a <Tab> with spaces. Implemented "Vim -r" to list any swap files that can be found. The "Q" operator no longer affects empty lines. Added '-' register for deletes of less than one line, see registers. Quickfix: Support for several error formats at the same time. Added separate mapping for normal mode and visual mode. Allow for digraphs to be entered in reverse. Added commands to search for #if/#endif and start/end of comment. Added ":abclear" and ":mapclear": remove all abbreviations/mappings. Added check for last modification time of original file before overwriting it.

vi compatibility improvements
A few more things have been made vi-compatible. The 'cpoptions' option has a few flags to switch specific vi-compatibility items on/off.

OLDER VIM FEATURES

These features were already present in Vim version 3.0.


Send feedback on this page to Rajesh Kallingal
For Vim version 3.24. Last modification: 1996 Apr 25