Make your own free website on Tripod.com

BigCalm : AIX UNIX : VI Help
Search

Vi Help


vi /V-I/, not /vi:/ and never /siks/ n.
[from `Visual Interface'] A screen editor crufted together by Bill Joy for an early BSD release. Became the de facto standard Unix editor and a nearly undisputed hacker favorite outside of MIT until the rise of EMACS after about 1984. Tends to frustrate new users no end, as it will neither take commands while expecting input text nor vice versa, and the default setup on older versions provides no indication of which mode the editor is in (years ago, a correspondent reported that he has often heard the editor's name pronounced /vi:l/; there is now a vi clone named `vile'). Nevertheless vi (and variants such as vim and elvis) is still widely used (about half the respondents in a 1991 Usenet poll preferred it), and even EMACS fans often resort to it as a mail editor and for small editing jobs (mainly because it starts up faster than the bulkier versions of EMACS). --
The Jargon (4.2.3) file


Overview Moving Edit Mode EXing Out
Yanking yer bits Information Commands Multipliers Ex Bits
Buffers Korn Shell



Overview

vi is rather strange as a word processor - it is different from almost any other text processor because it has two different modes - i.e. edit and control modes. Control mode allows moving,ex commands,and general editing commands - to enter control mode (you should be in control mode when you first enter vi) just press Escape. Edit mode allows entering of text - see section below on the different ways of entering edit mode. There's also some notes on command line options on the handycommands page

If you've never used vi before, use 'i' (insert text), 'a' (append text), 'R' (overwrite text), 'dd' (delete line), 'x' (delete char), 'u' (undo last change), ':q!' quit without saving, and 'ZZ' save and exit - and remember to press escape after every edit.

There's almost always more than one way to do it in vi - a close examination of people (like myself) who use vi a lot reveals great differences in how they edit a text document. (For example, I never use numbered or alphabetic buffers, but use mark references and temporary files instead). There are numerous vi clones on various operating systems, so that unix lovers can have their favourite text editor whatever OS they're using.


Moving (Apart from obvious arrow key stuff)

{ Back a paragraph
} Forward a paragraph
w forward a word
b back a word
' moves to a marked character, e.g. 'a will move to mark a
f<char> moves to the next occurence of <char>
^F/^D page down
^B/^U page up
^R refresh
0 move to beginning of line
$ move to end of line
<number> return move down number of lines
<number> uparrow move up number of lines
<number> left move left number of chars
<number> right move right number of chars
/text search for text (n to repeat, N to repeat backwards)
?text search backwards for text
:<number> move to line number - also :$ - move to end
n repeat last search
N repeat last search backwards
G move to end
<number>G move to line number
~ change case of letters
k cursor up
j cursor down
l cursor right
h cursor left
e move to end of word (nearly the same as w)
^E Scroll the screen down without moving the cursor
^Y Scroll the screen up without moving the cursor


Edit Mode

PRESS ESCAPE AFTER EVERY EDIT!!!!!!

a append text
i insert text
R overwrite text
^[ (ESC) exit to control mode **** VERY IMPORTANT ****
o insert line below cursor and enter edit mode
O insert line above cursor and enter edit mode
cc blanks line, and allows editing
A append at end of line
s substitute current char with characters
. repeat last edit
cw change word


EXing Out

:wq save and exit
:q exit
:q! force exit without saving
:w save
:w! forced write (if permissions are set wrong for example)
:w <filename> write to a different file
:x save and exit
:r <filename> read filename in at cursor point
ZZ save and exit
:e! start editing again from time of last write.
:e <file> edit new file
:!<shell command> execute shell command
:!ksh exit to shell. type 'exit' to return to vi


Yanking yer bits

dd deletes a line (d<number><CR> deletes that number of lines + 1)
D deletes to the end of a line
x deletes a character
y yank, erm, 'y6' for example will yank the 7 lines following the cursor into a buffer (yy or Y yanks one line) , where it may then be 'p'ut (which is also a form of 'undo' if you accidentally wipe a line using 'dd')
J joins two lines together. ( There is a bug in AIX vi which can cause this to scroll down a page and put you in insert mode. Pain in the bum)
m mark, e.g. 'ma' will set a marker 'a', which can then be used by an 'ex' command. - e.g. to copy a part of the text out to a different file, place two marks, one at the beginning, and one at the end of the text you wish to save out, and use the command :'a,'b w filename
p put lines that have been yanked or deleted
u undo last change
U undo all recent changes on a line
'a,'b w delme1 From mark a to markb write to new file delme1
'a,'b w>> delme1 From mark a to mark b append to file delme1
!!sh will execute the current line as a command on the shell, and insert the result into the document (good command - to pull a list of a directory into vi, just insert a line somewhere that says 'ls' and when you've got the cursor on that line do !!sh


Information Commands

^g shows the file currently being edited and the current line


Multipliers

Most vi commands accept multipliers - e.g.
10x will delete 11 characters
100>> will move the next 100 lines one tab to the right
9y<CR> will yank 10 lines into the buffer
79i=<ESC> will insert 79 '=' signs
50k will move you 50 lines up
c3w will substitute the next three words for whatever you type


Ex Bits

Try:

typing 'Q' will enter ex - typing vi while in ex mode returns

Search and Replace

:1,$ s,findtext,replacewith

Or, from start to end s(ubstitute),text,with other text. Any non-alphanumeric chars must be prefixed with a backslash in the findtext and replacewith section, '$' means end of line and '^' means beginning. e.g.
:1,$ s,31\/10\/96,30\/11\/96 - replaces all occurrences of 31/10/96 with 30/11/96

Special chars for search and replace:
'a mark a (marked in vi using 'ma')
$ end of line or end of file (depending where used)
1 beginning of file
^ beginning of line
\ general escape char to print characters other than alphanumeric ones. e.g. the text ^"\ would become \^\"\\
e.g. To put a '#' symbol at the beginning of every line between mark references a and b, do :'a,'b s,^,#


Buffers

Numbered
Increases the scope of the undo(u) command - whenever 'd' deletes more than a part of a line, a copy is placed in a numbered buffer. For example if you were to delete the previous 4 lines using 'dd' 4 times you could get them all back by doing: "4p "3p "2p "1p (quotes are actual).

Alphabetic
Allow you to copy lines to named buffers - while using commands y or d. If you prefix any y command with "<lower-case letter> then it will copy the results of that command into the buffer <lower-case letter>. For example, typing "xy9 would yank 10 lines into a buffer called 'x'. You can then put it by doing "xp


Korn Shell

The Korn shell can have some of the features of the vi editor put into it. Either do 'ksh -o vi' to change type of shell or 'set -o vi' if you are already using the korn shell. Then, the shell will function as normal, except when you press <escape>. e.g. Pressing <escape>k will bring up the previous command.




---------------- End of VIHelp file ----------------


Valid HTML 4.0!


This Page Was Last updated 28/09/01 Copyright Jonathan Daniel 2001