Vim is a powerful editor whose rich feature set and widespread availability makes it the editor of choice for many. Yet, beginners often find it difficult to save and quit files in Vim. We have prepared this guide to address this issue. You'll learn how easy it is to save or quit Vim files.

Save Files in Vim

You can save files using the write command. Use Vim's command mode to enter this command. If you're unfamiliar with different Vim modes, take a moment to go through our introductory guide on Vim basics.

Use the below command to write the current file after switching to the command mode.

        :w
    

You can also use the following.

        :write
    
Image showing how to save files in Vim

Quit Files in Vim

Use the following Vim command to quit editing the current file. Note that, Vim won't exit if you have unsaved changes in your file.

        :q
    

The below command does the same job.

        :quit
    

Save a File and Quit

You can save the current file and quit Vim anytime you want. Simply switch to the command mode and type the below command to save and quit vim.

        :wq
    
Image showing how to save and quit in Vim

You can also use the :x command. It works similar to :wq but only writes when you've made actual changes.

        :x
    

Quit a File Without Saving

If you don't want to save the progress, you can discard the changes altogether. Use the following Vim command to quit without saving changes.

        :q!
    
Image showing how to quit vim without saving

You can bookmark this Vim cheat sheet for quick access to essential vim commands.

Saving and Quitting Files in Vim

Being a modal editor, Vim is different than many popular Linux text editors. So, it's normal for beginners to feel overwhelmed at first. But once you master how to save and exit Vim files from the terminal, you'll become much more productive.