In vi editor we have below two modes.
1. Insert mode
2. Command mode
In this mode we can insert the required content for the file.
In this mode we can do maximum operations like searching a word, copy, delete, paste, undo changes, etc…
Creating file using vi editor:
[[email protected] ~]# 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
[[email protected] ~]# 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
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.