Sie sind auf Seite 1von 3

Chapter8

Introduction to vi
The vi Editor
υ Modes of Operation
ESC :

Input Command Last Line


mode mode mode

Insert, Append, Replace … Enter

υ The Work Buffer


 During the editing session, vi make all changes in the buffer

Basic
Command mode - Moving the Cursor
(Loading and Saving files)
υ vi [filename] - start vi ( edit filename) υ l,h,j,k - move right, left, down, up
υ vi +[number, /string] - begin with start line, first υ w,b,e - move right one, left one, to end of word
matching string, relatively υ W,B,E - equivalent above except the space delimited
υ :e filename - edit filename word
υ :q - terminate vi without saving υ -,Enter - move start of upper line, start of next line
υ :q! - terminate vi, leave file unchanged υ ^,$ - move start of line, end of line
υ :w - save edited file, stay in vi υ <crtl>+u,d,b,f - move screen one half-page up, one
υ :r filename - read in text in filename half page down, one page up, one page down in text
υ H,M,L - move left end of top, middle line, bottom line
υ G - move to last line
υ nG - move to nth line

Input Mode Command mode - Deleting text


υ i - insert before the cursor υ x - delete the character under the cursor
υ a - append after the cursor υ dw - delete to the of word
υ o - insert the text on a new line after the current line υ dW - delete to end of space delimited word
υ r - replace the current one character, automatically υ D - delete to end of line
return to command mode υ dd - delete the current line
υ I - insert the text at start of line υ u - undo the last change made
υ A - insert the text at end of line υ U - restore current line to previous state
υ O - insert the text on a new line before the current
line
υ R - overwrite all character until press <ESC>
υ <ESC> - return to command mode

1
Command mode - Changing text Searching for a String
υ The Search Commands
υ cw - change to end of word
 /xxx - search forward for text string xxx
υ cb - change to begin of word
 ?xxx - search backward for text string xxx
υ cW - change to end of space delimited word  / - repeat search forwards
υ cB - change to begin of space delimited word  ? - repeat search backwards
υ cc - change the current line  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

Substituting One String for Another Miscellaneous Commands


υ [address]s/search-string/replace-string[/g] υ J - join command
υ address υ <ctrl>-g - status command (line number of current
 number - line number line, total number of line)
 77,100 - line 77 through 100  End line mode - :f
 1, . - the beginning of the work buffer through the current line υ . - period command (repeat the most recent
 .,$ - the current line through the end of work buffer command that made a change)
 1,$ - the entire work buffer
υ ~ - tilde command (change between lowercase and
 % - the entire work buffer
uppercase)
 .,.+10 - the current line through the tenth following line

The Put, Delete and Yank Commands Reading and Writing Files
υ The General Purpose Buffer υ Read Command
 Store the text that you most recently changed, deleted and  :[address]r [filename]
yanked. υ Write Command
 Undo command uses the general purpose buffer when it
 :[address]w[!] [filename] - overwrite mode
restores text
 :[address]w>>filename - append mode
υ y - yank command  address - the same as substitution command
 yy, Y - yank the current line
 nyy, nY - yank the n line from current line
υ p - paste the text on a new line after the current line
υ P - paste the text on a new line above the current line

2
Setting Parameters Setting Parameters
υ Setting Parameters in a Startup File υ Parameters (Cont.)
 Bourne and Korn shell - .profile
 Shell[=pathname]
EXINIT = ‘set param1 param2 …’
 showmode, noshowmode - give a cue to let you know when
export EXINIT
vi is in Input Mode
 C shell - .login
 flash, noflash - beep when give invalid command or press
setenv EXINIT = ‘set param1 param2 …’
<ESC> in Command Mode
 .exrc
 ignorecase, noignorecase - ignore case in search
set param1 param2 …
 magic, nomagic - special characters in search strings have
υ Parameters no special meanings (except ^, $)
 :set all - show all parameter  list, nolist - show <TAB> -> ^I, end of line -> $
 number, nonumber - show line number, hide line number  wrapscan, nowrapscan
 wrapmargin=nn - break the line by inserting <newline>  autoindent, noautoindent
character at the closest blank delimited word boundary  shiftwidth=nn
λ nn - the number of character from the right side of the screen

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

Das könnte Ihnen auch gefallen