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:

Slides:



Advertisements
Similar presentations
Course Outline: System Requirements What is Vi Editor Conventions
Advertisements

In the last class… The vi basics command, input and ex mode Input mode – entering and replacing text Saving text and quitting – the ex mode.
 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
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.
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.
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
Basic Text Processing, Redirection and Pipes. 222 Lecture Overview  Basic text processing commands head, tail, wc  Redirection and pipes  Getting to.
Chapter 3: The UNIX Editors ASCII and vi Editors.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
The UNIX development environment CS 400/600 – Data Structures.
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.
(Stream Editor) By: Ross Mills.  Sed is an acronym for stream editor  Instead of altering the original file, sed is used to scan the input file line.
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.
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.
1May 16, 2005 Week 2 Lab Agenda Command Line FTP Commands Review More UNIX commands to learn File name expansion - * Introduction of vi.
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.
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.
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
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.
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
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Chapter 2 Basic vi Editor.
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:

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: are case-sensitive are not shown on the screen when you type them do not require an [Enter] after the command.

O PEN A F ILE vi is working on a copy of your file in the buffer: your edits will not affect your original file until you save the buffer. $ vi [ filename ] If the filename is omitted, vi will open an unnamed buffer. A filename must be unique inside its directory. can include any ASCII character except a slash $ vi practice $ vi letter

S AVING /L OADING F ILE First check that you are in command mode by pressing [ESC] To save file and quit the vi: ZZ :w q To safe file without quitting vi: :w (write to specified file) :w (write again) :w! (to override existing file) To load existing file: :r To edit new file: :e

Q UITTING VI To return to the last saved version of the file: :e! [Enter] :q! [Enter] (with quitting from vi) vi normally won't let you throw away your edits. The exclamation point added to the :e or :q command causes vi to override this prohibition. To quit vi if no changes were made :q

M OVING THE C URSOR up k down j left h right l : 4l moves the cursor four spaces to the right, just as if you had typed l four times (llll) A line is any text entered between newlines. beginning of the current line 0 end of the current line $ :set nu (to display line numbers)

M OVING THE C URSOR BY B LOCKS To the next word w (symbols and punctuation as equivalent to words) W To the previous word b (symbols and punctuation as equivalent to words) B Movement commands take numeric arguments 4w, or 5B To the line number nn :nn nnG For example, :4 or 4G (goes to the 4 th line) To the last line :$

I NSERTING T EXT i inserts text before cursor. a appends text after cursor. A appends text to the end of current line. I inserts text at the beginning of line. With numeric prefixes, you might insert a row of underlines or alternating characters: 50i*[ESC] inserts 50 asterisks o opens blank line below cursor for text. O opens blank line above cursor for text. All of these commands leave you in insert mode. After inserting text, press [ESC] to escape back to command mode. J joins two consecutive lines. Using a numeric argument with J joins that number of consecutive lines: 3J.

C HANGING T EXT Command c replaces any text in your file specified by movement command: cw to the end of the current word c2b back two words c$ to the end of line c0 to the beginning of line c, like i and a, leaves you in insert mode until you press the [ESC]. General format of commands: ( command )( number )(movement command) ( number )( command )(movement command) Lines shortcuts cc changes an entire line. C is shortcut for c$. r replaces a single character with another single character. No [ESC]. R overstrikes existing characters with new characters. s ( S ) deletes character at cursor (line) and substitute text. ~ changes a case of letter. No number prefix or movement.

D ELETING T EXT Command d deletes any text in your file. d is combined with a movement command to specify what to delete: dw the current word d2b back two words d$ to the end of line d0 to the beginning of line Lines shortcuts dd deletes an entire line (2dd) D is shortcut for d$. x deletes a single character before the cursor. 5x deletes 5 characters before the cursor : d deletes lines in the range. Examples of the range are 1,$ 1,..,$ 5,12.,.+2

M OVING T EXT "cut and paste“ paradigm p puts the text in the buffer after the cursor position. P puts the text before the cursor. :nn, [Enter], p – to puts the text after nn position Once you delete text, you must restore it before the next change command or delete command; otherwise, deleted text will be lost. Transposing Two Letters : xp (delete character and put after cursor command) transposes two letters. There is no command to transpose words.

C OPYING T EXT A yank command ( y ) copies the selected text into a buffer. You can then place this copy elsewhere in the file with the p command. y can be combined with any movement command ( yw, y$, 4yy ). The shortcut yy, Y operates on an entire line. : y yanks lines in the range. Yanking uses the same buffer as deleting. Each new deletion or yank replaces the previous contents of the yank buffer.

R EPEATING OR U NDOING Y OUR L AST C OMMAND. (period) repeats last editing command. Position the cursor where you want to repeat the editing command, and type a period. Occasionally, vi has problems repeating a command. u undoes your last command.The cursor need not be on the line where the original edit was made. U undoes all edits on a single line, as long as the cursor remains on that line. Once you move off a line, you can no longer use U. pu uu

S CROLLING Ctrl+D down half screen Ctrl+U up half screen Ctrl+F forward one screen Ctrl+B back one screen Ctrl+L refresh screen (useful in telnet) z[Enter] moves current line to top of thescreen and scroll. z understands a numeric prefix as a line number that it will use in place of the current line.

S EARCHING The search command is the special character / (slash): / pattern[Enter] A pattern can be any sequence of characters. vi begins the search at the cursor and searches forward, wrapping around to the start of the file if necessary. To begin a search backward: ? pattern[Enter] n repeats search in the same direction. N Repeat search in opposite direction. / [Enter] repeats search forward. ? [Enter] repeats search backward.

S EARCHING /R EPLACING : s/string to change/desired string substitutes first occurence : s/string to change/desired string/g substitutes all occurences in the range You can also use % instead of 1,$ to specify every line in a file. If you'd like to confirm each replacement before it is made, add the c option (for confirm) at the end of the substitute command: : s/string to change/desired string/gc If you want to make the replacement, you must enter y (for yes) and press [Enter]; otherwise, simply press [Enter].