Vi and Vim editor tutorial

Vi and Vim editor tutorial

Earlier we have seen about basics about VIM editor in Vim Editor tips post.In this post i am going to explain about some advance features of vim editor in detail. So lets learn some advance feature about vi and vim editor.

There are three modes in VI and VIM editor they are given below

1.Command Mode

2.Insert Mode and

3.Exit Mode

Vi and Vim editor tutorial
In Command Mode you can move your cursor, cut, copy and paste text. Right from command mode you can change to other two modes
In Insert Mode you can edit and modify the content of the file
In Exit Mode we can save, quit, search and replace etc.,

To exit from current mode Hit Esc(Escape Key). if you Hit double EscEsc(Escape Key) you will reach command mode

 

The global configuration file of vim is

#vi /etc/vimrc

Example:

Open /etc/vimrc file as root user and append the following line in the end to disable color in vim editor

syntax off

What ever you are changing here will effect globally to all users

To work in graphical VIM

#gvim /etc/passwd

Another method

Applications -> Programming -> VI IMproved

To navigate between the text in Command mode

^
k

< h         l >

j
v

The k key is used to move up direction in command mode

The h and key is used to move left direction in command mode

The I and key is used to move right  direction in command mode

The j key is used to move down direction in command mode

Task                             Change (replace) Delete (cut)   Yank (copy)
Line                              cc                         dd                   yy
Letter                            cl                          dl                    yl
Word                            cw                        dw                  yw
Sentence After             c)                         d)                   y)
Sentence Before          c(                         d(                   y(
Paragraph Before        c{                         d{                   y{
Paragraph After           c}                         d}                   y}

Move cursor to the starting of the line from command mode

shift + 6

Move the Cursor to the starting of the line, (Bring in to Insert Mode)

shift + i

shift + 6

Move the Cursor to the end of the line, (Bring in to Insert Mode)

Shift + a
Shift + 4

Move the Cursor one word backward

Shift + b
b

Move the Cursor one word forward

e
shift + e
Shift + w

Undo a word ( Like Ctrl +Z in Windows )

esc   + u

Redo a word ( Like Ctrl + Y in Windows )

ctrl  + r

To remove a single letter right side ( Like DELETE button in keyboard )

x

To remove a single letter left side ( Like BACKSPACE in keyboard )

X

To go to Insert mode

i

To append a text

a

To go to insert mode and print a empty line below the cursor

o

To go to insert mode and print a empty line above the cursor

shift + o

To Save a file

:w

Exit from the file

:q

Save and Exit from the file

:wq

To go to the 20th line of the file

: x

Exit with out saving the file

:q!

To go the first line of the file

gg

To go to the 10th line of the file

10gg

To go to the 20th line of the file

20gg

To go to the Last line of the file

Shift + g

To go to 25th line

:25

Show the line numbers

:se nu

It will start searching word Technical in your file

:/Technical

After it reaches the word Technical press n to search next by down direction

n

After it reaches the word Technical press N to search next by up direction

N

To search for text old and replace it with new globally in the file

:%s/old/new/g

To execute an external command from the vim editor

:!ls

To save the file in another file called rajkumar

:w rajkumar

To ignore k-sensitive

:set ic

To Ignore colour in vim editor

:syntax off

To scroll down

shift +^D

To know more about VIM or vi editor use below commands

#man vim

or

#man vi

or

#vimtutor




One thought on “Vi and Vim editor tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *