Chapter 3. Vim Editor

Normal Mode (7) – Save and Exit

Normal Mode (7) – Save and Exit
Tag:

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

IdeaNote: Quit

When you quit with the :q command even though you made some changes, you'll encounter the error like below.

Command Line - RESPONSE
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.

Command Line - INTERACTIVE
:q!

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

IdeaNote: Quit

When you quit with the :q command even though you made some changes, you'll encounter the error like below.

Command Line - RESPONSE
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.

Command Line - INTERACTIVE
:q!
Tag: