Friday, 2 August 2019

Vi Editor Commands in Linux

Vi editor

The Vi editor is the text editor mostly available in all Unix and Linux flavors. This editor is used to create the files and modifies the files.
In this VI indicates that visual interface.
In the new versions of Linux, vim editor is coming which is Vi improved version.

There are three modes in vi editor
  • Command mode
  • Insertion mode
  • Execution mode
By opening the file using vi editor first it will go to command mode.

Command mode

In command, we can modify the file like copy, paste and delete the lines etc.,
Press ctrl+R to redo the operation
/<search_word> is used to search a particular word in the document or file.
The subcommands used to do particular operations in the file are as follows.

CommandOperation
Esc+cwTo change the word
Esc+dwTo delete the word
Esc+rTo replace the character
Esc+shift+rTo replace the line
Esc +aTo move courser to at the end of the word
Esc+shift+aTo move courser to the end of the line
Esc+oTo add the line below the courser
Esc+shift+oTo add the line above the courser
Esc+shift+ggTo move courser last page to the last line
Esc +ddTo delete the line
Esc+nddTo delete the number of lines
Esc+shift+oTo add the line above the courser
Esc+ yyTo copy the line
Esc+pTo paste the copied lines
Esc+nyyTo copy the number of lines
Esc+uTo undo the operation
Esc+ctrl+RTo redo the operation

Insertion mode

By pressing a,I we will go to insertion mode from command mode. To go back to the command mode press Esc button.
You can navigate through the text using the dos keys.

Execution mode

By pressing shift+: we will go to to the execution mode. in the execution mode, we will do the tasks like saving the file, quitting from the file etc.,
The following are the commands in the execution mode to do the particular tasks.

CommandOperation
Shift+Goes from command mode to the execution mode
Shift+set nuTo set line numbers to the file
Shift+set nuTo set line numbers to the file
Shift+:set nonuTo unset the line numbers
Shift+set nuTo set line numbers to the file
Shift+:wq!To save and quit forcefully
Shift+q!To quit without saving forcefully
Shift+:1,$s/old_string/new_string /gTo replace the string

0 comments:

Post a Comment