510 likes | 642 Vues
This guide provides an in-depth exploration of the vi editor, covering everything from basic functions to advanced techniques. Learn how to create and edit files, navigate command and input modes, and use powerful commands for text manipulation. Discover how to manage multiple files and screens, undo changes, and customize your editing environment. Whether you're a beginner or looking to enhance your skills, this resource will equip you with the knowledge needed for efficient editing in vi.
E N D
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 • Setting Parameters • Advanced Editing Techniques
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
About vi • Next out as ex • Line editor – similar to ed • Added vi mode – visual mode • Displayed full screen of data • Provided Additional functionality
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
Topics • About vi • Getting Started: Creating and Editing • Introduction to vi Features • Command Mode – • Moving the Cursor • Changing text
Getting Started • Specifying a terminal • Normally system will assign terminal attributes • vi takes advantage of terminal capabilities • Smart vs Dumb
Getting Started • An editing session • Start vi by typing …$ vi someNewFileName • vi presents a screen identifying this as a new file.
~ are used as place holder Indicates file being created
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!
The : sets last line mode The q! says to quit immediately
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
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
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
Getting Started • Input Mode • The terminal control keys can be used in input mode to navigate. • Cntl+W, Cntl+H, Cntl+U • Limited control
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
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
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
Getting Started • I Quit !!!! • ZZ – writes the file and exits • :q! – exit Now! No save
Topics • About vi • Getting Started: Creating and Editing • Introduction to vi Features • Command Mode – • Moving the Cursor • Changing text
Introduction to vi Features • Simple Online Help • :help • Similar to info or man for vim • Tutorial • vimtutor
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
Introduction to vi Features • The vi display • The status line • Error messages • File status (read-only) • Special characters • ~ - Identifies un-used area
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
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!
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
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
Introduction to vi Features • Split Screens • :vi – can support multiple split screens • Switching between screens • Cntl+W • :e
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
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?
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
Topics • About vi • Getting Started: Creating and Editing • Introduction to vi Features • Command Mode – • Moving the Cursor • Changing text
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
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
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
Cmnd Mode – Changing • Change command • c3w – Change from cursor to end of 3rd word • Deletes 3 words right of cursor • Sets insert mode
Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques
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
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
Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques
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
Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques
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 )
Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques
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
Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques
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,
Topics • Searching & Substituting for a String • Miscellaneous Commands • Yank Put and Delete • Reading and Writing Files • Setting Parameters • Advanced Editing Techniques
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