How to exit nano and save to current file automatically?

11,427

According to Nano manual

You can configure ~/.nanorc to Save automatically on exit, don't prompt

($:~)=> nano -w ~/.nanorc 

# Save automatically on exit, don't prompt 
set tempfile 

Note: as @cutrightjm commented - the above setting can cause major problems in configurations if you are not careful and modify files and auto-save on exit.

Share:
11,427

Related videos on Youtube

laurent
Author by

laurent

Updated on September 18, 2022

Comments

  • laurent
    laurent over 1 year

    Whenever I close nano after having edited an existing file, it first asks if I'd like to save the file (which is fine), and then asks me to confirm the filename (so I press Enter, since literally 100% of the time I want to keep the same filename).

    So I'm wondering, is there any shortcut I can use to avoid having to confirm the filename every time?

    • Sparhawk
      Sparhawk almost 7 years
      The correct answer is: use vim! 😁
    • hildred
      hildred almost 7 years
      If there is an editor you prefer, setting the EDITOR variable will stop most instances of automatic invocation of nano, ie sudo.
  • cutrightjm
    cutrightjm almost 7 years
    Good suggestion, I would just exercise caution for newer users using this. Often times when I open up config files I'll accidentally put a character or two in it which can cause major problems in configurations if you are not careful
  • JAB
    JAB almost 7 years
    That's an interesting prompt they use.
  • Yaron
    Yaron almost 7 years
    @cutrightjm - thanks for the comment, I've updated my answer.
  • Danijel
    Danijel over 2 years
    @Yaron Maybe add info on how to exit without save, discarding the changes?
  • Danijel
    Danijel over 2 years
    The example config file with many (all?) the options is located at /usr/share/doc/nano/examples/sample.nanorc. Copy this file to your ~/.nanorc and start editing from there.