Vi Editor for Beginners

Standard

Today sayan,aavrug,chandan have taken a class on vi editor under Dinesh Kumar Pradhan .After attending class I am writing

The vi editor is available on almost all unix systems.VI can be used from any type of terminal because it does not depend on arrow keys  and function keys.vi (/’vi – ai’) is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by (and thus standardized by) the Single  Unix Notification and POSIX.

The original code for vi was written by Bill Joy in 1976, as the visual mode for a line editor called ex that Joy had written with Chuck Haley.Bill Joy’s ex 1.1 was released as part of the first BSD Unix release in March, 1978. It was not until version 2.0 of ex, released as part of Second Berkeley Software Distribution in May, 1979 that the editor was installed under the name vi (which took users straight into ex’s visual mode), and the name by which it is known today. Some current implementations of vi can trace their source code ancestry to Bill Joy; others are completely new, largely compatible re implementations.All thing will be working only with terminal.

Command Summary:-

How to open vi editor:-

1) At first go to terminal

Starting VI :-

vi <new filename> :- create a new file [Ex.  vi myself.c]

vi <filename> :- edit a file  [Ex.  vi kundan.c   i.e. kundan.c is existing file]

Now it is in command mode.

Entering VI :-

i   Insert text left of cursor

a  append text right of cursor

o  Start

These command are also working in command mode.

Moving Cursor in VI:-

h  left one space

j   down on  line

k  up one line

l  right one space

These command are also working in command mode.

Replacing Character, lines and words in VI:-

r      replace the current character

s     Enter edit mode and substitute current character by several one

cw   enter edit mode change the word after the cursor

c     enter edit mode change rest of line after the cursor

These command are also working in command mode.

Copying and Pasting in VI:-

yy   copy the current line to the buffer

p    Paste after the current line

P    paste before the current line

These command are also working in command mode

.

Deleting characters,words,and lines in VI:-

x    delete the characters at the current location

dw  delete the current word

D    delete remaining after cursor

dd   delete the current line

These command are also working in command mode.

Looking for strings in VI:-

/string   find the first occurence of string after cursor

?string  find the first  occurence of string befor the cursor

n          find the next occrance of last search

These command are also working in command mode.

Replacing in VI:-

n,ps/str1/str2/g  between  the line number n and p substitute all occurance of str1  by str2

1,$s/str1/str2/g in the  whole file substitute all occurance of str1 by str2

These command are also working in command mode.

Basic Editing in VI:-

u   Undo last change

U  restore last change

O  insert blank line abovecursor

0(Zero) Begging of line

M  to middle line

H   to the top line of the screen

$   last line of this screen

These command are also working in command mode.

Closing and Saving in VI:-

ZZ   save and their quit

:w   save file

:q!   discard changes and quit

:wq save & quit file

These command are also working in command mode.

For more knowledge:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s