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.

Slides:



Advertisements
Similar presentations
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)
Advertisements

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.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
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.
VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006.
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.
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:
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Chapter 3 Mastering Editors
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
The UNIX development environment CS 400/600 – Data Structures.
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.
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.
Introduction to Unix – CS 21 Lecture 7. Lecture Overview Regular expressions revisited emacs versus vi Basic emacs and vi usage.
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.
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.
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.
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
Purdue Linux Users Group Presents Linux 201: Session 1 Everything you ever wanted to do in VIM Thor Smith.
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.
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
The Emacs Editor Read: Forouzan, Appendix C
CSCI The UNIX System Editing files
In the last class… The vi basics command, input and ex mode
Presentation transcript:

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 and run a shell scripts

Suggested Reading Chapter 3 Class Handouts Or if your really need to know about vi try “Learning the vi Editor, 6th Edition” from Oreilly.Com

What is vi ? The visual editor on the Unix. Before vi the primary editor used on Unix was the line editor User was able to see/edit only one line of the text at a time The vi editor is not a text formatter (like MS Word, Word Perfect, etc.) you cannot set margins center headings Etc…

Vi History Although other stories exist, the true one tells that vi was originally written by Bill Joy in Who is Bill Joy you ask? He co-founded Sun Microsystems in 1982 and served as chief scientist until Joy's prowess as a computer programmer is legendary, with an oft- told anecdote that he wrote the vi editor in a weekend. Joy denies this assertion.vi

Some Vi Ports All Unix OS’s MS-Dos Windows 3.x Windows 9x/2k/NT/XP OS/2 Macintosh Atari Amiga OpenVMS/Alpha OpenVMS/VAX

Characteristics of vi The vi editor is: a very powerful but at the same time it is cryptic It is hard to learn, specially for windows users The best way to learn vi commands is to use them So Practice…

Vim equals Vi The current iteration of vi for Linux is called vim Vi Improved

Starting vi Type vi at the shell prompt After pressing enter the command prompt disappears and you see tilde(~) characters on all the lines These tilde characters indicate that the line is blank

Vi modes There are two modes in vi Command mode Input mode When you start vi by default it is in command mode You enter the input mode through various commands You exit the input mode by pressing the Esc key to get back to the command mode

How to exit from vi First go to command mode press Esc There is no harm in pressing Esc even if you are in command mode. Your terminal will just beep and/or or flash if you press Esc in command mode There are different ways to exit when you are in the command mode

How to exit from vi (comand mode) :q is to exit, if you have not made any changes to the file :q! is the forced quit, it will discard the changes and quit :wq is for save and Exit :x is same as above command ZZ is for save and Exit (Note this command is uppercase) The ! Character forces over writes, etc. :wq!

You can move around only when you are in the command mode Arrow keys usually works(but may not) The standard keys for moving cursor are: h - for left l - for right j - for down k - for up Moving Around

w - to move one word forward b - to move one word backward $ - takes you to the end of line takes the cursor the the beginning of next line Moving Around

- - (minus) moves the cursor to the first character in the current line H - takes the cursor to the beginning of the current screen(Home position) L - moves to the Lower last line M - moves to the middle line on the current screen Moving Around

f - (find) is used to move cursor to a particular character on the current line For example, fa moves the cursor from the current position to next occurrence of ‘a’ F - finds in the reverse direction Moving Around

) - moves cursor to the next sentence } - move the cursor to the beginning of next paragraph ( - moves the cursor backward to the beginning of the current sentence { - moves the cursor backward to the beginning of the current paragraph % - moves the cursor to the matching parentheses Moving Around

Control-d scrolls the screen down (half screen) Control-u scrolls the screen up (half screen) Control-f scrolls the screen forward (full screen) Control-b scrolls the screen backward (full screen). Moving Around

To enter the text in vi you should first switch to input mode To switch to input mode there are several different commands a - Append mode places the insertion point after the current character i - Insert mode places the insertion point before the current character Entering text

I - places the insertion point at the beginning of current line o - is for open mode and places the insertion point after the current line O - places the insertion point before the current line R - starts the replace(overwrite) mode Entering text

Editing text x - deletes the current character d - is the delete command but pressing only d will not delete anything you need to press a second key dw - deletes to end of word dd - deletes the current line d0 - deletes to beginning of line There are many more keys to be used with delete command

The change command c - this command deletes the text specified and changes the vi to input mode. Once finished typing you should press to go back to command mode cw - Change to end of word cc - Change the current line There are many more options

Structure of vi command The vi commands can be used followed by a number such as n For example dd deletes a line 5dd will delete five lines. This applies to almost all vi commands This how you can accidentally insert a number of characters into your document

Undo and repeat command u - undo the changes made by editing commands. (dot or period) repeats the last edit command

Copy, cut and paste in vi yy - (yank) copy current line to buffer nyy - Where n is number of lines p - Paste the yanked lines from buffer to the line below P - Paste the yanked lines from buffer to the line above (the paste commands will also work after the dd or ndd command)

Stupid vi Tricks Indent four lines: 4>> Will delete the character under the cursor, and put it afterwards. In other words, it swaps the location of two characters: xp Similar to xp, but swapping lines: ddp Remove all lines that start with # :g/^#/d Remove all empty lines, assumes no spaces or tabs: :g/^$/d

Some Practice Using a command line utility called wget let’s pull down a copy of the Gettysburg Address wget –U “ “ Now we will run a few commands against the text (note: I placed several blank lines and lines starting with the #)

Gettysburg.txt Run the following commands: vi gettysburg.txt :g/^#/d :g/^$/d

Gettysburg.txt Invoke vi’s edit mode by pressing the Esc key, then a colon ( : ), and enter: 1,$s/oldstring/newstring/g This will change oldstring into newstring wherever it occurs throughout the entire text. The 1 (the number one) in the above command means "start the search on the first line". The $ means "end the search on the last line". The g at the end executes the change globally on each line. If you omit the g, the search will stop after finding the first occurrence of oldstring.

Creating a shell script using vi Create a directory call class Change into class vi myscript.sh inside the file enter following commands clear echo "===========" echo "Hello World" echo "===========" sleep 3 clear echo Host is $HOSTNAME echo User is $USER

Creating a shell script using vi Save the file Change the permissions on myscript.sh chmod 700 myscript.sh Now execute myscript.sh myscript.sh Did the script run? Why not? Hint, think about absolute vs relative path Type echo $PATH to see your PATH variable Try this./myscript.sh The./ mean right here in this directory!

Vi – Emacs Holy Wars First salvo – Use vi? How hard could that be? Here are the steps for using vi. Procure fish, any kind, length > 12 inches Freeze it overnight Sit in front of PC, run vi Holding fish by the tail, smash it repeatedly against your forehead until you decide to give EMACS a try because the fish scales are flying around and your head is starting to ache.

Vi References The Vi Lovers Home Page The Editor War

For the vi Lover

World War VI

World War VI Word War vi is your basic side-scrolling shoot 'em up '80s style arcade game. You pilot your "vi“-per craft through core memory, rescuing lost.swp files, avoiding OS defenses, and wiping out those memory hogging emacs processes. When all the lost.swp files are rescued, head for the socket which will take you to the next node in the cluster.

Next Class Unix File Processing Suggested reading: Chapter 4