17

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?

laurent
  • 284

2 Answers2

15

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.

Yaron
  • 13,173
  • 4
    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 – cutrightjm Jun 06 '17 at 13:31
  • 1
    That's an interesting prompt they use. – JAB Jun 06 '17 at 19:01
  • @cutrightjm - thanks for the comment, I've updated my answer. – Yaron Jun 06 '17 at 19:21
  • @Yaron Maybe add info on how to exit without save, discarding the changes? – Danijel Dec 03 '21 at 08:49
  • 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. – Danijel Dec 03 '21 at 10:21
0

As of 2024, add set saveonexit to your ~/.nanorc (.nanorc in your user dir for Windows users like me)

https://www.nano-editor.org/dist/latest/nano.html#Nanorc-Files