Chapter 5 Editing Text Files

Slides:



Advertisements
Similar presentations
Course Outline: System Requirements What is Vi Editor Conventions
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.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor Chin-Chih Chang
Vi Editor TA for ITIS3100: Xu Fei
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.
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.
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.
1 © 2014 John Urrutia. All rights reserved. Chapter 7 The “ Emacs “ Editor.
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.
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.
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.
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.
Week 8: Linux / ubuntu Dr. I. H. Shah. / CSCS 301 Fall 2009.
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.
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
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
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
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
Technical University of Kosice
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:

Chapter 5 Editing Text Files Mr. Mohammad Smirat

Introduction The editors that we consider here are all full screen display. The one we are going to explain here is the VI editor. The other editors are PICO and EMACS.

The VI editor The UNIX VI editor has almost all the features of a word processor and tremendous flexibility in creating text files. VI is more complex than pico editor, but it gives the ability to work on much larger files. The vi editor is a standard part of UNIX, others like emacs you have to buy it separately.

The VI editor The VI editor can be invoked from the shell with an optional filenames list as argument. $vi filename $vi file1 file2 // vi will edit them one by one $vi // you have to name a file // before you write the text buffer It will start with the first line of the file as current line. $vi +30 filename will start the editor with the line 30 in the file filename is the current line.

The VI editor $vi +/string filename will make the line of the first occurrence of the string in the file filename is the current line. The VI editor fills the screen with the text file, leaving only one line at the bottom for special info, if the file less than a page it fills the screen with empty line begin with tilde ~.

Buffers The buffer is a temporary storage facility for the text that you are editing. It is very useful and important in VI (for Visual). The main buffer, sometime referred to as editing buffer, or the work buffer, is the main repository for the body of the text that you are trying to create or modify from some previous permanently archived file on disc. The general purpose buffer is where your most recent “cut copied text” is retained.

The VI three Modes Command mode, when vi it starts, it is in command mode, lot of commands you can use here such as when pressing i for input it will move you to input mode just before the current cursor location, with upper case I vi will enter input mode at the beginning of the current line. Input mode enter the text you want, every thing you enter goes to the file, backspace key lets you back up, deleting chars as you go, until the end of the line. Last line mode, you invoke this by entering : colon. The cursor will jump to the last line of the screen and vi will wait for your command :r file2 will read file2 into the current buffer after the current line.

The VI three Modes

Switching to Insert Mode a append text after the char the cursor is on. A append text after the last char of current line. c begin a change operation C change from cursor to end of line. i insert before the char where the cursor is on. I insert at the beginning of current line. o open a blank line below the current line. O open a blank line above the current line. R begin overwriting text. s substitutes single character. S substitutes whole lines.

Important Command For the Command Mode When you want to change from insert mode to command mode, press the ESC key. d deletes words, lines, etc. u undoes the last edit. P pastes -insert- the yanked or deleted lines before the current line. p paste the yanked or deleted lines after the current line. ZZ quit vi, saving the file only if changes were made since last save.

Examples of Command Syntax of VI editor 5dw delete five word, starting at the current cursor position. If the current line ends it will continue with the next line. Words in vi are seperated with spases, taps, “enter”, or any other special characters like comma, point, /, :, …etc. 7dd deletes 7 lines, starting at the current line. c2b changes back two words starting from the preceding character for the current cursor position. If the current it reached the beginning of the line it will continue with the previous line. 1G puts the cursor on the first line of the file. 10yy Yanks (copies) the next 10 lines starting with current line into temporary buffer.

Cursor Movement and Editing Commands 1G moves the cursor to the first line. G move the cursor to the last line. 0 (zero) move the cursor to the first char of the current line. ctl-g orG report the position of cursor in terms of line # and col #. $ moves the cursor to last char of the line. w moves the cursor forward one word. b moves the cursor backward one word. x delete the char at the cursor position. dd delete the line at the current cursor pos. u undoes the most recent change. r replace the char at the current cursor location with what is typed next.

Yank and Put (copy and paste) and Substitute (search and replace). In general you use the yank and put in sequence and move the cursor only between yanking and putting. Substitute command is executed from the last line mode where you preface the command with the : char and ends the command by pressing ENTER.

Yank and Put (Some Examples) y2w yanks two words, starting at the current cursor position, going right. 4yb yanks 4 words, starting at the character previous to the current position going to the left. yy or y yanks the current line. P put the yanked text before the current cursor position. p put the yanked text after the current line 5p put the yanked text in the buffer five times after the current cursor position.

The Last Line Mode :5,25w file3 write line 5 through 25 into file3. :w file4 write the current buffer into file4, if exists will ask you to confirm. :!ls temporary suspend vi, execute the shell command, when completed vi returned. :r filename reads and insert the contents of the file filename after the current line. :q! Quits vi without saving :wq save the buffer and quit. :w! filename overwrite file name with current text. :7,15d delete lines 7 through 15 in the buffer.

Substitute :[range]s/old-string/new-string[/option] where : is the colon prefix. Range is a valid specification of lines. S is the syntax for substitute. Old-string text you want to replace. New-string is the new text. /option is a modifier usually g for global

Substitute (Some Examples) :s/john/jane/ substitute the word jane for the word john the current line only. :s/john/jane/g substitute the word jane for every word john on the current line. :1,10s/john/jane/g substitute the word jane for the word john on line 1-10. :1,$s/john/jane/g substitute the word jane for the word john for every word in the entire document.

Setting the VI Environment you can use any of several environment options to customize the behavior of the vi editor. These include specifying maximum line length and automatically wrapping the cursor to the next line. You can use the options using the :set command (in the last line mode). The following are some of the important environment option you can set. autoindent or ai align the new line with the beginning of the previous one.

Setting the VI Environment (cont…) ignorcase or ic ignore the case of a letter during the search process. number nu display line number when a file being edited. showmode (not shm) display the current vi mode in the bottom right corner of the screen. wrapmargin wm sets the wrap margin in terms of the number of chars from the end of the line. :set wm=6 showmode nu ic

Examples :set showmode vi will display an on-screen indicator when you are in input mode. :set all will display all options :set noshowmode The option you set with the :set are only active for the current editing session.