Jump to content

vi (text editor)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Danbloch (talk | contribs) at 06:37, 8 December 2023 (top: remove hatnote, new name isn't ambiguous). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

vi
Developer(s)Bill Joy
Initial release1976; 48 years ago (1976)
Repository
Written inC
Operating systemUnix, Unix-like
PlatformCross-platform
TypeText editor
LicenseBSD-4-Clause or CDDL
Websiteex-vi.sourceforge.net Edit this on Wikidata

vi (pronounced as distinct letters, /ˌvˈ/)[1] 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 described by (and thus standardized by) the Single Unix Specification and POSIX.[2]

The original code for vi was written by Bill Joy in 1976, as the visual mode for a line editor called ex that Joy had written with Chuck Haley.[3] Bill 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 users straight into ex's visual mode),[4] and the name by which it is known today. Some current implementations of vi can trace their source code ancestry to Bill Joy; others are completely new, largely compatible reimplementations.[citation needed][discuss]

The name "vi" is derived from the shortest unambiguous abbreviation for the ex command visual, which switches the ex line editor to its full-screen mode. The name is pronounced /ˌvˈ/ (the English letters v and i).[5][6]

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%).[7]

History

Creation

Bill Joy, the original creator of the vi editor

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 AT&T Corporation, where ed originated, people seemed to be happy with an editor as basic and unfriendly as ed, George Coulouris recalls:[8]

[...] for many years, they had no suitable terminals. They carried on with TTYs and other printing terminals for a long time, and when they did buy screens for everyone, they got Tektronix 4014s. These were large storage tube displays. You can't run a screen editor on a storage-tube display as the picture can't be updated. Thus it had to fall to someone else to pioneer screen editing for Unix, and that was us initially, and we continued to do so for many years.

