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.
Related videos on Youtube
Author by
laurent
Updated on September 18, 2022Comments
-
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 almost 7 yearsThe correct answer is: use vim! 😁
-
hildred almost 7 yearsIf there is an editor you prefer, setting the EDITOR variable will stop most instances of automatic invocation of nano, ie sudo.
-
-
cutrightjm almost 7 yearsGood 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 almost 7 yearsThat's an interesting prompt they use.
-
Yaron almost 7 years@cutrightjm - thanks for the comment, I've updated my answer.
-
Danijel over 2 years@Yaron Maybe add info on how to exit without save, discarding the changes?
-
Danijel over 2 yearsThe 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.