To exit Vim text editor, you can follow these steps:
- Press the Esc key to ensure you are in the “Normal” mode in Vim.
- Type
:q
(colon followed by “q”) and press Enter to quit Vim if you have not made any changes to the file. This will exit Vim and return you to the command line. - If you have made changes to the file and want to save them before exiting, type
:wq
(colon followed by “wq”) and press Enter. This command will save the changes and exit Vim. - If you made changes but no longer want to save them, type
:q!
(colon followed by “q” and exclamation mark) and press Enter. This command will force quit Vim without saving the changes.
Remember that Vim has different modes, such as “Normal” mode, “Insert” mode, and “Command-line” mode. To ensure you are in the correct mode, press the Esc key to switch to “Normal” mode before entering the command to exit Vim.Also read list of important vim commands.