vi (pronounced as two letters, ) is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is standardized by the Single Unix Specification and POSIX.
vi is actually a mode of the earlier ex editor. Originally, ex lacked a full-screen editing capability, but in 1976, Bill Joy enhanced it to support a visual mode. The program was updated to start in visual mode when launched with the command instead of the legacy mode when launched via the command. In this way, ex and vi are the same program, not two programs. Joy's ex 1.1 was released as part of the first Berkeley Software Distribution (BSD) Unix release in March 1978. It was not until version 2.0 of ex, released as part of Second BSD in May 1979 that the editor was installed under the name "vi" which took a user straight into ex's visual mode.
Some implementations of vi trace their source code ancestry to Bill Joy's work. Others are completely new, largely compatible clones.
The name "vi" comes from the shortest unambiguous abbreviation of the ex command <kbd>visual</kbd>, which switches the ex line editor into full-screen mode.
In addition to various non–free software variants of vi distributed with proprietary implementations of Unix, vi was opensourced with OpenSolaris, and several free and open source software vi clones exist. A 2009 survey of Linux Journal readers found that vi was the most widely used text editor among respondents, beating gedit, the second most widely used editor, by nearly a factor of two (36% to 19%).
History
Creation
thumb|[[Bill Joy, the original creator of the vi editor, in 2003]]
vi was derived from a sequence of UNIX command line editors, starting with ed, which was a line editor designed to work well on teleprinters, rather than display terminals. Within Bell Labs, where ed originated, people seemed to be happy with an editor as basic and unfriendly as ed, George Coulouris recalls:) while acting as a lecturer at Queen Mary College. The em editor was designed for display terminals and was a single-line-at-a-time visual editor. It was one of the first programs on Unix to make heavy use of "raw terminal input mode", in which the running program, rather than the terminal device driver, handled all keystrokes. When Coulouris visited UC Berkeley in the summer of 1976, he brought a DECtape containing em, and showed the editor to various people. Some people considered this new kind of editor to be a potential resource hog, but others, including Bill Joy, were impressed. and then "extended" en to create ex version 0.1. which he did June through October 1977 adding a full-screen visual mode to exwhich came to be vi.
vi and ex share their code; vi is the ex binary launching with the capability to render the text being edited onto a computer terminalit is ex's visual mode. and the name vi is explained as a contraction of visual in later literature. <code>vi</code> is also the shell command to launch ex/vi in the visual mode directly, from within a shell. in the distribution, thereby exposing his editor to an audience beyond UC Berkeley. From that release of BSD Unix onward, the only editors that came with the Unix system were ed and ex. In a 1984 interview, Joy attributed much of the success of vi to the fact that it was bundled for free, whereas other editors, such as Emacs, could cost hundreds of dollars. such that when invoked as vi, ex would automatically start up in its visual mode. Thus, vi is not the evolution of ex, vi is ex.
Joy described ex 2.0 (vi) as a very large program, barely able to fit in the memory of a PDP-11/70, thus although vi may be regarded as a small, lightweight program today, it was not seen that way early in its history. By version 3.1, shipped with 3BSD in December 1979, the full version of vi was no longer able to fit in the memory of a PDP-11; the editor would be also too big to run on PC/IX for the IBM PC in 1984.
Joy continued to be lead developer for vi until version 2.7 in June 1979, In discussing the origins of vi and why he discontinued development, Joy said:
Ports and clones
thumb|The vi editor in [[OpenBSD (nvi) on startup, editing a temporary empty file]]
thumb|The vi editor in [[OpenBSD, editing a small "Hello, world!" type Ruby program]]
Up to version 3.7 of vi, created in October 1981, changes to the vi codebase happened more slowly and in a more dispersed and mutually incompatible way. At UC Berkeley, changes were made but the version number was never updated beyond 3.7. Commercial Unix vendors, such as Sun, HP, DEC, and IBM each received copies of the vi source, and their operating systems, Solaris, HP-UX, Tru64 UNIX, and AIX, continued to maintain versions of vi directly descended from the 3.7 release, but with added features such as adjustable key mappings, encryption, and wide character support.
In 1983, vi was one of several UNIX tools available for Charles River Data Systems' UNOS operating system under Bell Laboratories license.
While commercial vendors could work with Bill Joy's codebase, many people could not. Because Joy had begun with Ken Thompson's ed editor, ex and vi were derivative works and could not be distributed except to people who had an AT&T source license. Those wanting a free Unix-style editor would have to look elsewhere. By 1985, a version of Emacs (MicroEMACS) was available for a variety of platforms, but it was not until June 1987 that STEVIE (ST Editor for VI Enthusiasts), a limited vi clone, appeared for the Atari ST. In early January 1990, Steve Kirkendall posted a new clone of vi, Elvis, to the Usenet newsgroup comp.os.minix, aiming for a more complete and more faithful clone of vi than STEVIE. It quickly attracted considerable interest in a number of enthusiast communities. Andrew Tanenbaum quickly asked the community to decide on one of these two editors to be the vi clone in Minix; Elvis was chosen, and remains the vi clone for Minix today.
In 1989, Lynne Jolitz and William Jolitz began porting BSD Unix to run on 386 class processors, but to create a free distribution they needed to avoid any AT&T-contaminated code, including Joy's vi. To fill the void left by removing vi, their 1992 386BSD distribution adopted Elvis. 386BSD's descendants, FreeBSD and NetBSD, followed suit. But at UC Berkeley, Keith Bostic wanted a "bug for bug compatible" replacement for Joy's vi for 4.4BSD-Lite. Using Kirkendall's Elvis (version 1.8) as a starting point, Bostic created nvi, releasing it in the northern spring of 1994. Gunnar Ritter ported Joy's vi codebase (taken from 2.11BSD, February 1992) to modern Unix-based operating systems, such as Linux and FreeBSD. Initially, his work was technically illegal to distribute without an AT&T source license, but, in January 2002, those licensing rules were relaxed, allowing legal distribution as an open-source project. Ritter continued to make small enhancements to the vi codebase similar to those done by commercial Unix vendors still using Joy's codebase, including changes required by the POSIX.2 standard for vi. His work is available as Traditional Vi.
But although Joy's vi was now once again available for BSD Unix, it arrived after the various BSD flavors had committed themselves to nvi, which provided a number of enhancements over traditional vi, and dropped some of its legacy features (such as open mode for editing one line at a time). Thus BSD Unix, where Joy's vi codebase began, no longer uses it, and the AT&T-derived Unixes, which in the early days lacked Joy's editor, are the ones that now use and maintain modified versions of his code.
Use
vi became the de facto standard Unix editor and a hacker favorite outside of MIT until the rise of Emacs after about 1984. The Single UNIX Specification specifies vi, so every conforming system must have it.
vi is still widely used by users of the Unix family of operating systems. About half the respondents in a 1991 USENET poll preferred vi. In 1999, Tim O'Reilly, founder of the eponymous computer book publishing company, stated that his company sold more copies of its vi book than its Emacs book.
User experience
thumb|The vi editor employed minimal logic that would aid the user. This included trivial aids such as how to join two lines together and maintain reasonable usage of whitespace.
thumb|The vi editor has a number of revisions; however, the primary purpose was to allow a user to enjoy the full "visual" screen mode of modern terminals.
vi is a modal editor: it operates either in insert mode (where typed text becomes part of the document) or in command mode (where keystrokes are interpreted as commands that control the edit session). For example, typing while in command mode switches the editor to insert mode, but typing again at this point places an "i" character in the document. From insert mode, pressing switches the editor back to command mode. A perceived advantage of vi's separation of text entry and command modes is that both text editing and command operations can be performed without requiring the removal of the user's hands from the home row. As non-modal editors usually have to reserve all keys with letters and symbols for the printing of characters, any special commands for actions other than adding text to the buffer must be assigned to keys that do not produce characters, such as function keys, or combinations of modifier keys such as , and with regular keys. Also, vi has the property that most ordinary keys are connected to some kind of command for positioning, altering text, searching and so forth, either singly or in key combinations. Many commands can be touch typed without the use of or . Other types of editors generally require the user to move their hands from the home row when touch typing:
- To use a mouse to select text, commands, or menu items in a GUI editor.
- To the arrow keys or editing functions (Home / End or Function Keys).
- To invoke commands using modifier keys in conjunction with the standard typewriter keys.
For instance, in vi, replacing a word is replacement text, which is a combination of two independent commands (change and word-motion) together with a transition into and out of insert mode. Text between the cursor position and the end of the word is overwritten by the replacement text. The operation can be repeated at some other location by typing , the effect being that the word starting at that location will be replaced with the same replacement text.
A human–computer interaction textbook notes on its first page that "One of the classic UI foibles—told and re-told by HCI educators around the world—is the vi editor's lack of feedback when switching between modes. Many a user made the mistake of providing input while in command mode or entering a command while in input mode."
Variants
thumb|The startup screen of vi clone [[vim (text editor)|vim]]
; Vim: Vim (short for vi improved) has many additional features compared to vi, including (scriptable) syntax highlighting, mouse support, GUI support, visual mode, and many new and extended editing commands. Vim is typically included in a Linux distribution and in macOS. Vim provides a vi-compatibility mode, in which Vim is more compatible with vi than it is otherwise, although some vi features, such as open mode, are missing in Vim, even in compatibility mode. Vim features that do not conflict with vi compatibility are always available, regardless of this mode. Vim was derived from a port of Stevie for Amiga.
; Elvis: A free vi clone written by Steve Kirkendall. Elvis introduced a number of features now present in other vi clones, including allowing the cursor keys to work in input mode. It was the first to provide color syntax highlighting (and to generalize syntax highlighting to multiple filetypes). Elvis 1.x was used as the starting point for nvi, but Elvis 2.0 added numerous features, including multiple buffers, windows, display modes, and file access schemes. Elvis was the standard version of vi shipped on Slackware Linux until 2020-01-13 when it was replaced with nvi due to the latter's UTF8 support, and is still the standard version on Kate OS, and MINIX. The most recent version of Elvis is 2.2, released in October 2003.
; nvi: An implementation of the ex/vi text editor originally distributed as part of the final official Berkeley Software Distribution (4.4 BSD-Lite). This is the version of vi that is shipped with all BSD-based open source distributions. It adds command history and editing, filename completions, multiple edit buffers, and multi-windowing (including multiple windows on the same edit buffer). Beyond 1.79, from October, 1996, which is the recommended stable version, there have been "development releases" of nvi, the most recent of which is 1.81.6, from November, 2007.
; vile: Initially derived from an early version of Microemacs in an attempt to bring the Emacs multi-window/multi-buffer editing paradigm to vi users, and was first published on Usenet's alt.sources in 1991. It provides infinite undo, UTF-8 compatibility, multi-window/multi-buffer operation, a macro expansion language, syntax highlighting, file read and write hooks, and more.
; BusyBox: Includes a tiny vi clone in its single executable that provides many Linux utilities.
; Neovim: A refactor of Vim, which it strives to supersede.
See also
- Comparison of text editors
- List of POSIX commands
- List of text editors
- visudo
References
Further reading
External links
- The Traditional Vi: Source Code for Modern Unix Systems
- An Introduction to Display Editing with Vi, by Mark Horton and Bill Joy
- vi lovers home page
- Explanation of modal editing with vi – "Why, oh WHY, do those #?@! nutheads use vi?"
- The original source code of ex (aka vi) versions 1.1, 2.2, 3.2, 3.6, and 3.7 ported to current UNIX
