How to Save a File in Vi / Vim Editor & Quit (2024)

Introduction

Vim (Vi IMproved) is an open-source text editor for Unix and Linux systems. It is a powerful and stable tool for editing and writing text, both in the command-line interface and as an independent application in a GUI.

Take the first step in learning Vim with the basic save and exit commands. Follow this guide and learn how to save a file in Vi/Vim and exit the editor.

How to Save a File in Vi / Vim Editor & Quit (1)

Prerequisites

  • A system running Linux.
  • A user with sudo privileges.
  • Access to a terminal/command line.
  • Vim installed (alternatively, use the default Vi).

Using Vim Modes

When Vim launches, files are opened in command mode by default. This means that you can move around and edit the file, but cannot insert new text.

All alphanumeric keys in this mode are equal to commands, and pressing them will not display their value on the screen. For example, pressing the letter w will move the cursor one word forward.

To type text, you must be in insert mode. To switch to insert mode, press the i key. Now you can type text into a file.

To switch back to command mode, press the Esc button.

How to Save Changes in Vim

Vim offers different commands to save changes to a file, depending on whether you need to exit the text editor or not. Below are examples demonstrating how to save and exit, save without exiting, and exit without saving.

Start by opening a new text file using Vim:

vim example_file.txt

Next, press i to enter insert mode and add some text.

Vim Save and Quit Command

To save a file and exit Vim, do the following:

1. Switch to command mode by pressing the Esc key.

2. Press : (colon) to open the prompt bar in the bottom left corner of the window.

3. Type x after the colon and hit Enter. This will save the changes and exit.

How to Save a File in Vi / Vim Editor & Quit (2)

Alternatively, a command that will also save a file and exit the text editor is:

:wq

In which case the w stands for write (save) and q stands for quit.

How to Save a File in Vi / Vim Without Exiting

To save a file without exiting in Vim:

1. Switch to command mode by pressing the Esc key.

2. Type : (colon). This will open the prompt bar in the bottom left corner of the window.

How to Save a File in Vi / Vim Editor & Quit (3)

3. Type w after the colon and hit Enter. This will save in Vim the changes made to the file, without exiting.

You can also rename an existing file by adding the new name after the commands.

:w [newfilename]

In the picture below, we renamed the existing example1.txt into newexample.

How to Save a File in Vi / Vim Editor & Quit (4)

Exit Without Saving Changes in Vi / Vim

To exit Vim without saving changes:

1. Switch to command mode by pressing the Esc key.

2. Press : (colon) to open the prompt bar in the bottom left corner of the window.

3. Type q! after the colon and hit Enter to exit without saving the changes.

How to Save a File in Vi / Vim Editor & Quit (5)

The q! quits the text editor.

Conclusion

This article explained how to save files in Vi / Vim, with multiple command options.

The more comfortable you feel using keyboard shortcuts, the more you will understand why Vim earned its worldwide reputation. Next learn how to copy and paste in Vim, and how to go to the end of the file!

How to Save a File in Vi / Vim Editor & Quit (2024)
Top Articles
Berufsbild Content Marketing Manager: Aufgaben, Gehalt, Tipps | OMT 💙
What is SAP HR? | Introduction to SAP HCM
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Toyota Campers For Sale Craigslist
Unlocking the Enigmatic Tonicamille: A Journey from Small Town to Social Media Stardom
Ncaaf Reference
Globe Position Fault Litter Robot
Crusader Kings 3 Workshop
Robert Malone é o inventor da vacina mRNA e está certo sobre vacinação de crianças #boato
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Merrill Bechtelar CPA

Last Updated:

Views: 5898

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Merrill Bechtelar CPA

Birthday: 1996-05-19

Address: Apt. 114 873 White Lodge, Libbyfurt, CA 93006

Phone: +5983010455207

Job: Legacy Representative

Hobby: Blacksmithing, Urban exploration, Sudoku, Slacklining, Creative writing, Community, Letterboxing

Introduction: My name is Merrill Bechtelar CPA, I am a clean, agreeable, glorious, magnificent, witty, enchanting, comfortable person who loves writing and wants to share my knowledge and understanding with you.