vi
From Encoresoup - The Ultimate Guide to Free/Open Source Software
|
| vi | |
|---|---|
| | |
| vi editing a temporary, empty file. Tildes signify lines not present in the file. | |
| Developer: | Bill Joy |
| Written in: | C |
| OS: | Unix-like |
| Genre: | text editor |
| License: | BSD License |
vi is a screen-oriented text editor written by Bill Joy in 1976 for an early BSD release.
The name vi is derived from the shortest unambiguous abbreviation for the command visual in ex; the command in question switches the line editor ex to visual mode. The name vi is pronounced /ˈviːˈaɪ/,[1] or /vaɪ/.[2]
Current releases of vi are free and open source software, usually released under permissive free software licenses such as the BSD License.
Contents |
[edit] Interface
vi is a modal editor: it operates in either insert mode (where typed text becomes part of the document) or normal mode (where keystrokes are interpreted as commands that control the edit session). Typing Template:Keypress while in normal mode switches the editor to insert mode. Typing Template:Keypress again at this point places an "i" character in the document. How the Template:Keypress keystroke is processed depends on the editor mode. From insert mode, pressing the escape key switches the editor back to normal mode.
vi can process compound commands that embed text for insertion in the document. For example, the command:
- 20iHello world! Template:Keypress Template:Keypress
would insert 20 lines in the document with the text Hello world!. Rather than grapple with the notion of two mode switches while executing this command, some users view vi as a stateful filter. After processing the third character, vi changes state and begins processing input as text to be added to the file. On processing the escape, vi returns to the state in which it is ready to receive a new command.
Whether viewed as modal or stateful, vi's processing of the same keystroke in different ways depending on the history of the edit session distinguishes it from editors which are generally considered non-modal.
A perceived advantage of a modal editor is that the use of keyboard chords (multiple keys pressed simultaneously, typically a modifier plus a letter key) is reduced or eliminated. Instead, in normal mode, single keystrokes serve as commands. This results in the user's hands not having to take up awkward positions, which some find results in faster work.
[edit] History
Bill Joy wrote vi at the University of California, Berkeley, on a Lear-Siegler ADM3A 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 ADM3A had no other cursor keys.
vi became the de facto standard Unix editor and a nearly undisputed 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.[1] 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.[3]
[edit] Operation
[edit] Vi commands
There are two main classes of commands: cursor movements and text modification. vi is the fullscreen counterpart to ex, and cursor movement is a key part of the design.
- Motions
These commands move the cursor, either relative to its current position, or to an absolute position.
Relative motions can be prefixed with a count, to tell vi to repeat the motion. These are relative motion commands:
h j k l
| Move the cursor to the left, down, up, right, respectively. These also take a count: '8h' moves the cursor 8 letters to the left.
|
Return + -
| Move the cursor down (Return and '+') or up ('-').
|
w W b B
| Move forward ('w' and 'W') or back ('b' and 'B') by a word. 'w' and 'b' treat anything non-alphanumeric as a word delimiter; 'W' and 'B' honor only white space.
|
} {
| Move to end of current or previous paragraph, respectively. |
) (
| Move to end of current or previous sentence, respectively. |
Absolute motions do not accept a count except for special cases where it acts as a line or column number. These are absolute motion commands:
G
| Go to (a specified line). E.g., "10G" moves the cursor to line 10. Without a count, vi goes to the last line of the buffer. |
^
| Move to first nonblank character on the current line. |
$
| Move to end of current line. |
0
| (zero) Move to beginning of current line. |
- Operators
Many of the text modification commands form a special category known as operators. They can be prefixed with a count (to repeat the operator), and are suffixed with a motion command. The text between the current position and the final position (after the motion) is called a region.
These are examples of operators:
d
| delete a region. "d10G" deletes lines from current line until line 10 (inclusive). Recall that "10G" moves the cursor to line 10. |
c
| change a region. "cwnew" - changes current word with the text 'new'. Note that "cw" essentially switches the editor to '''insert mode'''.\n\p- valign="top"\n\p\lcode\g<\l/code\g \lcode\g>\l/code\g\n\pindent a region. "\lcode\g<}\l/code\g" indents left all the lines from here until end of paragraph. "\lcode\g>/xxx\l/code\g" indents right lines from here until the line containing the pattern "xxx".\n\p}\n\nIn some instances, if the motion command repeats the operator character (as in 'dd'), the region is a whole line. Thus "dd" deletes the current line, and "cc''new''\lEsc\g" replaces the entire current line with the text 'new'. Prefixing it with a count repeats (or makes it apply to more than one), e.g., "10dd" deletes 10 lines.\n\n; Inline Commands\nA few commands move the cursor only within the current line. Like operators, they accept a repeat count:\n{\p\n\p- valign="top"\n\pwidth="75pt"\p\lcode\gf\l/code\g''letter'' \n\pMove the cursor to the first occurrence of ''letter'' in the current line, starting from current position.\n\p- valign="top"\n\p\lcode\gF\l/code\g''letter''\n\pSimilar to 'f', but in the reverse direction.\n\p- valign="top"\n\p\lcode\gt\l/code\g''letter''\n\pMove the cursor before the first occurrence of ''letter'' in the current line, starting from current position.\n\p- valign="top"\n\p\lcode\gT\l/code\g''letter''\n\pSimilar to 't', but in the reverse direction.\n\p- valign="top"\n\p\lcode\g;\l/code\g\n\pRepeat the last forward scan.\n\p- valign="top"\n\p\lcode\g,\l/code\g\n\pRepeat the last reverse scan.\n\p}\n\n; Other Commands\nOther commands do not fall neatly into a category:\n{\p\n\p- valign="top"\n\pwidth="75pt"\p\lcode\g/\l/code\g''pattern'' \n\pSearch for pattern and place the cursor at the start of the matched text.\n\p- valign="top"\n\p\lcode\g?\l/code\g''pattern''\n\pSearch in the reverse direction.\n\p- valign="top"\n\p\lcode\g%\l/code\g\n\pMove the cursor to the matching brace or bracket: {} [] ().\n\p- valign="top"\n\p\lcode\g.\l/code\g\n\pRepeat the last command which has modified the file. This may be used in a map. For example, suppose one has substituted an underscore for a space as the last command. Then ''\lescape\g''':map g j0.''''' will set a macro-command ''g'' to perform the last . command after moving to the first column in a line (0) and then down one line (j). From then on, one may simply press the ''g'' key to repeat the last command.\n\p- valign="top"\n\p\lcode\g!\l/code\g''program'' \n\pFilter a region through an external program. "\lcode\g!Gsort\l/code\g" pipes all the lines from current line to the end of the document (\lcode\gG\l/code\g) to the \lcode\gsort\l/code\g program and replaces those lines in the document with the output of the sort program.\n\p}\n\n=== Regular expressions ===\nSupport for regular expressions (or text patterns) is an important feature of vi. These can be used extensively in search, substitution and global search and replace commands.\n\n===Ex commands===\nAll of the ex commands can be used in vi by typing ":" to get a prompt, and entering the command. Exit temporarily (or permanently) from visual mode to ex by "Q", return to visual mode by ":vi".\n\n; Options\nSeveral of vi's default behaviors can be altered using options. These take the form ":set ''option''" or ":set no''option''" and so on. Example: "set ignorecase" causes all searches to be case-insensitive.\n\n; File Commands\n{\p\n\p- valign="top"\n\pwidth="75pt"\p\lcode\g:w\l/code\g ''filename'' \n\pWrites (saves) the current document. If the optional ''filename'' is provided, the text is saved in the specified file.\n\p- valign="top"\n\p\lcode\g:q\l/code\g\n\pQuits the editor.\n\p- valign="top"\n\p\lcode\g:wq\l/code\g or \lcode\g:x\l/code\g\n\pSave and Quit.\n\p- valign="top"\n\p\lcode\g:e\l/code\g ''filename''\n\pLoads the specified file into the editor.\n\p- valign="top"\n\p\lcode\g:n\l/code\g\n\pLoads the next file into the editor. Useful when vi was invoked from the command line with multiple file names.\n\p- valign="top"\n\p\lcode\g:r\l/code\g ''filename''\n\pReads (inserts) the content of the specified file into the current document.\n\p}\n\nWhere applicable, these commands take a line number or a range of line numbers. E.g., "10,25w ''newfile''" will write lines 10 through 25 (inclusive) into the file ''newfile''; "$r ''newfile''" will read the contents of file ''newfile'' after the last line of the current document ('$' stands for the last line).\n\n; Maps and abbreviations\nA frequently used command sequence can be mapped to a new command-letter. The sequence could even include any text to be inserted. E.g.,:\n\lcode\g\n:map * iAuthor: John Bull\lEsc\g\n\l/code\g\ncauses the '*' character to be a command that inserts "Author: John Bull" at the cursor position.\n\nAn abbreviation is like a mapping, but during insert mode. Example:\n\lcode\g\n:abbr US United States\n\l/code\g\nThis will insert "United States" whenever the word "US" is typed when in '''insert mode'''.\n\n==Derivatives and clones==\n[[Image:Vim splash screen.png\pthumb\pThe startup screen of vi clone [[vim (text editor)\p'''vim''']]]]\n\n* [[nvi]] is an implementation of the ex/vi text editor originally distributed as part of the final official Berkeley Software Distribution(4.4BSD). 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, multi-windowing (including multiple windows on the same edit buffer). \n* [[Vim (text editor)\pVim]] "Vi IMproved" has yet more features than vi, including (scriptable) syntax highlighting, mouse support, graphical versions, visual mode and many new editing commands. It is the standard version of vi on most Linux systems.\n* [[elvis (text editor)\pElvis]] is a free vi clone for Unix and other operating systems. This is the standard version of vi shipped on [[Slackware Linux]], [[Kate OS]] and MINIX.\n* [[Vile (editor)\pvile]] 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.\n* bvi "Binary VI" is an editor for binary files based on the vi text editor.\n* BusyBox, a set of standard Linux utilities on a single executable, includes a tiny vi clone.\n* Viper, an emacs package providing Vi emulation on top of Emacs.\n\n== See also ==\n\ofossportal\c \n\n* List of text editors\n* Comparison of text editors\n* Editor war\n* List of Unix programs\n\n== References ==\n\n\oreflist\c\n\n== Further reading ==\n\n* \o cite book \p url = http://www.oreilly.com/catalog/vi6/ \p first = Linda \p last = Lamb \p coauthors = Arnold Robbins \p title = Learning the vi Editor (6th Edition) \p publisher = O'Reilly & Associates, Inc. \p date = 1998 \c\n* \o cite book \p url = http://oreilly.com/catalog/9780596529833/ \p first = Arnold \p last = Robbins \p coauthors = Linda Lamb, Elbert Hannah \p title = Learning the vi and Vim Editors, Seventh Edition \p publisher = O'Reilly & Associates, Inc. \p date = 2008 \c\n* Oualline, Steve (2001) ''[http://www.truth.sk/vim/vimbook-OPL.pdf Vi IMproved - Vim]'', New Riders Publishers, 572 pp.\n\n==External links==\n\oWikibooks\c\n*[http://ex-vi.sourceforge.net/ The original Vi version, adapted to more modern standards]\n*[http://docs.freebsd.org/44doc/usd/12.vi/paper.html An Introduction to Display Editing with Vi], by Mark Horton and vi programmer Bill Joy\n*[http://www.thomer.com/vi/vi.html vi lovers home page]\n*[http://www.saki.com.au/mirror/vi/ The vi Editor and its clones and programs with a vi like interface]\n*[http://www.theregister.co.uk/2003/09/11/bill_joys_greatest_gift/ "Bill Joy's greatest gift to man – the vi editor,"] from ''The Register''\n*[http://www.viemu.com/a-why-vi-vim.html explanation of modal editing with vi -- "Why, oh WHY, do those #?@! nutheads use vi?"]\n\n[[Category:Text]]\n[[Category:Text/Editing]]\n\n\n\n\n\l!--[[ar:في آي]]--\g\n\l!--[[bn:ভিআই]]--\g\n\l!--[[cs:Vi]]--\g\n\l!--[[de:Vi]]--\g\n\l!--[[es:Vi]]--\g\n\l!--[[fa:ویآی]]--\g\n\l!--[[fr:Vi]]--\g\n\l!--[[gl:Vi]]--\g\n\l!--[[ko:Vi]]--\g\n\l!--[[id:Vi]]--\g\n\l!--[[it:Vi (software)]]--\g\n\l!--[[la:VI]]--\g\n\l!--[[hu:Vi]]--\g\n\l!--[[ms:Vi]]--\g\n\l!--[[nl:Vi (Unix)]]--\g\n\l!--[[ja:Vi]]--\g\n\l!--[[pl:Vi (program)]]--\g\n\l!--[[pt:Vi]]--\g\n\l!--[[ru:Vi]]--\g\n\l!--[[fi:Vi]]--\g\n\l!--[[sv:Vi (textredigerare)]]--\g\n\l!--[[th:Vi]]--\g\n\l!--[[vi:Vi]]--\g\n\l!--[[tr:Vi]]--\g\n\l!--[[uk:Vi]]--\g\n\l!--[[zh:Vi]]--\g |

![Bluetooth Retro Handset [ThinkGeek] Bluetooth Retro Handset [ThinkGeek]](http://www.ftjcfx.com/image-3067719-10356334?imgurl=http%3A//www.thinkgeek.com/images/products/front/bluetooth_retro_handset_new.jpg)
![LED Binary Watch - Yes, it shows the time in Binary! [ThinkGeek] LED Binary Watch - Yes, it shows the time in Binary! [ThinkGeek]](http://www.ftjcfx.com/image-3067719-10356334?imgurl=http%3A//www.thinkgeek.com/images/products/front/ledbinarywatch.jpg)
![Linksys WRT600N Linksys Ultra RangePlus Dual-Band Wireless-N Gigabit Router with Storage Link [Amazon] Linksys WRT600N Linksys Ultra RangePlus Dual-Band Wireless-N Gigabit Router with Storage Link [Amazon]](http://openx.eclecticdave.com/images/41Q%2Bu9V4jWL._SL160_.jpg)

