Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIX Intro.86 10. vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text.

Similar presentations


Presentation on theme: "UNIX Intro.86 10. vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text."— Presentation transcript:

1 UNIX Intro.86 10. vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text

2 UNIX Intro.87 5.Deletion 6.Cut & Paste 7.File-related Commands 8.Text Substitution 9.Recovering after a Crash

3 UNIX Intro.88 1. Why use vi? v very powerful v useful simple subset of commands v portable (PCs, mainframes, etc.) v designed for slow networks v full-screen

4 UNIX Intro.89 2. vi Basics 2.1.Starting vi 2.2.Two Modes 2.3.The vi Window 2.4.When to type RETURN 2.5.Finishing a vi Session

5 UNIX Intro.90 2.1. Starting vi  vi file Start editing file v Changes are stored in a buffer, so you must save to change the file. v If the machine crashes, the buffer can usually be recovered (see later).

6 UNIX Intro.91 2.2. Two Modes v Command mode –move cursor, save, delete text, quit vi, etc. v Input mode –for inserting text –start by typing i; finish with ESC –cannot quit, delete, etc. in this mode –If in doubt, press ESC a few times. This will put you back in command mode.

7 UNIX Intro.92 2.3. The vi Window v Bottom line is the status line v Some, but not all, commands are shown on the status line. v Often you type a command and nothing appears on the screen!

8 UNIX Intro.93  Colon commands (e.g. :q! ) and search commands (e.g. /text ) require a RETURN.  Commands that start with a letter (e.g. ZZ, G ) and control characters (e.g. ^L ) do not require a RETURN 2.4. When to type RETURN

9 UNIX Intro.94 2.5. Finishing a vi Session  Get to command mode (press ESC s) ZZ save changes to the file and quit (no RETURN ) :q! quit without saving (press RETURN )

10 UNIX Intro.95 3. Moving Around 3.1.Basic Cursor Movements 3.2.Larger Moves

11 UNIX Intro.96 3.1. Basic Cursor Movements h move cursor one place to left j down one k up one l right one w move forward one word b back one word No RETURN required!

12 UNIX Intro.97 3.2. Larger Moves G go to last line G go to line number G go to line number10G ^G shows the current line number ^F Forward a screen ^B Back a screen

13 UNIX Intro.98 /text Search forward for text /func search for func /printf( search for printf( /^foo search for foo at start of line Type RETURN !

14 UNIX Intro.99 4. Inserting Text v Move to insertion point  Switch to input mode: i v Start typing; BACKSPACE or DELETE for deletion  ESC finish; back in command mode No RETURN

15 UNIX Intro.100 v Over a slow network, the screen may not refresh properly ^L refresh screen (in command mode)

16 UNIX Intro.101 5. Deletion v Must be in command mode. x Delete character that cursor is on. dd Delete current line. D Delete from cursor position to end of line u Undo last command

17 UNIX Intro.102 :i,jd Delete lines i to j :23,29d Delete lines 23 to 29 v Special line numbers:.means the current line number ^means line number 1 $means last line :.,$d Delete from current line to the end of file.

18 UNIX Intro.103 6. Cut & Paste 6.1.Cut & Paste Meaning 6.2.Cut & Paste with Deleted Text 6.3.Moving Text

19 UNIX Intro.104 6.1. Cut & Paste Meaning v Cut commands remove text from the screen, and store it in a buffer v Paste commands copy text from the buffer to the screen

20 UNIX Intro.105 6.2. Cut & Paste with Deleted Text v d or dd or D delete from screen and store text in a buffer v move cursor to new location  p paste contents of buffer to right of cursor posn

21 UNIX Intro.106 6.3. Moving Text v Cut and Paste with move  :i,jmk move lines i through j to start after line k :3,8m10 move lines 3 to 8 to start after line 10 :20m. move line 20 to after the current line :1,.m$ move lines 1 through current line to the bottom

22 UNIX Intro.107 7. File-related Commands :w file writes vi contents to new file :w >> file appends to file :w! file writes over file :w! writes over input file :r file read in file; places it starting at current cursor position

23 UNIX Intro.108 8. Text Substitution :s/old/new/g replace every occurrence of old by new. Dangerous! :s/Hat/Haad/g

24 UNIX Intro.109 :i,js/old/new/g replace every occurrence of old by new between lines i and j :2,200s/Andy/Andrew/g :1,.s/fc/function/g from line 1 to current :23,$s/pd/procedure/g from line 23 to end

25 UNIX Intro.110 9. Recovering after a Crash vi -r List files that can be recovered vi -r file Recover file.  You should make a backup of file first: cp file file.bak


Download ppt "UNIX Intro.86 10. vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text."

Similar presentations


Ads by Google