18
VI EDITOR University of Mississippi

VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Embed Size (px)

Citation preview

Page 1: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

VI EDITOR University of Mississippi

Page 2: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•What is Vi ?

▫Vi is a screen based editor.▫The screen of your terminal will act as a

window into the file you are editing.▫Most commands to Vi move the cursor

around the file.▫Faster (than pico) for those who can

type▫Available standard on most Unix

systems

Page 3: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•Starting the Vi editor

▫vi lets you create new files or edit existing files.

▫Command to start Vi : vi

▫Open existing (or create new) file in vi:vi example1

Page 4: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•Modes of Operation

▫Command ModeAllows the entry of commands to manipulate

textCommands are usually one or two characters

long

▫Insert Mode Puts anything you type on the keyboard into

the current file

Page 5: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•Modes of Operation

▫Command ModeAllows the entry of commands to manipulate

textCommands are usually one or two characters

long

▫Insert Mode Puts anything you type on the keyboard into

the current file

Page 6: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•Vi starts in command mode by default

•Most commonly used commands to get into insert mode are a and i

•Once in insert mode, you get out of it by hitting the Esc key

Page 7: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•From within vi:

Hit i key to enter edit Insert ModeType This is EASY.Then hit the escape key, for Command

Mode

Page 8: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•Saving files and exiting the Vi editor

▫:q Quit the editor▫:q! Quit the editor without saving the

changes to the file.▫:w Save the file you are editing▫ZZ The editing buffer is written to

the file only if any changes were made.

▫:wq :- Same effect as ZZ

Page 9: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

To ensure you are in command mode:Hit the Esc key twice.

To save your file:Type :w to write (save) the

file.

To save your file under a different name:Type :w example2

To save your file and quite:Type :wq

Page 10: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•How to type commands in command mode[count] command [where]

count : Its a number

where : Specifies how many lines or how much of the document the command affects. It can also be any command that moves the cursor.

Page 11: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

• Moving from Command to Insert Mode▫a

Enter insert mode; the characters typed will be inserted after the current cursor position. If a count is specified, then the inserted text will be repeated that many times

▫iEnter insert mode, the characters typed will be inserted before the current cursor position. If a count is specified, the inserted text will be repeated that many times

oEnter insert mode; will start a new line beneath current line.

Page 12: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor•Moving the cursor, in Command Mode

h move cursor to the leftl move cursor to the rightj move cursor upk move cursor down

Use vi to edit example2 to have these 2 lines:This is not hard.This is VERY easy.This is not hard at all.

Page 13: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor•Some simple Vi Commands

▫rreplace one character under the cursor. Specify count to replace that many characters.

▫RStarting from the current cursor position, replace the characters with the one typed on the keyboard

▫xDelete character under the cursor. Count specifies how many characters to delete

Practice these commands to further edit example2

Page 14: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor•Cutting text

d^Deletes from current cursor position

to the beginning of the line d$

Deletes from current cursor position to the

end of the line Dw

Deletes from current cursor position to the

end of the word dd

Deletes one line from current cursor position. Specify count to delete many lines.

Page 15: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor•Yanking and Pasting

ylyank a single character. Specify count

to yank more characters yw

yank a single word. Specify count to yank more words

yyyank a single line. Specify count to

yank more lines p

paste the text that was either deleted or yanked previously

m mark the current line

Page 16: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Practice Yanking, Deleting, and Pasting Lines of Text

Use vi to create a new file: example3, with these lines:

OneTwoThreeFourFiveSixSevenEightNineten

Then, from command mode, enter :wq to save the file

Page 17: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

Vi Editor

•To go to a specific line in the file:linenumber

•To go to the last line in the file:G

•String Search▫/[pattern] : search forward for the

pattern▫?[pattern] : search backward for the

pattern

•To undo the last command:▫u

Page 18: VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file

More practice

Use vi to edit existing file: example3