VIM is a free text editor, the possibilities of which largely exceed those of “ordinary editor”. However, there is one drawback, namely that the editor interface is not intuitive, so to work with it you need to spend some time to study the commands, hot keys, etc. When you first face VIM, you can easily get lost and not know how to do even simple things, for example how to exit it.
VIM editor exit commands
If you’re using text input mode, you must first press <ESC> to return to normal mode.
1 | ZQ // exit without saving |
or
1 | :q! // exit without saving |
1 | ZZ // save the file and exit (If the file is not modified, it will not be saved) |
or
1 | :wq // save the file and exit |
or
1 | :x // save the file and exit |
1 | :w <CR> g // save the file |
1 | :sav filename <CR> // “Save as” |
or
1 | :w filename <CR> // “Save as” |
1 | :w! <CR> // save the file. |
This command can help you if the file is opened in “read-only” mode (with -R option), if the file is locked by another user, if there are no such privileges, or there is another problem. If you try to save the file without “!”, a warning will be given.
1 | :w new_file <CR> |
Create a new file “new_file” and save the current contents. If the file already exists, a warning will be displayed. Then continue to work with the old file – newfile.txt
If there is a message that the disk has no free space when you try to save the file, you can go to the command shell and free up disk space by erasing unwanted files. To do this, use the command
1 | :sh <CR> // transition to command shell. |
Press CTRL-D or enter “exit” to return from the command shell to the editor
1 | :q <CR> // exit the editor. |
If the file has been modified, you won’t be able to do anything. In these cases, it is necessary to add “!” after the command:
1 | :q! <CR> // close the file without saving modifications |
1 | :qa! <CR> // close all files without saving modifications |
To cancel all modifications of the current session and return to the original version of the file, use the command
1 | :e! <CR> // cancel modifications of the current session. |