How To Exit From Vim?

Vim is a popular command-line text editor. As a command-line editor, Vim is managed and used with commands and keyboard shortcuts. Exiting from vim can be done in different ways.

Exit By Saving Changes

As a command-line editor, Vim provides different ways of exit where one of them is exit by saving changes. You can use the following steps;

  • Press ESC key in order to change normal mode.
  • Use the :wq and then push Enter in order to save changes. The w is the write command which will write or save changes and then the q is used to exit or quit from vim.
Exit By Saving Changes

Another alternative is using a single command : x like below.

  • Press the ESC key in order to change normal mode.
  • Type and execute the : x command and press enter.

Also the ZZ command can be used to save and quit from the vim.

  • Press the ESC key in order to change normal mode.
  • Use the ZZ keyboard shortcut.

Alternatively the long form of these commands can be used with the following steps.

  • Press ESC key in order to change normal mode.
  • Type and execute the :write command to save changes.
  • Type and execute the :quit command exit.

Exit Without Saving Changes

You may want to exit from Vim but without saving the changes after last save or opening file. You can follow these steps without problem.

  • Press ESC key in order to change normal mode.
  • Type and execute the :q! command and press enter.

Save Specific Lines Changes and Quit

As command advenced command line text editor Vim provides a lot of features. For example by using the following command only specified lines can be saved and then exit from Vim.

  • Press ESC key in order to change normal mode.
  • Type and execute the :1,10wq command and press enter. This will save lines between 1 and 10.
READ  How To Save File and Quit In Vim/Vi?

Exit By Killing Vim Process

Leave a Comment