Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation.

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.
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.
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.
The UNIX development environment CS 400/600 – Data Structures.
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.
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.
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.
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.
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.
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.
1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
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.
1 Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
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.
Getting Started with Linux Linux System Administration Editors.
BIF703 FTP (File Transfer Protocol) Utility vi editor Utility.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 14 – UNIX vi text editor.
Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
CS:414 introduction to Unix and Linux
Vi editor Pronounced: `vee eye‘’.
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Nassau Community College
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vim.
Vi Introduction Tony Kombol.
Linux 104 Training Module File Editing.
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)
The Linux Command Line Chapter 12
Chapter 2 Basic vi Editor.
CSCI The UNIX System Editing files
In the last class… The vi basics command, input and ex mode
Presentation transcript:

Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation

What is vi ? vi is the most widely used full-screen text editor for UNIX and Linux system. vi is short for visual extension (of the line- oriented editor ex) developed by Bill Joy, co- founder of Sun Microsystems. The UNIX/Linux editor succession is ed → ex → vi The main alternate editor, EMACS, was developed at MIT.

User Profile When a user logs in, there is a profile that is used to initialize the terminal session: ~]$ more.bash_profile #.bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then. ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH unset USERNAME ~]$

Starting vi To invoke the vi editor, type vi If the file is new, you will get a nearly-blank screen. You are initially in command mode. By typing, i or a, you can start to enter text.

Opening vi Screen ~ newfile [New File] 0,0-1 All

Command and Input Mode Command Mode Input Mode a, A, i, I, o, O Enter text Edit text Nota bene: You always start in command mode

ex Commands in vi ex commands are always available for use in vi command mode if you first type " : " Examples :s/x/y/ will substitute an y for x. :., +1j will join the current line with the following line. Finish the command by pressing  just as you would in ex.

Entering Input Mode a Append after current cursor position. A Append after current line. i Insert before current cursor position. I Insert before current line. o Open line below current line. O Open line above current.

Working in Command Mode The command never appears on the screen (except for ex commands). This is new text enter using "d" ~ :s/"a"/"d"/ 2,1 All

Leaving Input Mode To get back to Command Mode, press the "Escape" key. When in doubt about which mode you are in, press "Escape." If you press "Escape" in Command Mode, vi will beep.

Exiting Input Mode Hello, world My name is Sy. ~ 2,14 All Enter "a" in Command Mode Press ESC in Input Mode

Exiting vi To write and/or quit your vi session: :w Writes the files :wq Writes and quits :x Same as :wq ZZ Same as :wq :q Quits without writing (if unmodified) :q! Quits without writing

vi tells you the Number of Lines #include int main(void) { printf("Hello, world\n"); return(0); } ~ "hello.c" 7L, 78C 6,2-9 All

Moving Around the Screen hjkl 0 Beginning of current line $ End of current line  Beginning of next line + Beginning of next line - Beginning of previous line

Hello there Today is Thursday. It is raining and it is humid. ~ 4,6 All $  jj

Other Move Commands w move to the next word or punctuation e move to the end of the next word of punctuation b move to the beginning of the previous word ) move to the beginning of the next sentence ( move to the beginning of the current sentence } move to the beginning of the next paragraph { move to the beginning of the current paragraph

vi Words and Paragraphs vi sentences end with ". ", " ? " or " ! " vi paragraphs begin after a blank line. Hello world again.This is a mysterious file. Help ~ w }b }w

Moving Around Faster ^f Writes the files ^d Move forward ½ screen ^b Move backward one full screen ^u Move backward ½ screen G Moving to the end of the file A number in front changes the command 3^f – move ahead 3 screens 99G -go to line 99

Modifying Text r char – replace the current character with char. R string - Overwrite text with this string. J – joins current and next line into one line. ~ - Switches upper and lower case.

Deleting Text x deletes a single character num x delete num characters dw deletes the rest of the current word num dw deletes num words from the current position d$ deletes the rest of the line d) deletes to the beginning of the next sentence dd deletes current line dnumd deletes num lines from the current line

Moving Text Lines last deleted are placed in a buffer. You can "put" it anywhere in a file. p – put it to the right or below the current position. P – put it to the left or above the current position.

Moving Text – An Example Line 1 Line 2 Line 3 Line 4 Line 3 Line 4 Line 1 Line 2 After d2djp

Searching For Text / string – search forward for string ? string – search backward for string

Copying and Moving Text To copy text, use yy (to yank a line) or yw (to yank a word) or y$ (to yank until the end of the line) or y) (to yank until the next sentence) followed by p or P. To move text, use dd,dw, d$ or d) followed by p or P.

Using ex Commands in vi All ex commands in vi are preceded by a colon: :wq :q!

Some Useful ex Commands :address s/oldpattern/newpattern/ - replace the old pattern in the text with the new pattern on these lines :address d – deletes these lines :g/opattern/s//npattern – globally searches for opattern and replaces it with npattern. (once per line) :g/opattern/s//npattern/g – globally searches for opattern and replaces it with npattern. (all occurences) :r file – reads in file :! cmd – perform UNIX shell command cmd.

Addresses in ex Commands Address in these commands can be: 1, 5 – lines 1 through 5., 30 – current line through line 30 30, $ - line 30 through the end., +5 – current line through 5 lines downs :-3, +1 – 3 lines above until 1 line down

Miscellany and Metacharacters ^l – refreshes screen Metacharacters ^ - beginning of line $ - end of line. – matches any single character * - matches preceding character any number of times [string] – matches any character in string [^string] – matches any character NOT in string.

Metacharacters – An Example /^xyz – search for xyz at beginning /line.$ - search for this at the end of the line /^$ - search for empty line s/X.*$/Hello – finds X followed by any character any number of times at end of line and replaces it with Hello. :1, $s/[0-9]/-/g :1,$s/[^a-za-Z]/0/g :s/United.*ica/USA/