Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.

Similar presentations


Presentation on theme: "1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor."— Presentation transcript:

1

2 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor

3 2 © 2012 John Urrutia. All rights reserved. Topics About vi Getting Started: Creating and Editing Introduction to vi Features Command Mode –  Moving the Cursor  Changing text

4 3 © 2012 John Urrutia. All rights reserved. Topics Searching & Substituting for a String Miscellaneous Commands Yank Put and Delete Reading and Writing Files Setting Parameters Advanced Editing Techniques

5 4 © 2012 John Urrutia. All rights reserved. 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

6 5 © 2012 John Urrutia. All rights reserved. About vi Next out as ex  Line editor – similar to ed  Added vi mode – visual mode  Displayed full screen of data  Provided Additional functionality

7 6 © 2012 John Urrutia. All rights reserved. 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

8 7 © 2012 John Urrutia. All rights reserved. Topics About vi Getting Started: Creating and Editing Introduction to vi Features Command Mode –  Moving the Cursor  Changing text

9 8 © 2012 John Urrutia. All rights reserved. Getting Started Specifying a terminal  Normally system will assign terminal attributes  vi takes advantage of terminal capabilities  Smart vs Dumb

10 9 © 2012 John Urrutia. All rights reserved. Getting Started An editing session  Start vi by typing …$ vi someNewFileName  vi presents a screen identifying this as a new file.

11 10 © 2012 John Urrutia. All rights reserved. Indicates file being created ~ are used as place holder

12 11 © 2012 John Urrutia. All rights reserved. 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!

13 12 © 2012 John Urrutia. All rights reserved. The : sets last line mode The q! says to quit immediately

14 13 © 2012 John Urrutia. All rights reserved. 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

15 14 © 2012 John Urrutia. All rights reserved. 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

16 15 © 2012 John Urrutia. All rights reserved. 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

17 16 © 2012 John Urrutia. All rights reserved. Getting Started Input Mode  The terminal control keys can be used in input mode to navigate.  Cntl+W, Cntl+H, Cntl+U  Limited control

18 17 © 2012 John Urrutia. All rights reserved. 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

19 18 © 2012 John Urrutia. All rights reserved. Getting Started Command mode Navigation  Arrow key will move – Move left one character – Move right one character – Move down one line – Move up one line hljkhljk Keyboard

20 19 © 2012 John Urrutia. All rights reserved. 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

21 20 © 2012 John Urrutia. All rights reserved. Getting Started I Quit !!!!  ZZ – writes the file and exits  :q! – exit Now! No save

22 21 © 2012 John Urrutia. All rights reserved. Topics About vi Getting Started: Creating and Editing Introduction to vi Features Command Mode –  Moving the Cursor  Changing text

23 22 © 2012 John Urrutia. All rights reserved. Introduction to vi Features Simple Online Help  :help  Similar to info or man for vim Tutorial  vimtutor

24 23 © 2012 John Urrutia. All rights reserved. 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

25 24 © 2012 John Urrutia. All rights reserved. Introduction to vi Features The vi display  The status line  Error messages  File status (read-only)  Special characters  ~ - Identifies un-used area

26 25 © 2012 John Urrutia. All rights reserved. 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

27 26 © 2012 John Urrutia. All rights reserved. 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!

28 27 © 2012 John Urrutia. All rights reserved. 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

29 28 © 2012 John Urrutia. All rights reserved. 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

30 29 © 2012 John Urrutia. All rights reserved. Introduction to vi Features Split Screens  :vi – can support multiple split screens  Switching between screens  Cntl+W  :e

31 30 © 2012 John Urrutia. All rights reserved. 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

32 31 © 2012 John Urrutia. All rights reserved. Introduction to vi Features File Locking  When vi opens a file it locks it  Other vi sessions will allow others to only read the original file. How does it do that?

33 32 © 2012 John Urrutia. All rights reserved. Introduction to vi Features The same way it can recover an aborted editing session.  Creates a.swp file which can be used to re-cover some or all of the previous editing session  vi –r filename

34 33 © 2012 John Urrutia. All rights reserved. Topics About vi Getting Started: Creating and Editing Introduction to vi Features Command Mode –  Moving the Cursor  Changing text

35 34 © 2012 John Urrutia. All rights reserved. Cmnd Mode - Moving the Cursor For one line only  f chr – find next character  F chr – find previous character W – cursor to next word B – cursor to previous word

36 35 © 2012 John Urrutia. All rights reserved. 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

37 36 © 2012 John Urrutia. All rights reserved. Cmnd Mode - Moving the Cursor  Cntl+B – Back 1 screen  Cntl+U – Up ½ screen  Cntl+D – Down ½ screen  Cntl+F – Forward 1 screen Hey! BUDF Cntl yourself  ! #

38 37 © 2012 John Urrutia. All rights reserved. Cmnd Mode – Changing Change command  c3w – Change from cursor to end of 3 rd word  Deletes 3 words right of cursor  Sets insert mode

39 38 © 2012 John Urrutia. All rights reserved. Topics Searching & Substituting for a String Miscellaneous Commands Yank Put and Delete Reading and Writing Files Setting Parameters Advanced Editing Techniques

40 39 © 2012 John Urrutia. All rights reserved. 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

41 40 © 2012 John Urrutia. All rights reserved. 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

42 41 © 2012 John Urrutia. All rights reserved. Topics Searching & Substituting for a String Miscellaneous Commands Yank Put and Delete Reading and Writing Files Setting Parameters Advanced Editing Techniques

43 42 © 2012 John Urrutia. All rights reserved. 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

44 43 © 2012 John Urrutia. All rights reserved. Topics Searching & Substituting for a String Miscellaneous Commands Yank Put and Delete Reading and Writing Files Setting Parameters Advanced Editing Techniques

45 44 © 2012 John Urrutia. All rights reserved. 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 )

46 45 © 2012 John Urrutia. All rights reserved. Topics Searching & Substituting for a String Miscellaneous Commands Yank Put and Delete Reading and Writing Files Setting Parameters Advanced Editing Techniques

47 46 © 2012 John Urrutia. All rights reserved. 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

48 47 © 2012 John Urrutia. All rights reserved. Topics Searching & Substituting for a String Miscellaneous Commands Yank Put and Delete Reading and Writing Files Setting Parameters Advanced Editing Techniques

49 48 © 2012 John Urrutia. All rights reserved. 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,

50 49 © 2012 John Urrutia. All rights reserved. Topics Searching & Substituting for a String Miscellaneous Commands Yank Put and Delete Reading and Writing Files Setting Parameters Advanced Editing Techniques

51 50 © 2012 John Urrutia. All rights reserved. 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

52 51 © 2012 John Urrutia. All rights reserved. Advanced commands vi got a new shell  :sh  Spawns a new shell and then vi sleeps  :! command  Executes a shell command and returns to vi  !! command  Executes a shell command and returns std output and replaces current line


Download ppt "1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor."

Similar presentations


Ads by Google