How to exit vi editing mode on Linux?

There are several ways to exit editing mode in the vi editor.

  1. Press the Esc key on the keyboard, then type the command :q, and then press Enter. This will exit the editor, but only if no changes have been made.
  2. If you made changes during the editing process, you can press the Esc key, then type the command :q! and press Enter. This will force quit the editor and not save any changes.
  3. To save your changes and exit the editor, press the Esc key, followed by typing :wq and then hitting the Enter key. This will save your changes and exit the editor.
  4. To save changes without exiting the editor immediately, press the Esc key, then type :w command, and finally press Enter. This will save the changes and allow you to continue editing.

Please note that the above commands are entered in normal mode, not in edit mode. Before entering these commands, make sure to press the Esc key to ensure you are in normal mode.

bannerAds