The VI Editor: Diwakar Goel

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 16

The vi Editor

Diwakar Goel

Introduction to vi
Modes of Operation
There modes of operation
Input, Command, Last Line Mode
ESC Input mode Command mode Insert, Append, Replace heed Enter : Last Line mode

The Work Buffer


the buffer

During the editing session, vi makes all changes in

Basic (Loading and Saving files)


vi [filename] - start vi ( edit filename) - open
a single file vi [filename1 filename2] - opening multiple files vi +[number, /string] - begin with start line, first matching string, relatively :e filename - edit filename - open another file from vi :q - terminate vi without saving
contd
3

Basic (Loading and Saving files)



:q! - terminate vi forcefully without change :x terminate vi with saving :w - save edited file, stay in vi :w filename - write to the filename :w! filename - overwrite the file :r filename - read in text in filename :r! command - execute command and read output in file. :e# - quit from the current file with out

:rew - Go back to first file.

change (if more than one file is open)

Command mode - Moving the Cursor




l,h,j,k - move right, left, down, up w,b,e - move right one, left one, to end of word -,Enter - move start of upper line, start of next line ^,$ - move start of line, end of line <crtl>+u,d,b,f - move screen one half-page up, one half page down, one page up, one page down in text H,M,L - move left end of top, middle line, bottom line G,nG - move to last line, move to nth line [Address1] mo [Address1] Move the contents from address1 to address2 [Address1] co [Address1] Copy the contents from address1 to address2
5

Input Mode


i - insert before the cursor a - append after the cursor o - insert the text on a new line after the current line r - replace the current one character, automatically return to command mode I - insert the text at start of line A - insert the text at end of line O - insert the text on a new line before the current line R - overwrite all character until press <ESC> <ESC> - return to command mode
6

Command mode - Deleting text



x - delete the character under the cursor dw - delete to the end of word dW - delete to end of space delimited word D - delete to end of line dd - delete the current line u - undo the last change made U - restore current line to previous state

Command mode - Changing text


cw - change to end of word cb - change to begin of word cW - change to end of space delimited

word cB - change to begin of space delimited word cc - change the current line
8

Searching for a String


The Search Commands
/xxx - search forward for text string xxx ?xxx - search backward for text string xxx / - repeat search forwards ? - repeat search backwards n - repeat search in same direction N - repeat search in opposite direction Special Characters in Search Strings ^ - the beginning-of-line indicator $ - the end-of-line indicator . - the any character indicator \> - the end-of-word indicator \< - the beginning-of-word indicator [ ] - the character class definition
9

Substituting One String for Another


[address]s/search-string/replace-string[/g] address
number - line number 77,100 - line 77 through 100 1, . - the beginning of the work buffer through the

current line .,$ - the current line through the end of work buffer 1,$ - the entire work buffer % - the entire work buffer .,.+10 - the current line through the tenth following line

10

Miscellaneous Commands
J - join command ( Join Lines) <ctrl>+g - status command (line number of
current line, total number of line)
End line mode - :f

. - period command (repeat the most recent

command that made a change) ~ - tilde command (change between lowercase and uppercase)

11

The Put, Delete and Yank Commands


y - yank command
p - paste the text on a new line after the
yy, Y - yank the current line nyy, nY - yank the n line from current line

current line P - paste the text on a new line above the current line dd- deletes the current line ndd- delete n lines from the current line
12

Reading and Writing Files


Read Command
:[address] r [filename]

Write Command
:[address]w[!] [filename] - overwrite mode
:[address]w>>filename - append mode address - the same as substitution

command

13

Setting Parameters
Setting Parameters in a Startup File
Bourne and Korn shell - .profile

EXINIT = set param1 param2 export EXINIT C shell - .login setenv EXINIT = set param1 param2 .exrc set param1 param2 Parameters :set all - show all parameter number, nonumber - show line number, hide line number wrapmargin=nn - break the line by inserting <newline> character at the closest blank delimited word boundary nn - the number of character from the right side of the screen

14

Setting Parameters
Parameters (Cont.)
Shell[=pathname] showmode, noshowmode - give a cue to let you know when

vi is in Input Mode flash, noflash - beep when give invalid command or press <ESC> in Command Mode ignorecase, noignorecase - ignore case in search magic, nomagic - special characters in search strings have no special meanings (except ^, $) list, nolist - show <TAB> -> ^I, end of line -> $ wrapscan, nowrapscan autoindent, noautoindent shiftwidth=nn

15

Units of Measure
Character Word - <space>, <tab>,<newline>, numeral,

punctuation marks Line - <newline> Sentence - period, exclamation point, question mark, followed by two <space> or a <newline> Paragraph - blank line Screen
16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy