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

Slides:



Advertisements
Similar presentations
Course Outline: System Requirements What is Vi Editor Conventions
Advertisements

In the last Session… ls -l command seven fields nine permissions of a file ls -ld file ownership file permissions (three-tiered file protection system)
June 1, 1999Vi Editor1 Introduction to UNIX C. Vi Editor.
CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
A Guide to Unix Using Linux Fourth Edition
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Vi Editor TA for ITIS3100: Xu Fei
Chapter 5 Editing Text Files
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
CS 497C – Introduction to UNIX Lecture 9: The vi/vim Editor Chin-Chih Chang
Starting Vi Opening an existing file vi filename Creating a new file vi filename In your workshop directory, create a new file called mysong vi mysong.
CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a.
Copyrights© 2008 BVU Amplify DITM Basics of OS,UNIX/LINUX and Shell programming Page:1 Lesson 3: Vi- editor By Simi By Simi.
CSCI 330 T HE UNIX S YSTEM Editing files. E DITOR C ONCEPTS Editing a file is to modify the content of a file Text editor: Enter and modify text in a.
Using Linux Text Editors. Use Non-Graphical Linux Text Editors Graphical Text Editor.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Chapter 3 Mastering Editors
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving vi Session Aborting Editing Session.
T HE VI EDITOR. vi has 2 modes: command mode (initial or "default" mode) insert mode [Esc] is used to switch to command mode. In general, vi commands:
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 7 Editing.
Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Chapter8 The vi Editor. Introduction to vi u Modes of Operation u The Work Buffer  During the editing session, vi make all changes in the buffer  Advantage.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
1 © 2014 John Urrutia. All rights reserved. Chapter 7 The “ Emacs “ Editor.
UNIX Intro vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text.
4 Editing files and Emacs Editing files The Emacs editor.
Text editors Why should I use an editor ? It is very important to able to use at least one text mode editor a text mode editor is so useful on remote machines.
Unix Editors. u Editors in Unix come in two general flavours: –modal editors have "modes" v generally input mode and command mode –input mode allows entry.
Tony Kombol.  Why text edit?  Many programs and features require configuration ▪ Configuration is kept in files ▪ Usually in the /etc directory  Changes.
Unix Session IV.
Text Editing February 2 nd, 2004 Class Meeting 3.
1 of 47 Chapter 4: The vi Editor – First Look Copyright ©2008 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved.
Chapter Three Text Editing1 System Programming Text Editing.
Unix Environment Input Output 2  List Content (ls) ◦ ls (list current directory) ◦ ls –all (include hidden files/folders)  Make directory (mkdir) ◦
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
Introduction to Unix (CA263) File Editing By Tariq Ibn Aziz.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Chapter Three The UNIX Editors.
Linux Class #03. File Access Permissions Types of users in Linux: Local User (u) Group User (g) Other User (o) Each User can have 3 types of permissions:
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
THE vi EDITOR. Introduction There are three editors available in almost all versions of Unix: ed, ex and vi. The ed program is the original editor that.
Text editing and more basic commands CS 2204 Class meeting 3 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session.
Agenda Using vi Editor Starting vi Session Command / Input Modes
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
Amir Afzal UNIX Unbounded, 5th Edition Copyright ©2008 Chapter 6: The vi Editor – Last Look 1 of 55 Copyright ©2008 by Pearson Education, Inc. Upper Saddle.
Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
BIF703 FTP (File Transfer Protocol) Utility vi editor Utility.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
CS:414 introduction to Unix and Linux
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vim.
Vi Introduction Tony Kombol.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Chapter 2 Basic vi Editor.
Linux Operations and Administration
CSCI The UNIX System Editing files
In the last class… The vi basics command, input and ex mode
The Linux Command Line Chapter 12
Presentation transcript:

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

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

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

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

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

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

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

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

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.

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

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!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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!

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

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

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

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

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?

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

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

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

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

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  ! #

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

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

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

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

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

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

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

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 )

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

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

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

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,

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

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

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