Apple - How to save and exit "nano .bash_profile" in Terminal?

No, :w is a /usr/bin/vi command. Use the combination control+x to exit. You will be prompted to save the file if you have made unsaved changes.


Nano is intended to be a bit friendlier / simpler to new users than vi/vim or emacs which both cater to more power users that have spent time learning how to use them effectively.

To get started in nano - look for commands along the bottom of the window when nano is open. (^ stands for the control key)

^X      (F2)            Close the current file buffer / Exit from nano
^O      (F3)            Write the current file to disk

Per Apple's Support Article:

  1. To save the file, press Control-O.
  2. At the filename prompt, press Enter.
  3. To exit, press Control-X.

If you want to save the changes you've made, press Control+ O. To exit nano, type Control+ X. If you ask nano to exit from a modified file, it will ask you if you want to save it. Just press N in case you don't, or Y in case you do. It will then ask you for a filename. Just type it in and press Enter.

If you accidentally confirmed that you want to save the file but you actually don't, you can always cancel by pressing Control+ Cwhen you're prompted for a filename.