Chapter 3: The UNIX Editors ASCII and vi Editors.

Slides:



Advertisements
Similar presentations
A Guide to Unix Using Linux Fourth Edition
Advertisements

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.
Representing Information as Bit Patterns
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.
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 Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Topics Introduction Hardware and Software How Computers Store Data
Chapter 3 Mastering Editors
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
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:
Word Lesson 2 Basic Editing
Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation.
Editing, vi and Configuration Files Introduction to Linux June 16, 2009 Papeete, French Polynesia Hervey Allen.
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.
Editors And Debugging Systems Other System Software Text Editors Interactive Debugging Systems UNIT 5 S.Sharmili Priyadarsini.
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.
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.
Getting Started with Linux Linux System Administration Editors.
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:
PacNOG 6: Nadi, Fiji Editing, vi & Configuration Files Hervey Allen Network Startup Resource Center.
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
Editing, vi and Configuration Files Unix/IP Preparation Course May 29, 2011 Dar es Salaam, Tanzania
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
Editing, vi and Configuration Files Introduction to Unix May 25, 2008 Rabat, Morocco Hervey Allen.
Editing, vi and Configuration Files Unix/IP Preparation Course July 19, 2009 Eugene, Oregon, USA
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.
Editing, vi and Configuration Files Unix/Linux Preparation Course June 27, 2010 Pago Pago, American Samoa
1 Problem Solving using Computers “Data....Representation, and Storage.
M204 - Data Representation
Getting Started with Linux Linux System Administration Editors.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 14 – UNIX vi text editor.
1 Word Lesson 2 Basic Editing Microsoft Office 2010 Introductory Pasewark & Pasewark.
Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
CS:414 introduction to Unix and Linux
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
Unit 2.6 Data Representation Lesson 2 ‒ Characters
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Editing, vi and Configuration Files
Vi Editor.
Unix Fundamentals - Part iii vi Editor
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
Linux System Administration Editors
Data Encoding Characters.
Representing Characters
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Chapter 2 Basic vi Editor.
CSCI The UNIX System Editing files
In the last class… The vi basics command, input and ex mode
ASCII and Unicode.
Presentation transcript:

Chapter 3: The UNIX Editors ASCII and vi Editors

The vi Editor Objectives After studying this lesson, you should be able to: –Describe an ASCII text file –Explain why operating system editors use ASCII files –Create and edit simple documents using the vi editor

Program and Data Executable program files contain pure binary or machine language that the computer can immediately use or execute Data contains information. May be text, numeric, images, audio, video, … Today, we limits our attention only to text and numeric data.

How files are stored? Both programs and data in UNIX are stored in files All information stored in files is in the form of binary digits A binary digit, called bit for short, consists of two numbers, 0 and 1 The exclusive use of 0s (which mean “off”) and 1s (which mean “on”) as a way to communicate with the computer is known as machine language

ASCII Text Files translating binary numbers into plain EnglishTo make information stored in files accessible, computer designers established a standard method for translating binary numbers into plain English This standard used a string of eight binary numbers, called a byte, which is an acronym for “binary term” Each byte, or code, has been standardized into a set of bit patterns known as ASCII codes ASCII stands for the American Standard Code for Information Interchange

ASCII Text Files Standard encoding scheme used to represent characters in binary format on computers Was 7-bit encoding, so 128 characters can be represented. (Now is 8-bit encoding, including Arabic, French, German, etc.) 0 to 31 (& 127) are "control characters" (cannot print) –Ctrl-A or ^A is 1, ^B is 2, etc. –Used for screen formatting & data communication 32 to 126 are printable (95 printable symbols)

ASCII Characters

Example THE QUICK GREY FOX JUMPED OVER THE LAZY COWS. od -xc fox.txt

