If you are new to editing files with Terminal programs such as VI, VIM, or Nano, then it could be difficult at first to understand how to exit a file that is being opened in edit mode.
Let us take a look at how to exit a file based on each editor type.
Table of Contents
Exit a file using Nano Editor
If you want to save changes and exit then press Control + Y
If you do not want to save changes and exit then press Control + N
If you do not want to exit the file and continue editing then press Control + C
The Nano editor is the most easy to use editor for the Terminal. If you have opened a file using nano command, then you can exit by pressing the Keys "Control + X"
If you have made no changes to the file, the application will exit and return to your bash/zsh shell prompt.

If you have made changes to the file, then when you press Control + X you will be asked a question,

Exit File using Vi/Vim
- Step 1: Press Escape key to get into the command mode.
- Step 2:
Vi/Vim is a more powerful and advanced text editor, it could be a bit difficult at first how to exit its file editing modes as compared to Nano.
You should return back to the terminal prompt.
Exit File when using less or more commands
If you are less or more command to view the file contents in the terminal, then simply press Q to return back to the Terminal prompt.
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!


Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!