Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
How to Delete Multiple Lines in vim Editor in Linux
Next article icon

How to Edit Multiple Files in Vi Editor in Linux

Last Updated : 02 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Vi, short for "visual editor," is a powerful and ubiquitous text editor in the Linux ecosystem. Among its many features, one of the most useful is its capability to edit multiple files simultaneously. This ability streamlines the editing process, especially when dealing with projects that span multiple files. In this article, we'll delve into the techniques and commands required to efficiently edit multiple files in Vi editor on Linux.

Understanding Vi's Buffers:

Before diving into editing multiple files, it's essential to understand Vi's concept of buffers. A buffer in Vi is a temporary storage area where text is held during editing. Each file being edited occupies one buffer, and Vi can handle multiple buffers simultaneously.

Opening Multiple Files:

To open multiple files in Vi simultaneously, you can provide the filenames as arguments when invoking Vi from the command line.

For example:

vi example.txt example2.txt
editing multiple files in vi editor
editing multiple files in vi editor

This command will open both "example.txt" and "example2.txt" in separate buffers within the Vi editor.

Navigating Between Buffers:

Once you have multiple files open in Vi, navigating between buffers is crucial. Vi offers various commands for efficient buffer management:

  • :n: Move to the next buffer.
  • :N: Move to the previous buffer.
  • :buffers or :ls: List all open buffers.
  • :buffer <number> or :b <number>: Switch to a specific buffer by its number.
  • Ctrl + ^: Toggle between the current and previous buffer.

Editing Multiple Files:

Editing multiple files simultaneously involves switching between buffers and making modifications as needed. Here's a step-by-step guide:

  • Open Vi with multiple files, as explained earlier.
  • Use the buffer navigation commands to switch between files.
  • Make modifications in each buffer as required using Vi's editing commands.
  • Save changes to each file individually by switching to its buffer and using the :w command followed by the filename, or save changes to all buffers using :wa.

Example:

Let's consider a scenario where we have two files, "example.txt" and "example2.txt," and we want to edit them simultaneously in Vi.

Open Vi with both files:

vi example.txt example2.txt
editing two files in vi editor
editing two files in vi editor


  • Navigate to the buffer containing "example.txt" using :buffer 1 or Ctrl + ^ if it's the second buffer.
  • Make necessary edits in "example.txt" using Vi's editing commands.
  • Save changes in "example.txt" using :w.
  • Switch to the buffer containing "example2.txt" using :buffer 2 or Ctrl + ^ if it's the first buffer.
  • Make edits in "example2.txt" and save changes similarly.

Conclusion:

Mastering Vi's capability to edit multiple files simultaneously is a valuable skill for Linux users, especially programmers and system administrators. By understanding Vi's buffers and utilizing its buffer management commands effectively, users can streamline their editing workflows and boost productivity when working with multiple files. Practice and familiarity with Vi's commands are key to becoming proficient in editing multiple files efficiently.


Next Article
How to Delete Multiple Lines in vim Editor in Linux

V

vintymp6pl
Improve
Article Tags :
  • Linux-Unix

Similar Reads

  • How to Edit Multiple Files in Vim Editor in Linux
    Vim, short for "Vi Improved," is a highly configurable and powerful text editor built upon the foundation of Vi. Like its predecessor, Vim offers robust support for editing multiple files simultaneously, making it an indispensable tool for developers, system administrators, and anyone working extens
    4 min read
  • How to Delete Multiple Lines in vim Editor in Linux
    Vim Editor is a Linux terminal-based editor that has various advanced features for editing, but due to its terminal behavior, it is quite difficult to handle some of the operations in Vim. While making a text file, we often need to delete some unwanted lines. If the document consists of more unwante
    7 min read
  • How to comment multiple lines in Vim Editor in Linux
    Vim Editor in Linux is one of the most used text editors for writing scripts, codes, and textual data. There are different types of features offered by the Vim Editor through which we can create the text more comfortably. Various types of shortcuts, modes, and bindings are available in Vim Editor. W
    5 min read
  • How to Delete Multiple Lines in Vi editor
    Linux was developed by Linus Torvalds in 1991 as a hobby project. It is an open-source (source code that can be used by anyone freely) kernel that is most popular and widely used in the industry as well as in personal systems. There are various operating systems based on the Linux kernel, some of th
    5 min read
  • Edit Multiple Lines in Vi edtor
    In this article, we will cover how to edit multiple lines in vi editor. First, we look at what Linux and VI editors followed by editing multiple lines in the vi editor with examples and then we will look how to delete multiple lines in the vi editor. LinuxLinux is a kernel for operating system(OS) i
    4 min read
  • how to Enter in Editing Mode in VI Editor
    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 esse
    4 min read
  • How to undo in Vim editor in Linux
    Vim (short for Vi Improvised) is a popular text editor mainly used in Linux and Unix-based operating systems but due to having a CLI (command line interface), it might be difficult for new users to make use of basic features such as undo in Vim. So in this article, we will learn different ways and t
    3 min read
  • How to Display Line Number in vim editor in Linux
    In this article, we will cover how to make the Vim editor display or hide line numbers. First, we look at what Linux and VIM editors and why we use them, are its features and how can we use them Follow the basic VIM editor guide to get familiar with the editor followed by various options to make the
    5 min read
  • How to Hide Line Numbers in Vim Editor
    In this article, we will cover how to hide line numbers in the Vim editor. First, we look at what Linux and VIM editors and why we use them, what are its features and how can we use them followed by various options to make the Vim editor hide line numbers and how we can change the default settings o
    3 min read
  • How to Edit Text Files in Linux: Proven 3 Methods
    Need to tweak a file in Linux but not sure where to start? Editing text files in Linux is a handy skill that can help you fix settings, write scripts, or just note down notes all from your keyboard. This blog is here to help you get started, even if you’re new to Linux. We’ll show you simple ways to
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences