Introduction to Unix – CS 21 Lecture 7. Lecture Overview Regular expressions revisited emacs versus vi Basic emacs and vi usage.

Slides:



Advertisements
Similar presentations
CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
Advertisements

 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
A Guide to Unix Using Linux Fourth Edition
Introduction to the gedit editor. gedit: the Gnome editor Gnome: Gnome is a freely available (i.e., no cost) desktop environment for the UNIX system The.
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
Create your first presentation
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
Linux+ Guide to Linux Certification, Second Edition
Chapter 5 Editing Text Files
CS 497C – Introduction to UNIX Lecture 10: The vi/vim Editor Chin-Chih Chang
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
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
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.
Using Linux Text Editors. Use Non-Graphical Linux Text Editors Graphical Text Editor.
1 Unix Text Editors Creating files on the Unix system.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Key Applications Module Lesson 19 — PowerPoint Essentials
Chapter 3 Mastering Editors
CENT 305 Information Systems Security Linux Introduction.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
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.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
1 © 2014 John Urrutia. All rights reserved. Chapter 7 The “ Emacs “ Editor.
VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.
Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.
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.
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.
Chapter 9 Using Text Editors. vi Editor visual Editor, ASCII text editor, no formatting capabilities almost as powerful as MS Word, has 26 clipboards.
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:
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.
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.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop III - Part A Shell Commands Professional Training.
1 Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
1 Day 4 Introduction to VI. 2 Vi – Visual Editor Used to edit text files on a UNIX system –Now also available for Windows/Mac etc. Very powerful for editing.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 14 – UNIX vi text editor.
CS:414 introduction to Unix and Linux
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Vi Editor.
Vim.
Vi Introduction Tony Kombol.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
Technical University of Kosice
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
You do want to create and edit programs?
Emacs CSC 135.
Linux Operations and Administration
The Emacs Editor Read: Forouzan, Appendix C
CSCI The UNIX System Editing files
Day 5 Emacs Editor David A. Gaitros Department of Computer Science
Presentation transcript:

Introduction to Unix – CS 21 Lecture 7

Lecture Overview Regular expressions revisited emacs versus vi Basic emacs and vi usage

Back To Regular Expressions You will see regular expressions pop up over and over again Important to understand how they work Always important to keep in mind that syntax can change, but the meaning will be the same grep syntax is just as good as any

Guidelines On Constructing Regular Expressions Break it up piece by piece If asked for a regular expression that finds two things, try to come up with regular expressions that find each individually Combine multiple R.E.’s with “or” (|) If I want all lines with “hello” in them, and you have two expressions that find different instances, one expression with an or will get all of them

Example Find all instances of dog but not dogs “dog[^s]” finds at the beginning or middle “dog$” finds at the end “(dog[^s])|(dog$)” finds all instances

More Guidelines Think about all cases Beginning, middle, and end of the line Think about what else is important on the line If I ask for lines that start with “a” and end with “e”, also think about what could go in the middle

In-Class Exercise Come up with regular expressions for the following: All lines that have a phone number in it or All lines that contain the word “lean” but not the word “cleans” All lines that start with “And” and don’t end with “of”

In-Class Exercise Discussion “[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]” “[0-9]{3}-[0-9]{4}” ([^c]lean[^s])|(^lean)|(lean$) (^And.*[^f]$)|(^And.*[^o]f$)

Actually Creating And Modifying Files Good News Multiple editors in Unix exist that allow you to create and modify text files Bad News You will have to get used to and memorize a whole bunch of commands in order to use them well

Editors In Unix vi The “visual” editor vim = “vi improved” emacs “editor macros” “A way of life”, not just an editor

“Holy War” The choice between emacs and vi divides a large part of the Unix community No real answer as to which is better, just which you prefer to use Most likely what you started out with People, will argue endlessly over why one is better than the other

Why Would You Use vi? Quick and small Ready to use immediately and it doesn’t consume too many resources Simple No hassles, but quite a few features that are helpful Always there vi is virtually guaranteed to be on every Unix system, emacs isn’t

