You are on page 1of 15

THE vi EDITOR

CONTENTS
The vi basics Input mode entering and replacing text Saving text and quitting the ex mode Navigation Editing text

vi basics
To write and edit some programs and scripts, we require editors UNIX provides vi editor for BSD system created by Bill Joy Bram Moolenaar improved vi editor and called it as vim (vi improved) on Linux OS

vi <filename> Command mode non existant lines Input mode enter, edit text Current cursor position Current line

ctrl-w to delete any wrong word esc to return to command mode Beep indicates a key pressed unnecessarily Ex mode execute mode last line mode :x saves file on disk and shifts the control from editor to prompt mode ($)

Command mode copy and delete text, cant enter or replace text Input mode every key pressed is a text ex mode save and perform substitution by pressing : and get back to default command mode

THE REPEAT FACTOR


vi provides repeat factor in command and input mode commands Command mode command k moves the cursor one line up 10k moves cursor 10 lines up

Undo whenever you make a mistake esc u Clearing the screen in command mode ctrl-l Dont use (capslock) vi commands are case-sensitive Avoid using the PC navigation keys

INPUT MODE
:set showmode messages like INSERT MODE, REPLACE MODE, CHANGE MODE, etc will appear in the last line Pressing i changes the mode from command to input To append text to the right of the cursor position, we use a, text

I and A behave same as i and a, but at line extremes I inserts text at beginning of line A appends text at end of line Opening a new line o opens a new line below the current line

r<letter> replacing a single character s<text/word> replacing text with s R<text/word> replacing text with R Press esc key to switch to command mode after you have keyed in text

INPUT MODE COMMANDS


COMMAND i a I A o O r s S FUNCTION inserts text appends text inserts at beginneing of line appends text at end of line opens line below opens line above replaces a single character replaces with a text replaces entire line

SAVING TEXT AND QUITTING


:W saves file and remains in editing mode :x saves and quits editing mode :wq saves and quits editing mode :w <filename> save as :w! <filename> save as, but overwrites existing file :q quits editing mode :q! quits editing mode by rejecting changes made :sh escapes to UNIX shell :recover recovers file from a crash

:n1,n2w sample.db

writes line n1 to n2 to file named sample.db

:.w sample.db file sample.db


:$w sample.db

writes the current line to

writes the last line to sample.db

THANK YOU