Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a.

Similar presentations


Presentation on theme: "CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a."— Presentation transcript:

1 CS465 - UNIX The vi Editor

2 Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a very old line-oriented editor ex an enhanced version of ed vi the most commonly used editor

3 More Unix Editors emacs full-screen, fully-extensible editor created in the MIT AI Labs pico the pine editor joe Joe’s Own Editor jove Jonathan’s Own Version of Emacs and doubtless many others… Choose any one you like, but learn vi!

4 The vi Editor Created by Bill Joy at UCB Visual Interface to the ex line editor Holds file being edited as an internal buffer –Screen acts as a window onto the buffer Operates in two basic modes –Command mode –Insert mode

5 vi Modes Command Mode ( default when starting vi ) –Allows user to give commands such as: delete text search for strings search & replace save changes abort editing session without saving changes exit the vi editor Input Mode –Allows user to enter and minimally edit text

6 Starting vi vi –Starts vi with an empty buffer vi file –Starts vi and opens file for editing vi +n file –Starts vi and opens file at line n vi +/pattern file –Starts vi and opens file at the first line matching pattern NOTE: vi always starts in command mode

7 Possible Error If you see: "unknown": Unknown terminal type or if vi just doesn’t act right… Exit vi and type: –If you logged in via cygwin: $ TERM=cygwin;export TERM –If you logged in via telnet: $ TERM=ansi;export TERM

8 vi — command mode In command mode every character typed is a command You can move around in the buffer Characters/lines can be deleted or moved To enter any text, you must first shift to insert mode

9 vi — insert mode In insert mode characters typed are entered into the buffer as entered Shift from command to insert mode using: i insert text before cursor a append text after cursor Then type in your text: –Press ENTER before the end of the line (i.e. do not use word-wrap). –Tilde “~” characters below text represent end of file.

10 Correcting Text as you Enter it Error Correction (As you type): h Delete a letter w Delete a word u Delete a line When you’re done, shift from insert mode back to command mode by pressing the ESC (escape) key.

11 Moving around the file In command mode you can navigate through the file. You can choose to move: –to a position within the buffer –to a position on the screen –to a particular text string

12 Examples: HMove to top line on screen L Move to last line on screen M Move to middle line on screen ^ Move to start of current line $ Move to end of current line f Move forward one screen b Move backwards one screen You can also use the arrow keys.... Moving around the file

13 More movement nG Go to line n /text Find text (forward search) ?text Find text (backward search) n Find next occurrence of text (same direction) N Find next occurrence of text (opposite direction)

14 Deletion Commands xDeletes current character dwDeletes to the end of the word ddDeletes the current line uUndo. “Undoes” the last operation that user performed rReplaces current character cwReplaces the current word ccReplaces the current line

15 Redrawing the Screen Occasionally your screen display will get messed up due to: –A write message –A system message –Some other unknown To fix it, re-draw the screen: l(lowercase “L”)

16 Complex Commands Typing the : (colon) character in command mode causes a prompt to appear at the bottom of the screen ex commands can be typed here :1 Move to beginning of the file :$ Move to end of the file :n Go to line n You must always type after ex commands

17 Reading and Writing files More ex commands: :r filename read the named file into the buffer :w filename write the buffer to named file :w rewrite the buffer to an already named file

18 Saving your vi Session When you create a file using vi, all work performed during vi session is stored in a buffer (temporary storage) until you save your work. When saving, changes in the buffer are added to a new (empty) file if creating a new file, or changes in work buffer modify existing (previously created) file

19 Saving your vi Session To save your vi session, you must make sure you are in command mode: – Press To save your changes and exit: – Type ZZ (two capital Z’s)

20 Aborting Your Editing Session If you make a huge mistake in your editing session (that undo cannot solve), you can abort your session without modifying the contents your file (dump the work buffer). First make sure you are in command mode: Press Then to abort the current editing session, press: :q!


Download ppt "CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a."

Similar presentations


Ads by Google