vi editor in linux

In vi editor we have below two modes.

1. Insert mode

2. Command mode

Insert Mode:

In this mode we can insert the required content for the file.

Command Mode:

In this mode we can do maximum operations like searching a word, copy, delete, paste, undo changes, etc…

Creating file using vi editor:

[root@server ~]# vi testfile

Once executed above command press i in keyboard to move insert mode. You will find -INSERT- line bottom of the file once you moved to insert mode.

~
~
~
~
~
~
~
-- INSERT --

Type the content for this file. Once provided the content press esc key in keyboard to go back to command mode and use :wq to save and exit from the file

[root@server ~]# vi testfile
This is my test file
~
~
~
:wq

 

Find the below more options in vi editor which will be executed in command mode.

:q Simple q will help us to exit from the file without saving file.

:u undo operation

/ to search any word inside of this file

example: /test

yy to copy a line

<n>yy to copy n number of lines eg: 5yy

dd to delete a line

<n>dd to delete n number of lines eg: 10dd

p to paste the copied lines. it will paste the copied lines next line of the cursor placed.

:set nu to set line numbers inside the files.

 

 

Leave a Reply

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