16

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?

2
  • 2
    The correct answer is: use vim! 😁
    – Sparhawk
    Jun 6 '17 at 13:16
  • If there is an editor you prefer, setting the EDITOR variable will stop most instances of automatic invocation of nano, ie sudo.
    – hildred
    Jun 6 '17 at 15:50
13

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.