Chapter 3 Mastering Editors

Slides:



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

A Guide to Unix Using Linux Fourth Edition
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
Linux+ Guide to Linux Certification, Second Edition
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.
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
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.
Introduction to Shell Script Programming
Guide To UNIX Using Linux Fourth Edition
Chapter 3: The UNIX Editors ASCII and vi 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.
Intro. To Unix commands For those who’ve never used Unix before Quick tutorial to let you move around your Unix Accounts No discussion of inner workings.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
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.
Lesson 2: Manipulating Text Courseware #: 3240
Chapter 5 Editing Text Files. Basic Concept A text editor works on a file buffer that is a memory copy of a disk file The disk file is not updated until.
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.
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.
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.
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.
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.
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.
October 24,  Creating and Opening Files  Save and Exit  Navigation  Shortcuts  Copying, Cutting and Pasting  Searching and Replacing  More.
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.
By Justin Higgins. What is a text editor? If you’ve ever used Microsoft word you know what a text editor is (albeit a bloated one). When you write a program.
CS:414 introduction to Unix and Linux
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
The Essence of UNIX and Linux
Guide To UNIX Using Linux Third Edition
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vi Introduction Tony Kombol.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
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
Day 5 Emacs Editor David A. Gaitros Department of Computer Science
The Linux Command Line Chapter 12
Presentation transcript:

Chapter 3 Mastering Editors Guide To UNIX Using Linux Fourth Edition Chapter 3 (40 slides) CTEC 110

Objectives Explain the basics of UNIX/Linux files, including ASCII, binary, and executable files Understand the types of editors Create and edit files using the vi editor Create and edit files using the Emacs editor Chapter 3 (40 slides) CTEC 110

Understanding UNIX/Linux Files Almost everything you create in UNIX/Linux is stored in a file Bit: binary digit In one of two states: 0 or 1 Machine language: exclusive use of 0s and 1s as a way to communicate with computer Used by earliest programmers Chapter 3 (40 slides) CTEC 110

ASCII Text Files Byte (binary term): string of eight bits A byte can be configured into fixed patterns of bits ASCII: American Standard Code for Information Interchange 256 different characters Unicode Supports up to 65,536 characters Text files: contain nothing but printable characters Binary files: contain nonprintable characters Example: machine instructions Chapter 3 (40 slides) CTEC 110

Look at Page 113 Chapter 3 (40 slides) CTEC 110

Binary Files Some things cannot be represented with ASCII codes Binary files are used instead Example: graphic files include bit patterns Bitmap: made of rows and columns of dots Chapter 3 (40 slides) CTEC 110

Executable Program Files Text files containing program code are compiled into machine-readable language Scripts are files containing commands Typically interpreted, not compiled Executables: compiled and interpreted files that can be run Chapter 3 (40 slides) CTEC 110

Using Editors Editor: program for creating and modifying files containing source code, text, data, memos, etc. Text editor: a simplified word-processing program Used to create and edit documents Two text editors normally included in UNIX/Linux are screen editors vi Emacs Line editor: works with one line (or group of lines) at a time Chapter 3 (40 slides) CTEC 110

Using the vi Editor vi is a visual editor vi is also a modal editor Supports three modes Insert mode Accessed by typing “i” Command mode Accessed by typing Esc Extended (ex) command set mode Accessed by typing “:” in command mode Download the vi editor document on Canvas for reference Chapter 3 (40 slides) CTEC 110

Creating a New File in the vi Editor Chapter 3 (40 slides) CTEC 110

Inserting Text When you start vi, you are in command mode To insert text in your file, switch to insert mode Use i (insert) command To return to command mode, press Esc Chapter 3 (40 slides) CTEC 110

Repeating a Change Use a period (.) to repeat the most recent change you made Repeat command Works in command mode Chapter 3 (40 slides) CTEC 110

Moving the Cursor To move cursor use arrow keys (command/insert mode) or (in command mode) use: Chapter 3 (40 slides) CTEC 110

Deleting Text Deletion commands available (command mode) dd is used for “cutting” text Use “yank” (yy) command for “copying” text Chapter 3 (40 slides) CTEC 110

Undoing a Command Type u to use the undo command Example: If you delete a few lines from a file by mistake, type u to restore the text Chapter 3 (40 slides) CTEC 110

Searching for a Pattern To search forward for a pattern of characters: Type a forward slash (/) Type the pattern you are seeking Press Enter Examples: /\<top, /s..n, /pas[st], /!$ Chapter 3 (40 slides) CTEC 110

Searching and Replacing Screen-oriented commands execute at the location of the cursor Line-oriented commands require you to specify an exact location (an address) for the operation Preceded by a colon (:) Operate in ex mode Used for commands that perform more than one action Example: searching and replacing :1,$s/insure/ensure/g Chapter 3 (40 slides) CTEC 110

