0% found this document useful (0 votes)
20 views24 pages

VI Editor

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views24 pages

VI Editor

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Vi editor

Vi editor
• is a visual editor used to create and edit text
files, doc and programs.
• Displays content of the files.
• Available for all the versions of unix and linux.
• In Red hat linux it links in the form of vim
editor.
• View command is used to open a file in the
read only mode.
Getting started
• Type vi filename then press enter key in the prompt mode.
• E.g. vi lab1.sh
• After pressing enter key vi editor mode will open a editor mode like this
• |
• ~
• ~
• ~
• ~
• ~
• ~
• ~
• ~
• ~
• ~
• ~
• ~
• "testfile" [New File]
• Then press I key to insert text.
• You will notice a tilde (~) on each line
following the cursor. A tilde represents an
unused line. If a line does not begin with a
tilde and appears to be blank, there is a space,
tab, newline, or some other non-viewable
character present.
Operation Modes

• Command mode − This mode enables you to


perform administrative tasks such as saving the
files, executing the commands, moving the cursor,
cutting (yanking) and pasting the lines or words, as
well as finding and replacing. In this mode,
whatever you type is interpreted as a command.
• Insert mode − This mode enables you to insert text
into the file. Everything that's typed in this mode is
interpreted as input and placed in the file.
• vi always starts in the command mode. To enter
text, you must be in the insert mode for which
simply type i. To come out of the insert mode,
press the Esc key, which will take you back to the
command mode.
• Hint − If you are not sure which mode you are in,
press the Esc key twice; this will take you to the
command mode. You open a file using the vi editor.
Start by typing some characters and then come to
the command mode to understand the difference.
Getting Out of vi

• The command to quit out of vi is :q. Once in the


command mode, type colon, and 'q', followed by
return. If your file has been modified in any way, the
editor will warn you of this, and not let you quit. To
ignore this message, the command to quit out of vi
without saving is :q!. This lets you exit vi without
saving any of the changes.
• The command to save the contents of the editor
is :w. You can combine the above command with
the quit command, or use :wq and return.
• The easiest way to save your changes and exit
vi is with the ZZ command. When you are in
the command mode, type ZZ.
The ZZ command works the same way as
the :wq command.
Commonly used commands
• h moves the cursor to the previous character
• i moves the cursor to the next character
• k moves the cursor to the line above the
current line
• j moves the cursor to the line below the
current line
• x deletes the character at the current cursor
position
• :wq <enterkey> save and quit from vi ediotor
mode
• :w<enterkey> save the file
• :q!<enter> quit without save the file
• :e<filename><enter> open specified file
• :r<filename><enter> read and inserts the
contents after the current line.
• :w<filename><enter> write the file
• :w!<filename><enter>forcefully write the file.
• !<commandname><enter> executes a shell
command
Insert and replace commands
• i key Inserts text before the current cursor location
• I key Inserts text at the beginning of the current line
• a key Inserts text after the current cursor location
• A key Inserts text at the end of the current line
• o key Creates a new line for text entry below the
cursor location
• O key Creates a new line for text entry above the
cursor location
• Rx key replac the current character with
specified character
• Rtext<esc> key replace characters at the
current cursor position with specified text
until <esc> is pressed
Cursor movement commands
• CTRL+d Moves forward 1/2 screen
• CTRL+f Moves forward one full screen
• CTRL+u Moves backward 1/2 screen
• CTRL+b Moves backward one full screen
• CTRL+e Moves the screen up one line
• CTRL+y Moves the screen down one line
• CTRL+u Moves the screen up 1/2 page
• CTRL+d Moves the screen down 1/2 page
• CTRL+b Moves the screen up one page
• CTRL+f Moves the screen down one page
• CTRL+I Redraws the screen
• 0(zero) moves cursor to the beginning of the
file
• $ moves the cursor to the end of file
Word movement commands
• w key moves the cursor to the next word
• b key moves the cursor to the previous word
• e key moves the cursor to the end of the word
Change Commands

• cc Removes the contents of the line, leaving you in insert mode.


• cw Changes the word the cursor is on from the cursor to the
lowercase w end of the word.
• r Replaces the character under the cursor. vi returns to the
command mode after the replacement is entered.
• R Overwrites multiple characters beginning with the character
currently under the cursor. You must use Esc to stop the
overwriting.
• s Replaces the current character with the character you type.
Afterward, you are left in the insert mode.
• S Deletes the line the cursor is on and replaces it with the new
text. After the new text is entered, vi remains in the insert mode.
Deletion and modification commands
• dw deletes a word
• dd deletes a line
• cw changes a word
• cc changes a line
• X deletes the character before the current cursor
position
• J joins the line
• u undo the last changes
• Dot(.) repeats the last change made
Copy and Paste Commands

• You can copy lines or words from one place and


then you can paste them at another place using
the following commands −
• yy
• Copies the current line.
• yw
• Copies the current word from the character the
lowercase w cursor is on, until the end of the
word.
• p
• Puts the copied text after the cursor.
• P
• Puts the yanked text before the cursor.
• fx finds the specified character x on the
current line after the current cursor position
• Fx finds the specified character x on the
current line before the current cursor position
• / pattern <enter> finds the next line
containing the specified pattern
• ?pattern<enter> finds the previous line
containing the specified pattern
example
• Student file stores the details of the student
who have registered with infosys placement
• “00001”,”aaaa”,”bbbb”,”tkc”,”tiruppur”
• “00002”,”cccc”,”dddd”,”tkc”,”tiruppur”
• “00003”,”eeee”,”ffff”,”PSG”,”coimbatre”
• “00004”,”gggg”,”hhhh”,”stella maris”,”chennai”
example
• Student file stores the details of the student
who have registered with infosys placement
• “00001”,”aaaa”,”bbbb”,”tkc”,”tiruppur”
• “00002”,”cccc”,”dddd”,”tkc”,”tiruppur”
• “00003”,”eeee”,”ffff”,”PSG”,”coimbatre”
• “00004”,”gggg”,”hhhh”,”stella maris”,”chennai”
• If we want to display details of the particular
city student e.g. tiruppur then give the
command /tiruppur and it will list the details
as follows
• “00001”,”aaaa”,”bbbb”,”tkc”,”tiruppur”
• “00002”,”cccc”,”dddd”,”tkc”,”tiruppur”

You might also like