Normal Mode (7) – Save and Exit
![Saving and Exiting Vim Editor Normal Mode](/_next/image/?url=https%3A%2F%2Fstatic.d-libro.com%2F01-course-content-images%2F2011-10-Linux-Introduction%2F010-main-figures%2Fnormal-mode-7-save-and-exit-id201110030910.webp&w=1920&q=75)
To save changes and exit Vim, you can use the combination of w (write) and q (quit) command. ! is used to forcefully execute the command.
:w
: write (save) changes in the current file, but don't exit
:w
file_name : write (save) changes in a new file, but don't exit
:q
: quit (when there is no unsaved change)
:q!
: quit without saving changes
:wq
: write (save) changes in the current file and quit
:wq
file_name : write (save) changes in a new file and quit
Note: Quit
When you quit with the :q
command even though you made some changes, you'll encounter the error like below.
E37: No write since last change (add ! to override)
If you are sure that you want to exit Vim without saving the changes, run the :q!
command.
:q!