1 / 22

Introduction to UNIX

Introduction to UNIX. C. Vi Editor. Overview of vi. Performance Objectives 1. Start/End VI (vi, ESC, :wq) 2. Move the Cursor and Window (h,j,k,l, ^f, ^b) 3. Insert, Change, Delete Text (i, a, x, dd) 4. Search and Replace text (/.../, :n, $s/.../.../g)

wolfe
Télécharger la présentation

Introduction to UNIX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to UNIX C. Vi Editor Vi Editor

  2. Overview of vi Performance Objectives 1. Start/End VI (vi, ESC, :wq) 2. Move the Cursor and Window (h,j,k,l, ^f, ^b) 3. Insert, Change, Delete Text (i, a, x, dd) 4. Search and Replace text (/.../, :n, $s/.../.../g) 5. Move/Copy Text (ma, d'a, p) 6. Write and Read Files (:w file, :r file) 7. Tailor the VI Environment (:set) Vi Editor

  3. UNIX Family of editors • ex line editor • ed subset of ex • vi screen editor Vi Editor

  4. Why learn vi/ex? • Available on most UNIX systems. • Works with a variety of terminals. • Needs no special keyboard definition files. • Allows the use of ex commands from vi. • Provides for a customized editing environment. Vi Editor

  5. Some Conventions • vi commands do not require a <CR>. • vi commands not echoed. • ex commands begin with : / ? • ex commands are echoed and ended with a <CR> • The character ^ represents the <ctrl> key. Vi Editor

  6. Vi Modes: • COMMAND mode • The default mode on entering vi. • Anything typed is interpreted as a command. • INSERT mode • Enter INSERT mode by typing one of several commands. • Anything typed is interpreted as data. • Exit INSERT mode by typing the <ESC> key. Vi Editor

  7. Vi Modes UNIX Shell vi filename ZZ or :wq Command Mode i a o <ESC> Input Mode Vi Editor

  8. vi Window Display Line one Line two Line three ~ ~ ~ ~ ~ ~ Line n Command line File text Null lines EX cmd line Vi Editor

  9. Vi Window Positioning vi window ^f Display Next segment File Vi Editor

  10. Basic Window Positioning • Move window forward 32 lines ^f • Move window backward 32 lines ^b • Move window forward one line ^e • Move window to line n of file :n • Move window to end of file G • Move cursor up/dn left/rt or h j k l Vi Editor

  11. Making Changes Permanent • vi uses a temp file for changes: • Write file and quit editor :wq • Undo last command: u or U • Recovery: vi -r filename Perm File Temp File :w Vi Editor

  12. Insert/Delete Functions • Del current line dd • Del current char x • Insert before current char i ... • Insert after current char a ... • Insert after current line o ... (opens file at a line) Vi Editor

  13. More Vi Functions • Open several files vi file1 file2 ... • End editor :q(does not save changes) • Redraw screen ^l (L) • Join this line with next J Vi Editor

  14. Search For a Pattern • Search forward to pattern / ... / • Search backward to pattern ? ... ? • Advance to next pattern n (forward or reverse) Vi Editor

  15. Replace A Pattern • Replace string with another :s/.../.../ (only on same line) • Replace string (global) :1,$s/.../.../g Vi Editor

  16. Moving Text • ma mark the starting position with a • d'a delete text into a buffer • p put buffer contents after cursor ma Area to be moved d’a p Insert location Vi Editor

  17. Copying Text • ma mark the starting position with a • y'a yank text into a buffer • p put buffer contents after cursor ma Area to be copied y’a p Insert location Vi Editor

  18. Writing to a file • write current file :w • write named file :wfilename • overwrite named file :w! • write lines m - n to named file m,nw file Vi Editor

  19. Useful Functions • Re-edit current file, discard changes :e • Edit named file :e file • Read in and insert file at cursor :r file • Execute command and return to vi :!cmd Vi Editor

  20. Tailoring the Environment • For current session :setoptions<cr> • Example: :set nu <cr> will set line numbers • To view possible settings: :set all noautoindent nonumber noslowopen autoprint nonovice tabstop=8 noautowrite nooptimize taglength=0 nobeautify paragraphs= tags=tags /usr/lib/tags directory=/tmp prompt term=vt100 noedcompatible noreadonly noterse noerrorbells redraw timeout flash remap ttytype=vt100 hardtabs=8 report=5 warn noignorecase scroll=11 window=23 nolisp sections= wrapscan nolist shell=/bin/csh wrapmargin=0 magic shiftwidth=8 nowriteany mesg noshowmatch nomodelines noshowmode Vi Editor

  21. Order of Evaluation • On startup, vi sets options defined by EXINIT variable. • Then options defined in ~/.exrc file. • Settings in ~/.exrc take precedence. • Setting in .exrc file in CWD take precedence over ~/.exrc file and EXINIT. • Finally, :set options of current session take precedence during that session. Vi Editor

  22. End of Module Complete VI Editor Exercises Vi Editor

More Related