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.
You can also use the following.
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.
The below command does the same job.
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.
You can also use the :x command. It works similar to :wq but only writes when you’ve made actual changes.
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.
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.