From LQWiki
vi is a text editor originally written by Bill Joy. It is unique in that it has two primary modes, a command mode and an edit mode. When your first start the program, it starts in command mode where anything you type is treated as a command. Many people find vi hard to use, but a version of vi can be found on all Unix and Unix-like systems including Linux, and its existence is assured in the POSIX standard. It is therefore useful to know some basic commands. Vi vs Emacs is a source of holy wars, but that issue has been, for the most part, laid to rest by easier to use text editors, including WYSIWYG ones. Vi can be confusing at first, but when learned, some people swear by it.
Contents |
Commands
Since vi is a modal editor, one has to switch modes to issue a command. While this may sound tedious at first, as one experience grows with the editor, this becomes quite natural. Command mode is entered by pressing the escape key, and entering i or a gets the user back into entering plaintext. Commands can often be prefixed by a number to represent repetition of that command by that number (for example, dd deletes one line, 3dd deletes three). Marks and movement commands can be used to operate on larger chunks of text.
Basic commands
Some of the more common commands and their meanings:
i - insert x - delete one character :w - save (write) :wq - save (write) and quit
Other useful commands
ZZ - another way to save and quit
:q! - quits without saving the file
:w - saves the file (note that appending q will save and then quit)
:w path/filename - save the file you are working on in the directory path called filename
/some text - searches from your current position forward for "some text"
pressing / again will search for the last thing you searched for.
To search backwards, use ? instead of /
Navigation
Vi also has some handy ways of moving around in a document. In command mode, the letters h,j,k,l will move the cursor left, down, up, right respectively. 0 (zero) will move you to the beginning of the line and $ will move you to the end of the line.
If you have a more modern keyboard with arrow keys, the bindings are set up so you can use these as well. However, many experienced vi users do not use the arrow keys - navigating can be done without having to move one's hands a great distance.
Deleting
d^ - Deletes from the current position to the beginning of the line d$ - Deletes from the current position to the end of the line dw - Deletes from the current position to the end of the word 3dd - Deletes 3 lines from the current position downwards d/x - Delete up to (but not including) the first occurrence of x after the cursor position
Undo
u - Undo the last changes
Copying
y^ - Copy from the current position to the start of line y$ - Copy from the current position to the end of the line yw - Copy from the current position to the end of the word 3yy - Copy 3 lines in downward direction from the current position. y/x - Copy up to (but not including) the first occurrence of x after the cursor position
Pasting
p - Pastes after the cursor P - Pastes before the cursor np - Pastes text n times
Clone versions
The original vi did not have sources available and was not free, but now, has been relicensed and is available for download [1]. Because the original vi was not free, clones were created.
vim
vim is probably the most popular vi clone and most Linux distributions come with vim. Vim is an improved version of the vi editor distributed with most UNIX systems. Unlike the original vi, it also has a graphical version called gvim. Vim comes with a tutorial on the basics, which can be started by running the command 'vimtutor' in the shell.
Vim isn't a word processor. Although it can display text with various forms of highlighting and formatting, the formatting is just on screen and it still saves the file as plain text. If you wish to use it as a word processor, you will need to use it in combination with a typsetting language such as TeX or LaTeX.
nvi
Short for new vi, it was developed by Keith Bostic at University of California at Berkley. In the early 1990s, BSD developers wanted a vi whose source code could be freely distributed. They started with elvis 1.8 though little elvis code still exists. nvi is the de facto vi clone under BSD systems.
nvi is very close to the original vi but with the original limits removed and some features added: split screen editing; file completion; infinate undo/redo and overstrike mode. Nvi does not include many of the little used features that exist in VIM. It is lighter than VIM.
elvis
elvis was written and is currently maintained by Steve Kirkendall. An early version (1.8) was the basis for nvi. It is available on many operating systems.
vile
vile was written by Paul Fox, Kevin Buettner and Thomas Dickey (who is the maintainer). It is available for many operating systems. Unlike the other vi clones it does not try to be precisely vi, but has an Emacs flavor.
External links
- Official VIM website (www.vim.org)
- VI iMproved
- nvi (www.bostic.com)
- elvis (elvis.the-little-red-haired-girl.org)
- another version of vi
- Vi Like Emacs website
- List of the commands in vi (www.morris.umn.edu)
- vi tipsheet (www.udel.edu)

This page is available under a