Coulouris considered the cryptic commands of ed to be only suitable for "immortals", and thus in February 1976, he enhanced ed (using Ken Thompson's ed source as a starting point) to make em (the "editor for mortals"[9]) while acting as a lecturer at Queen Mary College.[8] 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.[8]

Inspired by em, and by their own tweaks to ed,[3] Bill Joy and Chuck Haley, both graduate students at UC Berkeley, took code from em to make en,[3][10] and then "extended" en to create ex version 0.1.[3] After Haley's departure, Bruce Englar encouraged Joy to redesign the editor,[11] which he did June through October 1977 adding a full-screen visual mode to ex[12]—which came to be vi.[13]

vi and ex share their code; vi is the ex binary launching with the capability to render the text being edited onto a computer terminal—it is ex's visual mode.[13] The name vi comes from the abbreviated ex command (vi) to enter the visual mode from within it. The longform command to do the same was visual,[13][14] and the name vi is explained as a contraction of visual in later literature. vi is also the shell command to launch ex/vi in the visual mode directly, from within a shell.[13]

According to Joy, many of the ideas in this visual mode were taken from Bravo—the bimodal text editor developed at Xerox PARC for the Alto. In an interview about vi's origins, Joy said:[3]

A lot of the ideas for the screen editing mode were stolen from a Bravo manual I surreptitiously looked at and copied. Dot is really the double-escape from Bravo, the redo command. Most of the stuff was stolen. There were some things stolen from ed—we got a manual page for the Toronto version of ed, which I think Rob Pike had something to do with. We took some of the regular expression extensions out of that.

ADM-3A terminal keyboard layout

Joy used a Lear Siegler ADM-3A terminal. On this terminal, the Escape key was at the location now occupied by the Tab key on the widely used IBM PC keyboard (on the left side of the alphabetic part of the keyboard, one row above the middle row). This made it a convenient choice for switching vi modes. Also, the keys h,j,k,l served double duty as cursor movement keys and were inscribed with arrows, which is why vi uses them in that way. The ADM-3A had no other cursor keys. Joy explained that the terse, single character commands and the ability to type ahead of the display were a result of the slow 300 baud modem he used when developing the software and that he wanted to be productive when the screen was painting slower than he could think.[10]

Distribution

Joy was responsible for creating the first BSD Unix release in March, 1978, and included ex 1.1 (dated 1 February 1978)[15] in the distribution, thereby exposing his editor to an audience beyond UC Berkeley.[16] 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.[3]

Eventually it was observed that most ex users were spending all their time in visual mode,[citation needed] and thus in ex 2.0 (released as part of Second Berkeley Software Distribution in May, 1979), Joy created vi as a hard link to ex,[17] 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,[18] 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;[19] the editor would be also too big to run on PC/IX for the IBM PC in 1984.[20]

Joy continued to be lead developer for vi until version 2.7 in June 1979,[11][21] and made occasional contributions to vi's development until at least version 3.5 in August 1980.[21] In discussing the origins of vi and why he discontinued development, Joy said:[3]

I wish we hadn't used all the keys on the keyboard. I think one of the interesting things is that vi is really a mode-based editor. I think as mode-based editors go, it's pretty good. One of the good things about EMACS, though, is its programmability and the modelessness. Those are two ideas which never occurred to me. I also wasn't very good at optimizing code when I wrote vi. I think the redisplay module of the editor is almost intractable. It does a really good job for what it does, but when you're writing programs as you're learning... That's why I stopped working on it.

What actually happened was that I was in the process of adding multiwindows to vi when we installed our VAX, which would have been in December of '78. We didn't have any backups and the tape drive broke. I continued to work even without being able to do backups. And then the source code got scrunched and I didn't have a complete listing. I had almost rewritten all of the display code for windows, and that was when I gave up. After that, I went back to the previous version and just documented the code, finished the manual and closed it off. If that scrunch had not happened, vi would have multiple windows, and I might have put in some programmability—but I don't know.

The fundamental problem with vi is that it doesn't have a mouse and therefore you've got all these commands. In some sense, it's backwards from the kind of thing you'd get from a mouse-oriented thing. I think multiple levels of undo would be wonderful, too. But fundamentally, vi is still ed inside. You can't really fool it.

It's like one of those pinatas—things that have candy inside but has layer after layer of paper mache on top. It doesn't really have a unified concept. I think if I were going to go back—I wouldn't go back, but start over again.

In 1979,[3] Mary Ann Horton took on responsibility for vi. Horton added support for arrow and function keys, macros, and improved performance by replacing termcap with terminfo.[11][22]

Ports and clones

The vi editor in OpenBSD (nvi) on startup, editing a temporary empty file
The vi editor in OpenBSD, editing a small "Hello, world!" type Ruby program

Up to version 3.7 of vi, created in October 1981,[21] UC Berkeley was the development home for vi, but with Bill Joy's departure in early 1982 to join Sun Microsystems, and AT&T's UNIX System V (January 1983) adopting vi,[23] 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.

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.[citation needed] 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.[24][25] 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.[26] It quickly attracted considerable interest in a number of enthusiast communities.[27] Andrew Tanenbaum quickly asked the community to decide on one of these two editors to be the vi clone in Minix;[28] 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.[29] When FreeBSD and NetBSD resynchronized the 4.4-Lite2 codebase, they too switched over to Bostic's nvi, which they continue to use today.[29]

Despite the existence of vi clones with enhanced feature sets, sometime before June 2000,[30] 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,[31] 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.[32]

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.

Impact

Over the years since its creation, vi became the de facto standard Unix editor and a hacker favorite outside of MIT until the rise of Emacs after about 1984.[33] 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.[34] 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.[35]

Interface

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.
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 in either insert mode (where typed text becomes part of the document) or command mode (where keystrokes are interpreted as commands that control the edit session). For example, typing i while in command mode switches the editor to insert mode, but typing i again at this point places an "i" character in the document. From insert mode, pressing ESC 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 Ctrl, and Alt with regular keys. 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 Ctrl or Alt. 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 cwreplacement textEscape, 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."[36]

Contemporary derivatives and clones

The startup screen of vi clone vim
  • Vim "Vi IMproved" has many additional features compared to vi, including (scriptable) syntax highlighting, mouse support, graphical versions, visual mode, many new editing commands and a large amount of extension in the area of ex commands. Vim is included with almost every Linux distribution[37] (and is also shipped with every copy of macOS). Vim also has a vi compatibility mode, in which Vim is more compatible with vi than it would be otherwise, although some vi features, such as open mode, are missing in Vim, even in compatibility mode. This mode is controlled by the :set compatible[38] option. It is automatically turned on by Vim when it is started in a situation that looks as if the software might be expected to be vi compatible.[39] Vim features that do not conflict with vi compatibility are always available, regardless of the setting. Vim was derived from a port of STEVIE to the Amiga.[40]
  • Elvis is a free vi clone for Unix and other operating systems 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 is the standard version of vi shipped on Slackware Linux, Kate OS, and MINIX. The most recent version of Elvis is 2.2, released in October 2003.
  • nvi is an implementation of the ex/vi text editor originally distributed as part of the final official Berkeley Software Distribution (4.4 BSD-Lite).[29] 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.[41][42]
  • vile was 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, a set of standard Linux utilities in a single executable, includes a tiny vi clone.
  • Neovim, a refactor of Vim, which it strives to supersede.

See also

References

  1. ^ Computerphile (9 July 2018), EXTRA BITS GREP from ED and Text Editors - Computerphile – Computerphile, archived from the original on 18 November 2021, retrieved 17 April 2020
  2. ^ The IEEE & The Open Group (2013). ""vi — screen-oriented (visual) display editor", The Open Group Base Specifications Issue 7; IEEE Std 1003.1, 2013 Edition". Retrieved 15 July 2013.
  3. ^ a b c d e f g h "Interview with Bill Joy". Archived from the original on 10 February 2012. Retrieved 3 June 2017.
  4. ^ "Second Berkeley Software Distribution Manual". roguel ife.org. Retrieved 27 March 2018.
  5. ^ Joy, William; Horton, Mark. "An Introduction to Display Editing with Vi" (PDF). freebsd.org. Retrieved 6 February 2019.
  6. ^ "The Jargon Lexicon". Hacker's Dictionary 4.3.0. 30 April 2001. Retrieved 6 February 2019.
  7. ^ Gray, James (1 June 2009). "Readers' Choice Awards 2009". Linux Journal. Retrieved 22 January 2010.
  8. ^ a b c A Quarter Century of UNIX, by Peter H. Salus, Addison-Wesley 1994, pages 139–142. (excerpt available online)
  9. ^ "Source code for em". coulouris.net. February 1976.
  10. ^ a b Vance, Ashlee (11 September 2003). "Bill Joy's greatest gift to man – the vi editor". The Register. Archived from the original on 13 May 2012. Retrieved 30 June 2012.
  11. ^ a b c Joy, Bill. ex Reference Manual (roff source). 4.4 BSD (encumbered, not Lite). CSRG, UC Berkeley. (see Acknowlegments section at end of file)
  12. ^ "See dates in copyright headers, ex 1.1 source code". minnie.tuhs.org.
  13. ^ a b c d "History and effective use of Vim". begriffs.com. Retrieved 27 August 2021.
  14. ^ Joy, William N. (November 1977) [November 1977]. "Command summary". Ex Reference Manual Version 1.1 (PDF). Berkeley, CA. p. 8. Archived (PDF) from the original on 14 April 2020.{{cite book}}: CS1 maint: location missing publisher (link)
  15. ^ "version.c, ex 1.1 source code". minnie.tuhs.org.
  16. ^ "1BSD/READ_ME" (roff source). Formatted: "Berkeley UNIX Software Tape" (PDF). Archived from the original (PDF) on 18 July 2011. Retrieved 27 December 2010.
  17. ^ "makefile, ex 2.0 source code". minnie.tuhs.org.
  18. ^ "READ_ME". ex 2.0 source code.
  19. ^ "ex 3.1 source code".
  20. ^ McMahon, Marilyn; Putnam, Robert (2 April 1984). "A First Look at PC-IX". InfoWorld. pp. 39–42. Retrieved 25 February 2016.
  21. ^ a b c "Change log for vi, versions 2.1–3.7". minnie.tuhs.org.
  22. ^ Joy, Bill. vi Reference Manual (roff source). 4.4 BSD (encumbered, not Lite). CSRG, UC Berkeley. (see Acknowlegments section at end of file)
  23. ^ Kenneth H. Rosen; Douglas A. Host; Rachel Klee (2006). UNIX: the complete reference. McGraw-Hill Osborne Media. p. 10. ISBN 978-0-07-226336-7.
  24. ^ Thompson, Tim (26 March 2000). "Stevie". Retrieved 29 December 2010.
  25. ^ Tim Thompson (28 June 1987). "A mini-vi for the ST". Newsgroupcomp.sys.atari.st. Usenet: 129@glimmer.UUCP. Retrieved 29 December 2010.
  26. ^ Steve Kirkendall (20 April 1990). "A new clone of vi is coming soon: ELVIS". Newsgroupcomp.editors. Usenet: 2719@psueea.UUCP. Retrieved 29 December 2010. (discusses January comp.os.minix posting, and design goals)
  27. ^ Usenet, various newsgroups (comp.editors, comp.sys.*, comp.os.*), 1990
  28. ^ Andrew S. Tanenbaum (18 January 1990). "Elvis vs. stevie". Newsgroupcomp.os.minix. Usenet: 5133@ast.cs.vu.nl. Retrieved 29 December 2010.
  29. ^ a b c Robbins, Arnold; Hannah, Elbert; Lamb, Linda (2008). "Chapter 16: nvi: New vi". Learning the vi and vim editors (7th ed.). O'Reilly Media, Inc. pp. 307–308. ISBN 978-0-596-52983-3.
  30. ^ Changes file, from Traditional Vi by Gunnar Ritter
  31. ^ "Caldera License for 32-bit 32V UNIX and 16 bit UNIX Versions 1, 2, 3, 4, 5, 6, 7" (PDF). mckusick.com.
  32. ^ "The traditional vi". SourceForge. 7 March 2013. Retrieved 24 July 2023.
  33. ^ Smith, T. J. (4 December 2001). "EMACS vs. vi: The endless geek 'holy war'". Linux.com. Retrieved 30 January 2018.
  34. ^ Raymond, Eric S., ed. (1996). The New Hacker's Dictionary (3rd ed.). MIT Press. ISBN 0-262-68092-0.
  35. ^ "Ask Tim Archive". O'Reilly. 21 June 1999.
  36. ^ I. Scott MacKenzie (2013). Human-Computer Interaction: An Empirical Research Perspective. Morgan Kaufmann, an imprint of Elsevier. p. 1. ISBN 978-0-12-405865-1.
  37. ^ Vugt, Sander van (21 November 2015). Beginning the Linux Command Line. Apress. p. 75. ISBN 9781430268291.
  38. ^ "Vim documentation: options". vim.net/sourceforge.net. Retrieved 30 January 2009.
  39. ^ "Vim documentation: starting". vim.net/sourceforge.net. Retrieved 30 January 2009.
  40. ^ Bram Moolenaar (18 April 2005). "Interview: Bram Moolenaar". LinuxEXPRES (Interview) (in Czech). Interviewed by Lukáš Zapletal. pp. 21–22. Retrieved 5 February 2015.
    English translation: "Interview: Bram Moolenaar". Moolenaar.net. Archived from the original on 19 September 2012. Is VIM derivate of other VI clone or you started from scratch? I started with Stevie. This was a Vi clone for the Atari ST computer, ported to the Amiga. It had quite a lot of problems and could not do everything that Vi could, but since the source code was available I could fix that myself.
  41. ^ Verdoolaege, Sven. "Development versions of nvi". Retrieved 1 January 2011.
  42. ^ Bostic, Keith. "Berkeley Vi Editor Home Page". Archived from the original on 5 December 2006. Retrieved 1 January 2011.

Further reading