1 using editors editors let you create and edit ascii files unix normally includes two editors: vi...

21
1 Using Editors Using Editors Editors let you create and edit Editors let you create and edit ASCII files ASCII files UNIX normally includes two UNIX normally includes two editors: vi and Emacs editors: vi and Emacs Vi and Emacs are screen editors: Vi and Emacs are screen editors: they display the text you are they display the text you are creating (or editing) one screen creating (or editing) one screen at a time at a time

Post on 21-Dec-2015

234 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

11

Using EditorsUsing Editors

Editors let you create and edit ASCII filesEditors let you create and edit ASCII files

UNIX normally includes two editors: vi and UNIX normally includes two editors: vi and EmacsEmacs

Vi and Emacs are screen editors: they Vi and Emacs are screen editors: they display the text you are creating (or display the text you are creating (or editing) one screen at a timeediting) one screen at a time

Page 2: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

22

Using the vi EditorUsing the vi Editor

Called vi because it is visual – it immediately Called vi because it is visual – it immediately displays on screen the changes that you make displays on screen the changes that you make to textto text

works in different modesworks in different modes– Insert mode - lets you enter textInsert mode - lets you enter text– Command mode - lets you enter commands to Command mode - lets you enter commands to

perform editing tasksperform editing tasks

Page 3: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

33

Using the vi EditorUsing the vi Editor

To create a new file in the vi editor, type vi and the name of the new file at the command prompt

Page 4: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

44

Using the vi EditorUsing the vi Editor

When started, the vi editor is in command modeWhen started, the vi editor is in command mode– In order to insert text, you must issue the “i” command In order to insert text, you must issue the “i” command

to enter insert modeto enter insert mode– Esc key will change vi from text mode to command Esc key will change vi from text mode to command

modemode– You can repeat the line just entered with the repeat You can repeat the line just entered with the repeat

command (.)command (.)– To edit what you’ve just typed, move the cursor with To edit what you’ve just typed, move the cursor with

the various keyboard cursor movement keysthe various keyboard cursor movement keys

Page 5: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

55

Using the vi EditorUsing the vi Editor

In insert mode, every character you type appears on the screen

Page 6: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

66

Using the vi EditorUsing the vi Editor

The repeat command repeats the last insertion, or line. Now, edit the new line in order to create the next item

Page 7: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

77

Using the vi EditorUsing the vi Editor

Page 8: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

88

Vi-Correcting text keysVi-Correcting text keys

xx Deletes the character specified by the Deletes the character specified by the cursor positioncursor position

dddd Deletes the line specified by the cursor Deletes the line specified by the cursor positionposition

uu Undoes the most recent changeUndoes the most recent change

UU Undoes all the changes on the current lineUndoes all the changes on the current line

rr Replaces a character that the cursor is onReplaces a character that the cursor is on

RR Replaces characters starting from the Replaces characters starting from the cursor position, and changes vi to the text cursor position, and changes vi to the text modemode

Page 9: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

99

Exit from vi editorExit from vi editor

Save - :w Save - :w

Save as different file - :w filenameSave as different file - :w filename

Save file and exit -- :wq filenameSave file and exit -- :wq filename

Exit without saving file - :q!Exit without saving file - :q!

Page 10: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1010

practicepractice

Page 11: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1111

Using the vi EditorUsing the vi Editor

Page 12: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1212

Using the vi EditorUsing the vi Editor

Use the delete commands and the cursor movement keys to edit the text

Page 13: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1313

Using the vi EditorUsing the vi Editor

Page 14: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1414

Using the vi EditorUsing the vi Editor

Page 15: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1515

Using the vi EditorUsing the vi Editor

The status line at the bottom of the screen displays information, including line-oriented commands and error messages

Page 16: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1616

Using the vi EditorUsing the vi Editor

During text searches, you can replace, too. Use line-oriented commands in ex mode to perform this action

Page 17: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1717

Using the vi EditorUsing the vi Editor

Saving a File and Exiting viSaving a File and Exiting vi– You should always save the file before exiting You should always save the file before exiting

vi, otherwise changes are lostvi, otherwise changes are lost– To save a file and continue working on it, type To save a file and continue working on it, type

the :w (write) commandthe :w (write) command– While in command mode, use the :wq (write While in command mode, use the :wq (write

and quit) command to save and exit iv, or and quit) command to save and exit iv, or the :zz command to exit after saving the :zz command to exit after saving

Page 18: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1818

Using the vi EditorUsing the vi Editor

In vi, you can also:In vi, you can also:– Add text from another fileAdd text from another file– Leave vi temporarily to perform other UNIX Leave vi temporarily to perform other UNIX

tasks, then return to your filetasks, then return to your file– Change your display while editing, such as Change your display while editing, such as

adding line numbering to help editingadding line numbering to help editing– Copy, cut, and paste text to help editingCopy, cut, and paste text to help editing– Print text filesPrint text files– Cancel an editing sessionCancel an editing session

Page 19: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

1919

Using the vi EditorUsing the vi Editor

Page 20: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

2020

Using the vi EditorUsing the vi Editor

Page 21: 1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display

2121