Table of contents
Vi is a screen-oriented text editor created for the Unix operating system.
Basic Vi commands
There are two modes when in Vi
Command mode( press ":<command>" )
Insert mode( press "i" then Esc to enter command mode)
To start ;
To use vi on a file, type in the vi file name. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.
To exit ;
Usually, the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file.
:x (Enter) - quit vi, writing out modified file to filename in the original invocation
:wq (Enter) - quit vi, writing out modified file to filename in the original invocation
:q (Enter) - quit/exit vi
:q! (Enter) - quit vi even though the latest changes have not been saved for this vi call
Inserting Text
The following commands put the vi into insert mode, thus, the <Esc> key must be pressed to terminate the entry of text and to put the vi editor back into command mode.
"i" - insert text before the cursor until {Esc} is hit
"I" - insert text at beginning of the current line, until {Esc} is hit
"a" - append text after the cursor, until {Esc} is hit
"A" - append text to the end of the current line, until {Esc} is hit
"o" - open and put text in a new line below the current line, until {Esc} is hit
"O" - open and put text in a new line above the current line, until {Esc} is hit
Cutting and Pasting Text
"yy" (yank)- copy the current line into the buffer
"p" - paste the line(s) in the buffer into the text after the current line
Saving and Reading files
":r" <filename> (Enter) - read the filename and insert it after the current line
(the line with cursor)":w" - write current contents to file named in original vi call
N/B; Still being written.