Why Would You Use emacs? Large Specialized Modes exist that help you out for many different types of files Powerful Allows you to integrate a lot of work from the shell without leaving the editor Fast (relatively)

Which One Should You Choose? Whichever one you feel comfortable with Both will be introduced here and you will see the differences Try them both and figure out which suits you best

Unix Editors Versus Windows Editors vi knows nothing about the mouse vi doesn’t have any menu options either If emacs is run inside a terminal window, then the mouse is useless as well All conveniences can be done through keystrokes, not through mouse operations

Modes Of vi vi is a modal program The same key means different things depending on what mode you are in vi always begins in “command mode” You won’t be able to type in any text until you change modes “Esc” will get you into command mode

vi Basics Starting vi Usage: vi [FILE] Quitting vi Esc, :q

emacs Essentials Always able to enter text Commands are given by combinations of control keys Cntrl Meta Usually “Alt” Sometimes “Esc” (Solaris, etc.)

emacs Basics Starting emacs Usage: emacs [FILE] Quitting emacs Cntrl-x, Cntrl-c Book specifices Cntl-x, Cntl-h, Ctnrl-h, Cntrl-h but that doesn’t work on our system

Opening A File In vi In command mode, hit :e FILENAME This will abandon you previous file

Opening A File In emacs Cntrl-x, Cntrl-f This will switch you to a new file, but will not abandon your previous file

Moving Around In vi With vim, the arrow keys, page up, and page down work just fine On some systems, you will need to use special keys in command mode Cntrl-f = page down Cntrl-b = page up h, j, k, l = work like the arrow keys Left, down, up, right respectively

Specific Movement Commands In vi w = move forward one word b = move backward one word 0 = move to the beginning of a line $ = move to the end of the line Cntrl-u = move up half a page Cntrl-b = move down half a page

Moving Around In Emacs Arrow keys and page up, page down work fine Special keys exist just in case Cntrl-f = one character forward Cntrl-b = one character backward Cntrl-v = Page Down Meta-v = Page up

Special Movement Commands In emacs Meta-f = move forward one word Meta-b = move backward one word Cntrl-a = move to the beginning of the line Cntrl-e = move to the end of the line Meta-a = move to the beginning of a sentence Meta-e = move to the end of a sentence

Simple Searching In vi In command mode, type “/” followed by the word you are looking for To go to the next occurrence, in command mode type “n” Search forwards “N” will go to previous occurrences in the file Search backwards

Simple Searching In emacs Cntrl-s Type in the word you are searching for Searches the file forwards Cntrl-S again will move you to the next occurance Cntrl-r Works exactly the same way, but searches backwards through the file

Inserting In vi First, make get into “insertion mode” i = transfer into insertion mode o = transfer into insertion mode in a new line below the current line O = transfer into insertion mode in a new line above the current line Now type as normal

Inserting In emacs Just type as normal I see this as the biggest advantage emacs has over vi No special command is needed to start inserting text Combined with the menus, emacs is a little easier for beginners to handle

Deleting In vi x = delete one character dw = delete one word dd = delete one line d10 = delete 10 more lines (11 actually)

Deleting In emacs Cntrl-d = delete one character Meta-d = delete next word Cntrl-k = delete one line

Cut And Pasting In vi Whatever was just deleted is available to be pasted Word, character, or block of lines In command mode, “P” will paste most recently cut object

Cut And Pasting In emacs As long as you are deleting lines with Cntrl-k, those lines can be pasted somewhere else Cntrl-y will paste most recently cut lines

Saving Changes In vi In command mode, hit “:w” If you want to quit without saving changes, you need to the command “:q!”

Saving Changes In emacs Cntrl-x, Cntrl-s If you want to exit without saving changes, Cntrl-x, Cntrl-c as normal and then you will be prompted on if you really want to do that

Emacs Backup Files Emacs will automatically backup the last version of a file whenever you save new changes Example~ Whenever a problem occurs, another file gets created #Example#

Next Time We go into a lot more depth with emacs and vi A lot of tricks that come in handy will be presented