1 / 51

Chapter 6

Chapter 6. The vi Editor. Topics. About vi Getting Started: Creating and Editing Introduction to vi Features Command Mode – Moving the Cursor Changing text. Topics. Searching & Substituting for a String Miscellaneous Commands Yank Put and Delete Reading and Writing Files

calla
Télécharger la présentation

Chapter 6

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. Chapter 6 The vi Editor

  2. Topics • About vi • Getting Started: Creating and Editing • Introduction to vi Features • Command Mode – • Moving the Cursor • Changing text

  3. Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques

  4. About vi • Started out as ed • Line editor – processes commands against a single line • Displays only 1 line at a time • Cumbersome and awkward to use

  5. About vi • Next out as ex • Line editor – similar to ed • Added vi mode – visual mode • Displayed full screen of data • Provided Additional functionality

  6. About vi • Today vi • Many variations • LINUX uses vim • vi has different options than vim • Extremely Powerful • Complex command structure • Works when all else fails

  7. Topics • About vi • Getting Started: Creating and Editing • Introduction to vi Features • Command Mode – • Moving the Cursor • Changing text

  8. Getting Started • Specifying a terminal • Normally system will assign terminal attributes • vi takes advantage of terminal capabilities • Smart vs Dumb

  9. Getting Started • An editing session • Start vi by typing …$ vi someNewFileName • vi presents a screen identifying this as a new file.

  10. ~ are used as place holder Indicates file being created

  11. Getting Started • An editing session • vi has two mode • Command • Input • Default is Command Mode • Quit vi without saving by typing in command mode :q!

  12. The : sets last line mode The q! says to quit immediately

  13. Getting Started • Command Mode • Executes commands based on the keys pressed. • Commands (case sensitive) • Cursor movement • Change or Delete existing text • Switch to input mode

  14. Getting Started • Command Mode • Switching to input mode • i – insert before cursor • I – insert at beginning of line • a – append after cursor • A – append at end of line • o – open line below cursor • O – open line above cursor

  15. Getting Started • Input Mode • Anything you type is stored in the file buffer and echoed back to the terminal. • Navigation may be available through the arrow keys depending on your terminal

  16. Getting Started • Input Mode • The terminal control keys can be used in input mode to navigate. • Cntl+W, Cntl+H, Cntl+U • Limited control

  17. Getting Started • Input Mode • Trouble Getting around?Go back to command mode. It’s easy • Press ESCape key • If already in command mode terminal will beep/click/flash or otherwise complain

  18. Getting Started • Command mode Navigation • Arrow key will move Keyboard – Move left one character – Move right one character – Move down one line – Move up one line h l j k

  19. Getting Started • Command Mode • Deleting Text • dd – delete one line at cursor • d – delete two lines at cursor • dw – delete word to the right of cursor • Oops-- • Undo last action – u

  20. Getting Started • I Quit !!!! • ZZ – writes the file and exits • :q! – exit Now! No save

  21. Topics • About vi • Getting Started: Creating and Editing • Introduction to vi Features • Command Mode – • Moving the Cursor • Changing text

  22. Introduction to vi Features • Simple Online Help • :help • Similar to info or man for vim • Tutorial • vimtutor

  23. Introduction to vi Features • The five faces of vi • ex – command mode • ex – input mode • vi – is a mode of the ex editor • Command mode • Input mode • Last line mode

  24. Introduction to vi Features • The vi display • The status line • Error messages • File status (read-only) • Special characters • ~ - Identifies un-used area

  25. Introduction to vi Features • The vi display • If the terminal becomes unreadable due to scrolling or messages from others • Use the re-draw function Cntl+L Clears screen and re-paints buffer

  26. Introduction to vi Features • Correcting Text as you type • Back-space to the area you want and change the input mode to replace (Shift R) • Remember commands are case sensitive!

  27. Introduction to vi Features • The Work Buffer • Allocated when vi is started • Changes are made to the buffer • Overlays the file when saved • Use view for read-only files

  28. Introduction to vi Features • Line Length & File Size • Maximum line length is limited to the size of memory • Maximum file size is limited to the available drive space

  29. Introduction to vi Features • Split Screens • :vi – can support multiple split screens • Switching between screens • Cntl+W • :e

  30. Introduction to vi Features • Split Screens can be manipulated to the foreground or background • :bg – send to background • :fg – rotate to foreground • :display s – display all screens in background

  31. Introduction to vi Features • File Locking • When vi opens a file it locks it • Other vi sessions will allow others to onlyread the original file. • How does it do that?

  32. Introduction to vi Features • The same way it can recover an aborted editing session. • Creates a .swpfile which can be used to re-cover some or all of the previous editing session • vi –r filename

  33. Topics • About vi • Getting Started: Creating and Editing • Introduction to vi Features • Command Mode – • Moving the Cursor • Changing text

  34. Cmnd Mode - Moving the Cursor • For one line only • fchr– find next character • Fchr– find previous character • W – cursor to next word • B – cursor to previous word

  35. Cmnd Mode - Moving the Cursor • )– go to end of sentence • (– go to beginning of sentence • }– go to next paragraph mark • {– go to prev. paragraph mark

  36. Cmnd Mode - Moving the Cursor !# • Hey! BUDF Cntl yourself • Cntl+B – Back 1 screen • Cntl+U – Up ½ screen • Cntl+D – Down ½ screen • Cntl+F – Forward 1 screen

  37. Cmnd Mode – Changing • Change command • c3w – Change from cursor to end of 3rd word • Deletes 3 words right of cursor • Sets insert mode

  38. Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques

  39. Search & Substitution • Search Command syntax • /expr.– find the next whatever • ^– Beginning of line • $– End of line • •– Any character • \< – Beginning of word • \> – End of word • [] – Character class definition

  40. Search & Substitution • Substitute Command syntax • :addr expr. s/search /replace /options • addr expr. • Starting line , ending line • 1 – first line of file • • – current line of file • $– Last line of file

  41. Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques

  42. Join the party • Miscellenous • J –Joins 1 or more lines into one by removing the newline characters • Cntl+G – Re-displays the status line • •(period) – repeats the last command

  43. Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques

  44. Put that Yank in the Delete Bin • The General Purpose Buffer • P or p – copy text from GP buffer to Work Buffer • Y or y – Yank (copy) into GP buffer • D or d – Delete from Work Buffer insert into GP buffer • There are 26 Additional “named” buffers. (“a – “z )

  45. Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques

  46. Read ing, Write ing & Rithmatic • Read command will copy files into the addressed line of the Work Buffer. • :addr expr. r filename • Write command will write all or part of the Work Buffer to a file. • :addr expr. w filename • :addr expr. w! filename • :addr expr. w>> filename

  47. Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques

  48. Setting Parameters • Parameters are used to configure vi at start-up. • These can be set or reset at the command line. Or in lastline command mode. • Common Parameters • (no)number, wrapmargin, (no)showmode, (no)flash, (no)ignorecase,

  49. Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques

  50. Advanced commands • I’ll Edit one more for the road • :e filename • Edits the new file if current buffer is unchanged • :e! filename • Edits the new file even if current buffer has changed • Preserves the named buffers

More Related