Saving a File and Exiting vi To save file without exiting, use :w To save and exit, use :wq, :x, ZZ (Do this in command mode) Chapter 3 (40 slides) CTEC 110

Adding Text from Another File To copy entire contents of one file into another file: Use vi to edit the file you would like to copy into Use the command :r filename filename is the name of the file that contains the information you want to copy Chapter 3 (40 slides) CTEC 110

Leaving vi Temporarily To launch a shell or execute other commands from within vi, use :! Example: :!cal To run several command-line commands in a different shell without closing vi session Use Ctrl+z to display the command line Type fg to go back to vi Chapter 3 (40 slides) CTEC 110

Leaving vi Temporarily (continued) Chapter 3 (40 slides) CTEC 110

Changing Your Display While Editing To turn on line numbering :set number To delete lines 4 through 6 (ex mode) :4,6d Chapter 3 (40 slides) CTEC 110

Copying or Cutting and Pasting The command yy copies (yanks) a specified number of lines To cut the lines, use dd Lines are placed in clipboard Use p to paste the clipboard contents Chapter 3 (40 slides) CTEC 110

Printing Text Files To print a file, use the lpr (line print) shell command Example: :!lpr -P lp2 accounts Chapter 3 (40 slides) CTEC 110

Canceling an Editing Session Canceling an editing session will discard all the changes you have made Or, save changes you made since last using :w Saves file without exiting vi Chapter 3 (40 slides) CTEC 110

Getting Help in vi Use the help command Other alternatives: :help man vi From the command line :!man vi From vi (command mode) Chapter 3 (40 slides) CTEC 110

Using the Emacs Editor Emacs is a popular UNIX/Linux text editor Not modal More complex than vi More consistent than vi Sophisticated macro language Macro: set of commands that automates a complex task Uses: read mail, edit contents of directories, etc. Powerful command syntax Extensible Chapter 3 (40 slides) CTEC 110

Using the Emacs Editor (continued) Chapter 3 (40 slides) CTEC 110

Using the Emacs Editor (continued) Chapter 3 (40 slides) CTEC 110

Creating a New File in Emacs Chapter 3 (40 slides) CTEC 110

Navigating in Emacs To create a new file: emacs filename To navigate in the file, use the cursor movement keys or Ctrl/Alt key combinations Example: Alt+f To save your work: Use File menu Use the save icon Press Ctrl+x, Ctrl+s To exit: use menu, icon, or Ctrl+x, Ctrl+c Chapter 3 (40 slides) CTEC 110

Deleting Information Del or Backspace keys delete individual characters Ctrl+k deletes to the end of a line To undo a deletion, use Ctrl+x, u Repeatedly undoes each deletion Chapter 3 (40 slides) CTEC 110

Copying, Cutting, and Pasting Text To Copy-Paste or Cut-Paste: Mark the text Position cursor at the beginning, and Ctrl+Spacebar Navigate to the end of the text you want to include: Alt+w copies the text Ctrl+w cuts the text To paste, move to where you want to place the text Ctrl+y (the yank command) Chapter 3 (40 slides) CTEC 110

Searching in Emacs One way to search in Emacs is to: Press Ctrl+s Entering string to find (on status line) Pressing Ctrl+s repeatedly to find each occurrence Use Ctrl+r to search backward Other alternatives: Use search forward for a string icon On the menu: Edit  Search  Search Chapter 3 (40 slides) CTEC 110

Reformatting a File Alt+q turns on word wrap feature Lines automatically wrap around from one line to the next Chapter 3 (40 slides) CTEC 110

Getting Help in Emacs Emacs comes with extensive documentation and a tutorial Tutorial is useful for getting up to speed quickly Click Help menu  Emacs Tutorial Or (in most versions), type Ctrl+h and then type t To view general Emacs documentation: Ctrl+h (press one or two times) Or, man emacs at command line Chapter 3 (40 slides) CTEC 110

Summary Bytes: computer characters (a series of bits) stored using numeric codes The vi editor is popular among UNIX/Linux users Three modes: insert (i), command (Esc), and ex (Esc :) With vi, you edit a copy of the file placed in memory File is not altered until you save it on disk Emacs is a popular alternative to vi Supports powerful command syntax and is extensible Insert text simply by typing Sophisticated macro language Chapter 3 (40 slides) CTEC 110

Command Summary Chapter 3 (40 slides) CTEC 110

Command Summary (continued) Chapter 3 (40 slides) CTEC 110

Chapter 3 Unix Exercises Work through Hands-on Projects at end of chapter 3 Canvas: Review Questions (Do not do questions 22,23,24 and 25) Read chapter 4 before next class session Quiz 3 Unix… Chapter 3 (40 slides) CTEC 110