Vi Editor - Linux

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Basic

Introduction to vi (Loading and Saving files)


 Modes of Operation  vi [filename] - start vi ( edit filename)
:
 vi +[number, /string] - begin with start line, first matching
ESC
Input Command Last Line
mode mode mode string, relatively
Insert, Append, Replace … Enter
 :e filename - edit filename
 The Work Buffer  :q - terminate vi without saving
 During the editing session, vi make all changes in the buffer  :q! - terminate vi, leave file unchanged
 :w - save edited file, stay in vi
 :r filename - read in text in filename

Command mode - Moving the Cursor Input Mode


 l,h,j,k - move right, left, down, up  i - insert before the cursor
 w,b,e - move right one, left one, to end of word  a - append after the cursor
 W,B,E - equivalent above except the space delimited word  o - insert the text on a new line after the current line
 -,Enter - move start of upper line, start of next line  r - replace the current one character, automatically return to
 ^,$ - move start of line, end of line command mode
 <crtl>+u,d,b,f - move screen one half-page up, one half  I - insert the text at start of line
page down, one page up, one page down in text  A - insert the text at end of line
 H,M,L - move left end of top, middle line, bottom line  O - insert the text on a new line before the current line
 G - move to last line  R - overwrite all character until press <ESC>
 nG - move to nth line  <ESC> - return to command mode

Command mode - Deleting text Command mode - Changing text


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

1
Searching for a String Substituting One String for Another
 The Search Commands
 /xxx - search forward for text string xxx  [address]s/search-string/replace-string[/g]
 ?xxx - search backward for text string xxx  address
 / - repeat search forwards
 ? - repeat search backwards  number - line number
 n - repeat search in same direction  77,100 - line 77 through 100
 N - repeat search in opposite direction
 1, . - the beginning of the work buffer through the current line
 Special Characters in Search Strings
 ^ - the beginning-of-line indicator  .,$ - the current line through the end of work buffer
 $ - the end-of-line indicator  1,$ - the entire work buffer
 . - the any character indicator
 \> - the end-of-word indicator  % - the entire work buffer
 \< - the beginning-of-word indicator  .,.+10 - the current line through the tenth following line
 [ ] - the character class definition

Miscellaneous Commands The Put, Delete and Yank Commands


 J - join command  The General Purpose Buffer
 <ctrl>-g - status command (line number of current line,  Store the text that you most recently changed, deleted and
total number of line) yanked.
 End line mode - :f  Undo command uses the general purpose buffer when it
restores text
 . - period command (repeat the most recent command that
made a change)  y - yank command
 yy,Y - yank the current line
 ~ - tilde command (change between lowercase and
 nyy, nY - yank the n line from current line
uppercase)
 p - paste the text on a new line after the current line
 P - paste the text on a new line above the current line

Reading and Writing Files Setting Parameters


 Setting Parameters in a Startup File
 Read Command
 Bourne and Korn shell - .profile
 :[address]r [filename] EXINIT = ‘set param1 param2 …’
 Write Command export EXINIT
 C shell - .login
 :[address]w[!] [filename] - overwrite mode
setenv EXINIT = ‘set param1 param2 …’
 :[address]w>>filename - append mode  .exrc
 address - the same as substitution command 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

2
Setting Parameters Units of Measure
 Parameters (Cont.)  Character
 Shell[=pathname]
 showmode, noshowmode - give a cue to let you know when vi is in  Word - <space>, <tab>,<newline>, numeral, punctuation
Input Mode marks
 flash, noflash - beep when give invalid command or press <ESC> in
Command Mode  Line - <newline>
 ignorecase, noignorecase - ignore case in search  Sentence - period, exclamation point, question mark,
 magic, nomagic - special characters in search strings have no special
meanings (except ^, $) followed by two <space> or a <newline>
 list, nolist - show <TAB> -> ^I, end of line -> $  Paragraph - blank line
 wrapscan, nowrapscan
 autoindent, noautoindent  Screen
 shiftwidth=nn

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