vi Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

The vi command is a powerful and versatile text editor found in Linux operating systems. It allows users to create, edit, and navigate through text files with various modes, commands, and shortcuts. In this article, we will cover the syntax, options, and examples of the vi command.

Linux vi Command Syntax

The syntax for the vi command is as follows:

Where:

  • options: Optional flags that alter the behavior of the vi command.
  • file: The name of the file to be edited or created.

vi Command Options:

  • -R: Opens the file in read-only mode, preventing any changes from being saved.
  • -c command: Executes the given command upon starting vi.
  • +n: Opens the file and places the cursor at line number n.
  • -r: Recovers a file after a crash, using the swap file.
Sharpen Your Fundamentals with Free Learning

Example Usages

  • Opening a file for editing:

    Explanation: Opens the 'example.txt' file in the vi editor. If the file does not exist, it will be created.

  • Opening a file and going to a specific line:

    Explanation: Opens the 'example.txt' file in the vi editor and positions the cursor at line 10.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Tips

  • Use 'i' to enter insert mode, 'ESC' to exit insert mode, and '' to save and quit the file.

  • Use 'h', 'j', 'k', and 'l' keys to move the cursor left, down, up, and right, respectively.

Advanced Use Cases of vi Command in Linux

  • Searching for a pattern in the file:

    Explanation: Searches for the specified pattern in the file. Press 'n' to jump to the next occurrence of the pattern.

  • Replacing all occurrences of a pattern:

    Explanation: Replaces all occurrences of the 'old' pattern with the 'new' pattern in the entire file.

  • Undo and redo changes:

    Explanation: Press 'u' to undo the last change. Press 'Ctrl+r' to redo the change.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • The vi command is a powerful text editor in Linux operating systems.

  • vi offers a wide range of options, commands, and shortcuts for efficient text editing.

  • Advanced usages include searching for patterns, replacing patterns, and undoing and redoing changes.