Is ASCII code enough? Is the ASCII code enough? –No. Chinese or Japanese language text (thousands of symbols) Unicode –A 16-bit coding scheme (allows for how many characters?) –Developed by consortium of major American computer manufacturers, primarily to overcome the chaos of different coded character sets in use when creating multilingual programs and internationalizing software. ISO 32-bit code –Developed by International Organization for Standardization –Allows for (how many ?) characters

Using Operating System Editors Operating system editors let you create and edit simple ASCII files UNIX includes three editors: – vi – Emacs – pico We only cover vi Editor:

vi Editor vi is not user-friendly! You have to remember all of the commands, in addition to which mode the editor is in. However, vi is very powerful and fast once you have mastered it. The vi editor remains the choice of most UNIX users

Using the vi Editor It is also a modal editor; that is, it works in two modes: –Insert mode lets you enter text –Command mode (default node) lets you enter commands to perform editing tasks, such as moving through the file and deleting text

Starting and Exiting vi Starting: –vi begin editing unnamed file –vi file1.txt begin editing file1.txt Exiting (used only in command mode): –:q quit (assumes no changes made) –:q! quit, discard any changes that were made –:wq write the file, then quit –ZZ write the file, then quit –:w newname write the file to 'newname'

Insert mode i (insert text before the cursor) a (insert text after the cursor) A (insert text at end of line) cw (change word)

Navigating Although the and and arrow keys work on some systems, I would strongly discourage their use. The following commands are guaranteed to work properly on all systems. vi equivalent –Page Up^F –Page Down^B –Left Arrowh –Right Arrowl –Up Arrowk –Down Arrowj –Begin_ –End$

Deleting delete current line dd delete from cursor to end of line D delete character under cursor x delete character before cursor (backspace) X Note that many of the above commands can be preceded by a number, for example: –9x delete 9 characters –3dd delete 3 lines

Setting Line Number Show line numbers :set nu Turn off line numbers :set nonu display current line number/file name ^g go to line number :1 (go to line 1) G (go to last line in file)

Copying copy current line to "clipboard“yy paste contents of "clipboard" below current linep paste contents of "clipboard" above current lineP copy current line, and next 4 lines to "clipboard“5yy

Searching for a Pattern You can search forward for a pattern of characters by typing a forward slash (/), typing the pattern you are seeking, and then pressing Enter #include using std::cout; int main() { cout << "Hello, World, in C++." << endl; return 0; } ~ /World 6,19 All

Searching set case insensitive search:set ic set case sensitive search:set noic search forward (down) for "hello“/hello search backward (up) for "hello“?hello search again, (same direction as original) n search again, (opposite direction as original)N search for "hello" at start of a line/^hello search for "hello" at end of a line/hello$ search for "hello" or "Hello“/[hH]ello search for "int" as a word (i.e. not print or sprint)/\ search for "eat" but not "beat" or "neat“/\[^bn]eat

Replacing replace "dog" with "cat" (first occurrence of dog) on the current line:s/dog/cat replace "dog" with "cat" on lines 1 -> 3 (first occurrence of dog on each line) of the file:1,3s/dog/cat replace "dog" with "cat" on lines 1 -> 3 of the file, every occurrence:1,3s/dog/cat/g replace "dog" with "cat" (every occurrence) for the entire file:1,$s/dog/cat/g replace "dog" with "cat" (every occurrence) for the entire file (alternative method):%s/dog/cat/g replace "dog" with "cat" (every occurrence) for the entire file but confirm each replacement:%s/dog/cat/gc

Latex A script language for editing documents Eample: cp ~yzhu/public_html/cs251/tutorial.tex. latex tutorial dvips –o tutorial.ps tutorial.dvi

Chapter Summary Bytes are “computer characters” referred to as “codes” These codes have been standardized and are known as ASCII codes The vi editor remains the choice of most UNIX users

Chapter Summary Continued The vi editor is a modal editor, because it works in two modes: insert mode and command mode In the vi editor’s insert mode, characters you type are inserted in the file You have to remember all of the commands to be more efficient.