Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.

Slides:



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

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.
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.
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:
Basic Text Processing, Redirection and Pipes. 222 Lecture Overview  Basic text processing commands head, tail, wc  Redirection and pipes  Getting to.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
The UNIX development environment CS 400/600 – Data Structures.
More on Linux - vi Opening Discussion zWhat did we talk about last class? zYou will use the command line a lot in this course. So lets review.
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.
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.
Introduction to Unix – CS 21 Lecture 7. Lecture Overview Regular expressions revisited emacs versus vi Basic emacs and vi usage.
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.
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.
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.
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.
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)
Emacs CSC 135.
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:

Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey

The vi editor The standard interactive editor on Unix systems is called ‘vi’. How do you open a file? vi file1 file2 This allows you to edit two files, first file1, then file2

Command Mode When you start vi, you begin in command mode All commands are entered from the keyboard--no mouse here! vi has two other primary modes, insert mode for free-form text input, and ex- mode for running commands on the text

Movement Commands Movement: You can move the cursor around using the arrow keys In the old days, we used h (left), j (up), k (down), and l (right) 0 moves to the beginning of a line, $ moves to the end -F and -B move forward and backwards a page

More Movement w moves you to the start of the next word e moves you to the last character of the next word b moves you to the previous word Note that vi separates all words by punctuation Use the capitalized versions: W, E, B for whole words

And more movement Use ( and ) to jump to prior and next sentences Use { and } to jump to prior and next paragraphs

Saving and Quitting Typing : followed by a letter executes what is called ‘ex’ mode. :q will quit vi, if you have nothing to save :q! will quit vi, throwing away changes :w will save the current file you’re editing :x (or :wq) will save the file and quit vi

More Files :w filename will write the contents to the given file name :sp filename will open another file in a split window -w -w will switch between windows--all commands only affect the active window

My dog closed my terminal! Don’t worry, vi keeps a backup and will warn you when you try to edit the file again vi -r will list the files that can be recovered vi -r will recover the edited file when your terminal was closed

Simple editing x deletes the character the cursor is on J (capitalized) joins the next line with the current line r followed by a character replaces the character under the cursor dd deletes the current line

More editing d plus a movement command will delete in that manner dw deletes up to the next word, db the prior word d) deletes to the end of the sentence, d} deletes to the end of the paragraph. will repeat a command. For example, dd. will delete two lines

Undo! Finally, the command u will undo prior edits -r will redo the last undo

Insert Mode To enter insert mode: i will let you enter text at the cursor a will move the cursor forward one and let you enter text To exit insert mode: will put you back in command mode

More Insert mode You can now type in free-form, backspace, delete, and enter will work as expected More insert commands: A will start appending text to the current line I will start adding text at the start of the current line

Edit/Insert o will insert a blank line below your current line, move the cursor and place you in insert mode O will insert a blank line above your current line, move the cursor and put you in insert mode cc will replace the current line with a new line and put you in insert mode

Edits/inserts c0 deletes everything from the cursor to the start of the line and puts you in insert mode c$ deletes everything from the cursor to the end of the line and puts you in insert mode c (for change) is like the d command, you can use it with movements to edit and insert

Combos! We’ve seen two combo commands already: d and c Using a number prior to a command repeats it that many times 100dd deletes 100 lines, 12w jumps forward 12 words

Special c and d combos You can combine c and d with a number and command: d2j will delete the current and next two lines d3w will delete the next 3 words Experiment!

Searching Sometimes you need to find something: / will search forward for the regular expression in the text and put the cursor on the expression / will repeat the last search ? will search backwards

Moving to visual mode Hitting ‘v’ will switch vi (on vim, elvis, gvim, etc versions) to visual mode. visual mode was added later, old versions of vi won’t have it v will let text be highlighted through the use of movement commands Hitting ‘v’ while in visual mode will drop you back to command mode

Copy/Cut Once in visual mode: y will copy the text (y for yank!) d will cut the text Either of these commands will drop you back to command mode p/P will insert the text which was copied/cut from y or d either after/before the cursor

Replacing text Replacing text requires the ex-mode :s/ /replacement/ :s/ /replacement/g will replace all occurrences on the line :%s/ /replacement/g will replace all in the file :%s/ /replacement/gc will ask for confirmation

Miscellaneous For source files, vi can auto-indent for you If it’s not on, type :set autoindent -d will indent to the left one level -t will indent to the right one level :set tabstop=4 sets the indention to 4 per level

:set sm will show matching {, (, or [ when programming :syntax on will turn on syntax highlighting (ie, color)