Open In App

how to Enter in Editing Mode in VI Editor

Last Updated : 02 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The Vi editor, short for “Visual Editor,” is a powerful and widely used text editor in the Unix and Linux operating systems. Vi offers various modes for text manipulation, including command mode, insert mode, and visual mode. In this article, we will focus on entering the editing mode, which is essential for making changes to your text files in Vi.

Entering the editing mode in VI:

Follow the below steps to enter the editing mode in vi

Step 1: Open a File in Vi

To start editing a file with Vi, open your terminal.

Type the following command: vi filename, replacing “filename” with the name of the file you want to edit. If the file doesn’t exist, Vi will create a new one with the provided name.

vi filename

Replace “filename” with the name of the file you want to edit. If the file does not exist, Vi will create a new one with the provided name.

Step 2: Navigate to Command Mode

When you open a file in Vi, you start in the command mode. In this mode, you can issue commands to navigate, save, and manipulate text. To ensure you are in command mode, press the Esc key. This step is crucial because you cannot enter text in other modes.

2023-09-21-00_16_39-A-Beginner's-Guide-to-Editing-Text-Files-With-Vi---Brave

Step 3: Enter Insert Mode

To enter insert mode, which allows you to add or modify text, press one of the following keys while in command mode:

Option

Description

i

Start inserting text before the current cursor position.

I

Start inserting text at the beginning of the current line.

a

Start inserting text after the current cursor position.

A

Start inserting text at the end of the current line.

o

Open a new line below the current line and enter insert mode.

O

Open a new line above the current line and enter insert mode.

2023-09-21-00_17_46-A-Beginner's-Guide-to-Editing-Text-Files-With-Vi---Brave

Step 4: Editing Your Text

Once you are in insert mode, you can freely type and edit your text. Make the necessary changes, additions, or deletions as required.

2023-09-21-00_19_23-A-Beginner's-Guide-to-Editing-Text-Files-With-Vi---Brave

Step 5: Return to Command Mode

After you have made your edits, press the Esc key to return to command mode. This step is vital because it allows you to save or exit the file.

Step 6: Save and Exit

To save your changes and exit Vi, use the following command in command mode:

:wq

2023-09-21-00_22_17-A-Beginner's-Guide-to-Editing-Text-Files-With-Vi---Brave

You will not be able to quit if you do not use “!” .

2023-09-21-00_23_43-A-Beginner's-Guide-to-Editing-Text-Files-With-Vi---Brave

Step 7: Discard Changes and Exit

If you made changes but wish to discard them and exit Vi, use the following command in command mode:

:q!

Conclusion

In conclusion, mastering the Vi text editor’s editing mode is a valuable skill for anyone working in Unix and Linux environments. By following these steps, you can seamlessly transition between modes, insert and edit text with precision, and efficiently manage your text files. As you practice and become more familiar with Vi’s commands, you’ll gain confidence in your ability to navigate and manipulate text swiftly and effectively. Whether you’re editing code, configuring files, or creating documents, Vi’s versatility and power are at your fingertips. So, embrace the learning process, and happy editing!



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads