Why does nano editor prompt me to "save changes" when nothing is changed, and can I change this behavior?

0

When I open a file in nano, if I add a character then remove it, so the file is exactly the same as it was initially, upon close I'm prompted to "save changes" and I have to type N for no. Is there any way to change this? It would be nice to not have it prompt unless changes have actually been made.

Vim seems to follow the pattern I prefer, but maybe that's just my impression because Vim's separate command mode/edit modes prevent the tendency to add & then remove whitespace (ie. when considering whether to edit some code before moving on to another file)

Nathan Smith

Posted 2017-09-24T01:34:03.523

Reputation: 103

1You did make changes. You added a character and you removed a character. – Appleoddity – 2017-09-24T01:56:50.970

that's true, but I never made changes to the file (other than modification time). I'm pretty sure that it's not saving a history of changes to jump in & undo things from where I left off or anything. personally, i'd find the behavior of prompting a save only for a change to the file more consistent & preferable ux. Should I edit Q? to make it clearer? – Nathan Smith – 2017-09-24T03:52:22.900

No it's clear. But the point is you DID make a change. It's seeing a change and flagging the need to save. It's not considering you are putting the file back to original. This is how almost every program and UI works. Even when making config setting changes. Changing an option and then changing it back enables the "Apply" button. Just normal behavior. Try the undo feature like suggested in the answer. – Appleoddity – 2017-09-24T12:21:24.050

Yeah, I suppose the feature I want would be a bit of trouble to add in, because it would require computing a diff upon close, instead of just having a boolean modified flag that's set on once you've made changes. I thought of forking the git repo & making my own version, but making that a priority would be hardcore procrastination on my part lol. Anyway, thanks for your feedback – Nathan Smith – 2017-09-24T21:13:27.487

Answers

0

Nano is not constantly comparing your file to the original one in case it detects something changed, rather, it just keeps track on changes to the buffer and since there are two inputs (a char and a del char), it will detect a change. Try using the undo command which actually goes a step back on the edit history if this is an issue for you.

arielnmz

Posted 2017-09-24T01:34:03.523

Reputation: 2 960

good point about the undo command. I just looked it up, nano says it's M-U; after a little digging I found that means Alt+U on my setup – Nathan Smith – 2017-09-24T21:22:25.290