VI Diff
VI Diff
This file lists the differences between Vim and Vi/Ex and gives an overview of
what is in Vim that is not in Vi.
Vim is mostly POSIX 1003.2-1 compliant. The only command known to be missing
is ":open". There are probably a lot of small differences (either because Vim
is missing something or because Posix is beside the mark).
==============================================================================
1. Simulated command *simulated-command*
Vim does not support open mode, since it's not really useful. For those
situations where ":open" would start open mode Vim will leave Ex mode, which
allows executing the same commands, but updates the whole screen instead of
only one line.
==============================================================================
2. Missing options *missing-options*
These options are in the Unix Vi, but not in Vim. If you try to set one of
them you won't get an error message, but the value is not used and cannot be
printed.
Vi did not allow for changing the termcap entries, you would have to exit Vi,
edit the termcap entry and try again. Vim has the |terminal-options|.
==============================================================================
3. Limits *limits*
Vim has only a few limits for the files that can be edited {Vi: can not handle
<Nul> characters and characters above 128, has limited line length, many other
limits}.
Information for undo and text in registers is kept in memory, thus when making
(big) changes the amount of (virtual) memory available limits the number of
undo levels and the text that can be kept in registers. Other things are also
kept in memory: Command-line history, error messages for Quickfix mode, etc.
The option 'maxmem' ('mm') is used to set the maximum memory used for one
buffer (in kilobytes). 'maxmemtot' is used to set the maximum memory used for
all buffers (in kilobytes). The defaults depend on the system used. For the
Amiga, 'maxmemtot' is set depending on the amount of memory available.
These are not hard limits, but tell Vim when to move text into a swap file.
If you don't like Vim to swap to a file, set 'maxmem' and 'maxmemtot' to a
very large value. The swap file will then only be used for recovery. If you
don't want a swap file at all, set 'updatecount' to 0, or use the "-n"
argument when starting Vim.
==============================================================================
4. The most interesting additions *vim-additions*
Vi compatibility. |'compatible'|
Although Vim is 99% Vi compatible, some things in Vi can be
considered to be a bug, or at least need improvement. But still, Vim
starts in a mode which behaves like the "real" Vi as much as possible.
To make Vim behave a little bit better, try resetting the 'compatible'
option:
:set nocompatible
Or start Vim with the "-N" argument:
vim -N
Vim starts with 'nocompatible' automatically if you have a .vimrc
file. See |startup|.
The 'cpoptions' option can be used to set Vi compatibility on/off for
a number of specific items.
Folding. |folding|
A range of lines can be shown as one "folded" line. This allows
overviewing a file and moving blocks of text around quickly.
Folds can be created manually, from the syntax of the file, by indent,
etc.
Plugins. |add-plugin|
The functionality can be extended by dropping a plugin file in the
right directory. That's an easy way to start using Vim scripts
written by others. Plugins can be for all kind of files, or
specifically for a filetype.
Packages make this even easier. |packages|
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.
Viminfo. |viminfo-file|
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.
Printing. |printing|
The |:hardcopy| command sends text to the printer. This can include
syntax highlighting.
==============================================================================
5. Other vim features *other-features*
When Vim is started with "-s scriptfile", the characters read from
"scriptfile" are treated as if you typed them. If end of file is reached
before the editor exits, further characters are read from the console.
The "-w" option can be used to record all typed characters in a script file.
This file can then be used to redo the editing, possibly on another file or
after changing some commands in the script file.
The "-o" option opens a window for each argument. "-o4" opens four windows.
In command mode:
When the 'showcmd' option is set, the command characters are shown in the last
line of the screen. They are removed when the command is finished.
If the 'ruler' option is set, the current cursor position is shown in the
last line of the screen.
"U" still works after having moved off the last changed line and after "u".
Characters with the 8th bit set are displayed. The characters between '~' and
0xa0 are displayed as "~?", "~@", "~A", etc., unless they are included in the
'isprint' option.
"]f", "[f" and "gf" start editing the file whose name is under the cursor.
CTRL-W f splits the window and starts editing the file whose name is under
the cursor.
"*" searches forward for the identifier under the cursor, "#" backward.
"K" runs the program defined by the 'keywordprg' option, with the identifier
under the cursor as argument.
"%" can be preceded with a count. The cursor jumps to the line that
percentage down in the file. The normal "%" function to jump to the matching
brace skips braces inside quotes.
With the CTRL-] command, the cursor may be in the middle of the identifier.
The used tags are remembered. Commands that can be used with the tag stack
are CTRL-T, ":pop" and ":tag". ":tags" lists the tag stack.
Vi uses 'wrapscan' when searching for a tag. When jumping to a tag Vi starts
searching in line 2 of another file. It does not find a tag in line 1 of
another file when 'wrapscan' is not set.
The 'tags' option can be set to a list of tag file names. Thus multiple
tag files can be used. For file names that start with "./", the "./" is
replaced with the path of the current file. This makes it possible to use a
tags file in the same directory as the file being edited.
{Vi: always uses binary search in some versions}
{Vi does not have the security prevention for commands in tag files}
Previously used file names are remembered in the alternate file name list.
CTRL-^ accepts a count, which is an index in this list.
":files" command shows the list of alternate file names.
"#<N>" is replaced with the <N>th alternate file name in the list.
"#<" is replaced with the current file name without extension.
Search patterns have more features. The <NL> character is seen as part of the
search pattern and the substitute string of ":s". Vi sees it as the end of
the command.
Searches can put the cursor on the end of a match and may include a character
offset.
The command ":next!" with 'autowrite' set does not write the file. In vi the
file was written, but this is considered to be a bug, because one does not
expect it and the file is not written with ":rewind!".
In Vi when entering a <CR> in replace mode deletes a character only when 'ai'
is set (but does not show it until you hit <Esc>). Vim always deletes a
character (and shows it immediately).
The ":w!" command always writes, also when the file is write protected. In Vi
you would have to do ":!chmod +w %:S" and ":set noro".
With the "J" (join) command you can reset the 'joinspaces' option to have only
one space after a period (Vi inserts two spaces).
"cw" can be used to change white space formed by several characters (Vi is
confusing: "cw" only changes one space, while "dw" deletes all white space).
{Vi: "cw" when on a blank followed by other blanks changes only the first
blank; this is probably a bug, because "dw" deletes all the blanks}
"o" and "O" accept a count for repeating the insert (Vi clears a part of
display).
After a ":cd" command the file names (in the argument list, opened files)
still point to the same files. In Vi ":cd" is not allowed in a changed file;
otherwise the meaning of file names change.
No check for "tail recursion" with mappings. This allows things like
":map! foo ^]foo".
When a mapping starts with number, vi loses the count typed before it (e.g.
when using the mapping ":map g 4G" the command "7g" goes to line 4). This is
considered a vi bug. Vim concatenates the counts (in the example it becomes
"74G"), as most people would expect.
The :put! command inserts the contents of a register above the current line.
The "p" and "P" commands of vi cannot be repeated with "." when the putted
text is less than a line. In Vim they can always be repeated.
":noremap" command can be used to enter a mapping that will not be remapped.
This is useful to exchange the meaning of two keys. ":cmap", ":cunmap" and
":cnoremap" can be used for mapping in command-line editing only. ":imap",
":iunmap" and ":inoremap" can be used for mapping in insert mode only.
Similar commands exist for abbreviations: ":noreabbrev", ":iabbrev"
":cabbrev", ":iunabbrev", ":cunabbrev", ":inoreabbrev", ":cnoreabbrev".
The 'scrolljump' option can be set to the minimum number of lines to scroll
when the cursor gets off the screen. Use this when scrolling is slow.
The 'scrolloff' option can be set to the minimum number of lines to keep
above and below the cursor. This gives some context to where you are
editing. When set to a large number the cursor line is always in the middle
of the window.
Uppercase marks can be used to jump between files. The ":marks" command lists
all currently set marks. The commands "']" and "`]" jump to the end of the
previous operator or end of the text inserted with the put command. "'[" and
"`[" do jump to the start. {Vi: no uppercase marks}
The 'shelltype' option can be set to reflect the type of shell used on the
Amiga.
The 'highlight' option can be set for the highlight mode to be used for
several commands.
The CTRL-A (add) and CTRL-X (subtract) commands are new. The count to the
command (default 1) is added to/subtracted from the number at or after the
cursor. That number may be decimal, octal (starts with a '0') or hexadecimal
(starts with '0x'). Very useful in macros.
With the :set command the prefix "inv" can be used to invert boolean options.
In both Vi and Vim you can create a line break with the ":substitute" command
by using a CTRL-M. For Vi this means you cannot insert a real CTRL-M in the
text. With Vim you can put a real CTRL-M in the text by preceding it with a
CTRL-V.
In Insert mode:
If the 'revins' option is set, insert happens backwards. This is for typing
Hebrew. When inserting normal characters the cursor will not be shifted and
the text moves rightwards. Backspace, CTRL-W and CTRL-U will also work in
the opposite direction. CTRL-B toggles the 'revins' option. In replace mode
'revins' has no effect. Only when enabled at compile time.
The backspace key can be used just like CTRL-D to remove auto-indents.
You can backspace, CTRL-U and CTRL-W over line breaks if the 'backspace' (bs)
option includes "eol". You can backspace over the start of insert if the
'backspace' option includes "start".
When the 'paste' option is set, a few options are reset and mapping in insert
mode and abbreviation are disabled. This allows for pasting text in windowing
systems without unexpected results. When the 'paste' option is reset, the old
option values are restored.
CTRL-@ (insert previously inserted text) works always (Vi: only when typed as
first character).
CTRL-A works like CTRL-@ but does not leave insert mode.
CTRL-Y and CTRL-E can be used to copy a character from above/below the
current cursor position.
After CTRL-V you can enter a three digit decimal number. This byte value is
inserted in the text as a single character. Useful for international
characters that are not on your keyboard.
The window always reflects the contents of the buffer (Vi does not do this
when changing text and in some other cases).
When repeating an insert, e.g. "10atest <Esc>" vi would only handle wrapmargin
for the first insert. Vim does it for all.
A count to the "i" or "a" command is used for all the text. Vi uses the count
only for one line. "3iabc<NL>def<Esc>" would insert "abcabcabc<NL>def" in Vi
but "abc<NL>defabc<NL>defabc<NL>def" in Vim.
In Command-line mode:
General:
The 'ttimeout' option is like 'timeout', but only works for cursor and
function keys, not for ordinary mapped characters. The 'timeoutlen' option
gives the number of milliseconds that is waited for. If the 'esckeys' option
is not set, cursor and function keys that start with <Esc> are not recognized
in insert mode.
There is an option for each terminal string. Can be used when termcap is not
supported or to change individual strings.
The 'fileformat' option can be set to select the <EOL>: "dos" <CR><NL>, "unix"
<NL> or "mac" <CR>.
When the 'fileformats' option is not empty, Vim tries to detect the type of
<EOL> automatically. The 'fileformat' option is set accordingly.
On systems that have no job control (older Unix systems and non-Unix systems)
the CTRL-Z, ":stop" or ":suspend" command starts a new shell.
The 'columns' and 'lines' options are used to set or get the width and height
of the display.
Option settings are read from the first and last few lines of the file.
Option 'modelines' determines how many lines are tried (default is 5). Note
that this is different from the Vi versions that can execute any Ex command
in a modeline (a major security problem). |trojan-horse|
If the 'insertmode' option is set (e.g. in .exrc), Vim starts in insert mode.
And it comes back there, when pressing <Esc>.
Undo information is kept in memory. Available memory limits the number and
size of change that can be undone. This is hardly a problem on the Amiga and
almost never with Unix and Win32.
Vim creates a file ending in ".swp" to store parts of the file that have been
changed or that do not fit in memory. This file can be used to recover from
an aborted editing session with "vim -r file". Using the swap file can be
switched off by setting the 'updatecount' option to 0 or starting Vim with
the "-n" option. Use the 'directory' option for placing the .swp file
somewhere else.
Vim is able to work correctly on filesystems with 8.3 file names, also when
using messydos or crossdos filesystems on the Amiga, or any 8.3 mounted
filesystem under Unix. See |'shortname'|.
Error messages are shown at least one second (Vi overwrites error messages).
If Vim gives the |hit-enter| prompt, you can hit any key. Characters other
than <CR>, <NL> and <Space> are interpreted as the (start of) a command.
{Vi: only ":" commands are interpreted}
==============================================================================
6. Supported Vi features *vi-features*
Vim supports nearly all Vi commands and mostly in the same way. That is when
the 'compatible' option is set and 'cpoptions' contains all flags. What the
effect is of resetting 'compatible' and removing flags from 'cpoptions' can be
found at the help for the specific command.
The help files used to mark features that are in Vim but not in Vi with {not
in Vi}. However, since these remarks cluttered the help files we now do it
the other way around: Below is listed what Vi already supported. Anything
else has been added by Vim.
Common for these commands is that Vi doesn't support the ++opt argument on
`:edit` and other commands that open a file.
note: See the beginning of |normal-index| for the meaning of WORD, N, Nmove
and etc in the description text.
'autoindent' 'ai' take indent for new line from previous line
{Vi does this slightly differently: After the
indent is deleted when typing <Esc> or <CR>, the
cursor position when moving up or down is after
the deleted indent; Vi puts the cursor somewhere
in the deleted indent}.
'autowrite' 'aw' automatically write file if changed
'directory' 'dir' list of directory names for the swap file
{Vi: directory to put temp file in, defaults to
"/tmp"}
'edcompatible' 'ed' toggle flags of ":substitute" command
'errorbells' 'eb' ring the bell for error messages
'ignorecase' 'ic' ignore case in search patterns
'lines' number of lines in the display
'lisp' automatic indenting for Lisp {Vi: Does it a little
bit differently}
'list' show <Tab> and <EOL>
'magic' changes special characters in search patterns
'modeline' 'ml' recognize 'modelines' at start or end of file
{called modelines in some Vi versions}
'number' 'nu' print the line number in front of each line
'paragraphs' 'para' nroff macros that separate paragraphs
'prompt' 'prompt' enable prompt in Ex mode
'readonly' 'ro' disallow writing the buffer {Vim sets 'readonly'
when editing a file with `:view`}
'remap' allow mappings to work recursively
'report' threshold for reporting nr. of lines changed
'scroll' 'scr' lines to scroll with CTRL-U and CTRL-D
'sections' 'sect' nroff macros that separate sections
'shell' 'sh' name of shell to use for external commands
'shiftwidth' 'sw' number of spaces to use for (auto)indent step
'showmatch' 'sm' briefly jump to matching bracket if insert one
'showmode' 'smd' message on status line to show current mode
'tabstop' 'ts' number of spaces that <Tab> in file uses
'taglength' 'tl' number of significant characters for a tag
'tags' 'tag' list of file names used by the tag command
{Vi: default is "tags /usr/lib/tags"}
'tagstack' 'tgst' push tags onto the tag stack {not in all versions
of Vi}
'term' name of the terminal
'terse' shorten some messages
'timeout' 'to' time out on mappings and key codes
'timeoutlen' 'tm' time for 'timeout' {only in some Vi versions}
'ttytype' 'tty' alias for 'term'
'verbose' 'vbs' give informative messages {only in some Vi
versions as a boolean option}
'warn' warn for shell command when buffer was changed
'window' 'wi' nr of lines to scroll for CTRL-F and CTRL-B
{Vi also uses the option to specify the number of
displayed lines}
'wrapmargin' 'wm' chars from the right where wrapping starts
{Vi: works differently and less usefully}
'wrapscan' 'ws' searches wrap around the end of the file
'writeany' 'wa' write to file with no need for "!" override
Also see |missing-options|.
==============================================================================
7. Command-line arguments *cmdline-arguments*
Only Vim is able to accept options in between and after the file names.
--remote-silent {file} Vim: edit the files in another Vim server if possible
--remote-wait Vim: edit the files in another Vim server and wait for it
-a Elvis: Load all specified file names into a window (use -o for
Vim).
-d {device} Vim: Use {device} for I/O (Amiga only). {only when compiled
without the |+diff| feature}
-d Vim: start with 'diff' set. |vimdiff|
-p[N] Vim: Open [N] tab pages, or one for each file.
-t {tag} Elvis, Nvi, Posix, Vi, Vim: Edit the file containing {tag}.
-t{tag} Vim: Idem.
-w {size} Elvis, Posix, Nvi, Vi, Vim: Set value of 'window' to {size}.
-w{size} Nvi, Vi: Same as "-w {size}".
-w {name} Vim: Write to script file {name} (must start with non-digit).
==============================================================================
8. POSIX compliance *posix* *posix-compliance*
In 2005 the POSIX test suite was run to check the compatibility of Vim. Most
of the test was executed properly. There are the few things where Vim
is not POSIX compliant, even when run in Vi compatibility mode.
*$VIM_POSIX*
Set the $VIM_POSIX environment variable to have 'cpoptions' include the POSIX
flags when Vim starts up. This makes Vim run as POSIX as it can. That's
a bit different from being Vi compatible.
This is where Vim does not behave as POSIX specifies and why:
*posix-screen-size*
The $COLUMNS and $LINES environment variables are ignored by Vim if
the size can be obtained from the terminal in a more reliable way.
Add the '|' flag to 'cpoptions' to have $COLUMNS and $LINES overrule
sizes obtained in another way.
The "{" and "}" commands don't stop at a "{" in the original Vi, but
POSIX specifies it does. Add the '{' flag to 'cpoptions' if you want
it the POSIX way.
The "D", "o" and "O" commands accept a count. Also when repeated.
Add the '#' flag to 'cpoptions' if you want to ignore the count.
The ":cd" command fails if the current buffer is modified when the '.'
flag is present in 'cpoptions'.
vim:tw=78:ts=8:noet:ft=help:norl: