Command of the VI-Editor and implement them.

In this article, we explain to you Linux vi commands and Implement them.

Theory and Output:

  • The vi editor (short for a visual editor) is text editor which is available on almost all Unix/Linux systems
  • vi has no menus but instead uses combinations of keystrokes in order to accomplish commands.
  • you can use vi editors to edit(add, change, and delete text) an existing file or to create a new file from scratch. You can also use this editor to just read a text file

The UNIX vi-editor is a full-screen editor and has two modes of operation:

  • Command mode: This mode enables you to perform administrative tasks such as saving files, executing commands, moving the cursor, cutting and pasting lines or words, and searching and replacing. In this mode, whatever you type is interpreted as a command
  • Insert mode: This mode enables you to insert text into the file. Everything that’s typed in this mode is interpreted as input and finally, it is put in the file.
  • By default vi is in command mode.

Linux vi commands and Implement them

Refer one by one command to better understand

The Syntax for creating (if not created before) and opening files in vi-editor:

$ vi <file-name>

1– i command:- This command is used to insert data in the file/used to go in insert mode.

After pressing (i) it will go into insert mode and we can write some content inside the file.

Linux vi commands and Implement them

Also read: – How To Recover Deleted Files, Photos, Videos, Documents

2- Esc command: This command is used to escape out from the insert mode and come back to the command mode.

Note(you can see the difference between above 2 pics with cursor position)

Linux vi commands

3-a command:- This command is used to append the more data/go back to the insert mode.

Appending new data.

Linux vi commands and Implement them

4-A command:- This command is also used for inserting a new data but at the end of line/goes into insert mode

This image shows cursor is in the midway.

a command

5-u command: This command is used for  undo the last change.(we have added rollno here)

That last change is get undo. Note :(U command undo all the changes to the entire line)

u command

6-o command: This command open a new line/goes into insert mode.

o command

7- O command:- This command before open a new line/goes into insert mode.

O command

8dd command: This command is used to delete one single line.

One line get deleted.

dd command

Suggested: – How to install Ubuntu on Virtual box for windows.

9-D command: This command delete the content of the line after cursor

You can see delete command work after m i.e. M Matunga.

. You can delete one by one word also


d command

10- C command:- This command delete the content of the line after cursor and insert new text.

Linux vi commands

11- dw command:This command deletes a single word.

Linux vi commands

12- cw command:– This command changes the word.

Linux vi commands

13- x command– These commands at cursor.

Linux vi commands

14-r command: This command replaces the char.

Linux vi commands

15-R command: This command overwrites char from cursor onwards.

Linux vi commands

16-s command: This command substitute one char under cursor and continue to inserting from that position.

Linux vi commands

17-S command: This command substitute entire line and begin to insert at the beginning of the line.

18-~ command: This command change char of each case.

19-k command: Move cursor up in command mode.

Before k mode:

After k command:

20-j command: Move cursor down in command mode

Before:

After j command:

21-h command: This command move cursor left in command mode

Before:

After h command i.e left:

22-l command: This command move cursor in right direction.

Before:

After h command i.e right:

Linux vi commands
Linux vi commands

23- w command : This command saves the file but keep it open

24-shift+zz and: wq command: These both commands save the file and quit.

:q command: This command quit without saving.

Linux vi commands

Conclusion : Hence we have done the study of vi-editor with its basic commands.

About Ashishkumar Vishwakarma

I am Ashish- a Developer live in Mumbai.

View all posts by Ashishkumar Vishwakarma →

One Comment on “Command of the VI-Editor and implement them.”

  1. Hello there, You have done a fantastic job. I’ll certainly digg it and for my part recommend to my friends. I’m sure they’ll be benefited from this site.|

Leave a Reply