EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Unix Tutorial VI Editor in Unix
 

VI Editor in Unix

Priya Pedamkar
Article byPriya Pedamkar

Updated May 31, 2023

VI Editor in Unix

 

 

Introduction to VI Editor in Unix

VI Editor is a kind of text editor that is available in the UNIX operating system, and it is the default editor that comes with the UNIX operating system, which is used to create a new file or editing an existing file and offering rich, user-friendly features, which are available in almost all the UNIX distribution systems. The capabilities incorporated into the tool, which opens the door to the endless possibilities used to edit a file, renders the tool a unique position among all the editors, including pico, nano, vile, in UNIX, is termed as VI Editor in the UNIX operating system.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Modes of VI Editor in Unix

To have an easy working experience with the VI editor, we need to understand the different modes of operations of the VI editor.

They are divided into three main parts:

  1. Command Mode
  2. Insert Mode
  3. Escape Mode

1. Command Mode

Command Mode is the first screen of the VI editor. It is case sensitive. Any character that is typed during this mode is treated as a command. These character are not visible on the window. We can cut, copy, paste, or delete a piece of text or even move through the file in this mode

[ESC] used to enter the Command Mode from another mode (Insert Mode)

2. Insert Mode

We can easily move from Command mode à Insert mode by pressing the ‘i’ or ‘Insert’ key from the keyboard. Characters typed in this mode are treated as input and add text to your file

Pressing ESC will take you from Insert Mode -> Command Mode

3. Escape Mode

Press [:] to move to escape mode. This mode is used to save the files & execution of the commands.

 Escape Mode

Fig : Blue Box Represents the various modes on the VI editor

Green Box Represents the keys/commands to move from one mode to another

Syntax of VI Editor in Unix

VI Editor has various features for easy editing in the Linux environment. The basic purpose of highlighting these commands and their syntax is to familiarize oneself with the availability of various features. We do not need to mug up all the commands. You can refer to the main pages for the details of the commands and the options.

Now let us get going on the same:

1. Open/ Create a File

This will create a file with the name ‘filename’ or open the file with the name ‘filename’ if it already exists.

Vi Filename

Output:

VI Editor

Note: all the line starts with a tilde (~) sign which represents the unused lines

2. Read-Only Mode

To open the file in read-only mode, use the following:

 vi R

Output: At the bottom of the file, you will see ‘Readonly.’

 vi editor in unix

3. Moving out of a file

:q Quit out of a file
:q! Quit the file without saving the changes
:w Save the content of the editor
:wq Save the changes and quit the editor (*Combing the commands: q &: w)
ZZ In command mode, this works similarly to wq

4. Rename a File

:w newFileName – This will rename the file you are currently working into ‘new filename’. A command is used in Escape Mode.

5. Move within a file

To move around in a file without actually editing the content, we must be in Command mode and keep the below commands handy.

h Moves the cursor left one character position
l Moves the cursor right to one character position
k Moves the cursor one line up
j Moves the cursor one line down

**Arrows can help you remember the functionality of that key. It has no other significance.

Move within a file

Keyboard keys for movements within the editor.

Note: Number at the beginning is equal to the number of times you want the action to occur

Example: 2j will move the cursor two lines down from the current cursor location\

6. Inserting or Adding Text

Following is the command used to put the editor in the insert mode.

Once the ESC is pressed, it will take the editor back to command mode.

i Insert text before the cursor
I Insert at the beginning of the current line
a Append after the cursor
A Append at the end of the current line
o Open & places the text in a new line below the current line
O Open & places the text in a new line above the current line

7. Searching the Text

Similar to the find & replace command in the windows editor, we also have certain Search & replace commands available in the VI editor.

/string Search the mentioned ‘String’ in the forward direction
?string Search the mentioned ‘String’ in the backward direction
n Move to the next available position of the searched string
N Move to the next available position of the searched string in the opposite direction

8. Determining the Line Number

Having the line number is very useful sometimes while editing the file. These commands are used in Escape Mode that is after pressing the [:] key

:.= Line Number of the current line
:= Gives the total number of lines
^g Gives the line number along with the total number of lines in a file at the bottom of the screen

9. Cutting & Pasting Text

These commands allow you to copy and paste the text

yy Copy (yank, cut) the current line into the buffer
Nyy or yNy Copy ‘N’ lines along with the current line into the buffer
p Paste / Put the lines in the buffer into the text after the current line

Conclusion

Due to the availability of the VI editor in all the Linux environment, learning the VI editor can be really useful. It can help us in creating and editing the scripts. We must be familiar with the commands along with the particular mode in which that command is to be used. This is not the end of the options available in VI editor keep exploring as the challenge comes your way.

Recommended Articles

We hope that this EDUCBA information on “VI Editor in Unix” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. Uses of Unix
  2. Functions in Unix
  3. Array in Unix
  4. Crontab in Unix

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW