My point: I *LOVE* Vim. However, this sort of design decision is unacceptable. It seems to be a design decision because it was not a bug or a crash.
My two-cents' worth.
Todd
First of all, not encoding nor fileencoding will work on modelines because the file was already loaded. See ':h encoding' and ':h fileencoding' for that.
In my opinion, there is no bad design. You disabled write backups. That is the way Vim keeps your original file safe.
Sorry for your lost.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
On May 13, 2012 7:53 AM, "Toddintr" <amsa...@gmail.com> wrote:
>
> WARNING: Original file may be lost or damaged
> don't quit the editor until the file is successfully written! (In orange)
> Press ENTER or type command to continue (in green)
>
> What I meant by bad design decision: When the conversion fails, why not simply restore the previous buffer? The unacceptable behaviour is that even if I do a "q!", I still lose the file.
>
So you get a warning about loosing data if you quit, quit anyway, and complain that you lost data? Interesting.
--
On May 13, 2012 8:53 AM, "A.M. Sabuncu" <amsa...@gmail.com> wrote:
>
> I never read the warning. Much like no one reads the manual. I never thought I would *ever* encounter anything with Vim that would lead to losing a file.
>
Ok, I don't run windows so when I get a message I *read* it. If the message happens to repeat, I figure out how to disable it.
You've never encountered anything in VI that makes you loose a file? Huh, I do it all the time. Process: vim somefile, start typing, ah I don't like that filename, :q! and that data is gone. I don't even get a warning.
/me omits sarcastic thoughts
Also, you use VI without reading the manual? That's impressive.
On May 13, 2012 9:00 AM, "Toddintr" <amsa...@gmail.com> wrote:
>
> Also, I did not think that q! would result in any change to the file since the last write. This is against user expectations.
>
If this is true, this is quite odd...
> Process: vim somefile, start typing, ah I don't like that filename, :q! and
> that data is gone. I don't even get a warning.
I see. I was not aware that you are a beginner, in grammar school.
> The copy is still in the buffer. It is valid. The problem is, that
> writing failed because converting to your desired fileencoding failed.
>
> The problem is probably, that Vim opened the file for writing, truncated
> it and when writing noticed the error. But at this time, the old
> contents are already gone.
This explains the current way Vim handles the process. It does not have to be this way. This is what I mean by bad design. Loss of data should only happen in an unforeseen situation (a crash, etc). If you are truncating a file, especially prior to a conversion that can fail, you should take extra precautions.
> Besides, big red warning messages should always be read, because they
> don't usually happen.
This is the "Soviet" style of user interface design: it dictates *how* people should use a product, and ignores the real-life scenarios. (Much like the opening line of your message - "Please don't top poste and please wrap to 75 columns.") If I *really* care about customer feedback, I don't care how the customer sends me feedback / it can be top-posted, bottom-posted, sideways. What is important is that I am getting feedback about the worst thing that can happen w/ my product.
I am done w/ this issue, thank you all for your responses.
> Ah, but Vim is only _largely_ foolproof. It is not proof against
> deliberate self harm. It might be worth reading enough to understand
> that "q!" is "Forced Quit", and so you didn't "lose" a file, but
> deliberately discarded it by choice. The "Forced Quit" is quite useful
> when used, if not intelligently, then at least consciously.
>
> However, a lesson learnt the hard way is usually a lesson well learned.
Typical engineer mentality, lack of any experience with real-life scenarios.
Furthermore, you are wrong. The q! should take me to the prior state of the file, which was an intact buffer before the conversion attempt. Prior to the q!, I did not do a 1,$d.
You are a good example of this entire community - looking down on others with snide remarks. Good luck to you. (Thank God there is stackoverflow where such bulls**t is not tolerated.)
Later you say you used :q! and lost data. Here I see you actually saved the
file with a "force save and quit" and lost data. That's a big difference,
but I admit somewhat irrelevant to the discussion, which has gotten quite
out of hand. I understand you're frustrated. Let's all settle down, we may
have a real issue here (which may have been fixed since 7.3.0, of course).
Regardless, YOU (the original poster) are not going to get anywhere by
outright insulting long-time and very respected members of the Vim
community.
I think I gather from later posts that the problem occurs when you set
'encoding' but not 'fileencoding' from a modeline.
:help 'encoding' says:
This option cannot be set from a |modeline|. It would most likely
corrupt the text.
:help changed-7.3 indicates this protection was added sometime between 7.2
and 7.3, but I don't see it in the changelog for 7.2 patches, so apparently
sometime in the run-up for 7.3 somebody realized setting Vim's internal
encoding via modeline is a very bad idea and fixed this issue. However, your
followup post with version information indicates that you should not have
been able to set the encoding via modeline.
On my Windows Vim, if I successfully save a file with a modeline containing
"encoding=cp857", I get an error when loading the file:
E520: Not allowed in a madeline: encoding=cp857
Setting fileencoding in a modeline, by the way, will not do what you
probably intend. A modeline is processed only AFTER a file is read into Vim,
so setting it in the modeline can only affect how the file is written, it
will NOT affect how Vim interprets the bytes in the file while reading. To
do this, you would need to properly set 'fileencodings' (note the final 's'
in the option name) to detect your desired encoding, PRIOR to reading the
file. A BufReadPre autocmd is a good place to do this, or just have it
always set properly. Another option, if you know the file's encoding, is to
use a ++enc=cp857 argument when editing the file, e.g.
:edit ++enc=cp857 myfile.txt
Also see the AutoFenc plugin:
http://www.vim.org/scripts/script.php?script_id=2721
Anyway, that was slightly off topic. I tried reproducing the error with your
example file, and could not. No matter what I did, without changing text
within the buffer, I was unable to wind up with an empty file by saving
and/or quitting, with or without a !. :wq! doesn't even work for me with a
character in the file invalid for the current 'fileencoding' (e.g. when I
load the file containing the undotted 'i' in your example, without Vim
detecting the correct encoding, and then try to write in the correct
encoding without correcting the character first), it fails to write and
fails to quit, since Vim doesn't know HOW to write. Can you give the exact
commands you execute to result in an empty file? And, what is the initial
value of 'encoding'? And your 'fileencodings' option? Finally, this is
possibly a stupid question, but are you sure you lost your data in the 7.3.0
version of Vim you say you are using? Maybe you accidentally loaded the file
in an older version you still have installed alongside somewhere?
What if, right here, Vim were to check the buffer contents to see if all characters in the file can actually be converted to the new fenc setting, and issue a warning if not? It's not something Vim does currently...but I don't see why it couldn't. And I'd like to know if I do something stupid *when I do it*, not when I try to write the file and end up killing my file.
> :set nobackup nowritebackup
> :w
>
> 3. Observe message which you have probably never seen before:
> "bad.tmp" E513: write error, conversion failed
> (make 'fenc' empty to override)
> WARNING: Original file may be lost or damaged
> don't quit the editor until the file is successfully written!
>
> 4. Panic and do what has always worked in the past:
> :q!
>
Right, to me, :q! means "oh crap I didn't mean to do that, GET ME OUT!"
Since the error only occurs if 'backup' and 'writebackup' are both off, maybe we could only do the "dry run" conversion in this situation? I.e., if either 'backup' or 'writebackup' are set, do what Vim has always done; but if neither are set, do the extra check first. We could even put a nice notice in :help 'writebackup' saying "if this option is off, writing the file will take longer due to extra safety checks" to discourage turning it off in the first place.
This sounds sane.
From Christian's test data, it looked like the slow-down was on the order of a few seconds for a write of a big file. I think that would be a small price to pay to know that the entire content of your file isn't going to be lost because Vim decided it could not modify them. I don't consider it a penalty. I consider it giving users some of the security of 'writebackup' even if they don't have it turned on.
> Or would you force us to reinstate it so as not to be penalized..?
>
> Aha... you turned off backup and writebackup.. you wicked little
> so-and-so.. You seriously thought you were going get away with it..?
>
It's risky, but it's also a valid use scenario, so that's why I want to see the file contents protected against being cleared for no good reason, even if the option is turned off.
I don't think it's clear at all. The help for 'writebackup' gives no indication that this option is important to leave on to prevent losing not just your edits in progress, but the entire file you're editing. This is especially surprising when the write error has nothing to do with the ability to write to the filesystem, only with Vim's ability to convert characters between encodings. Additionally, it's not just a matter of 'writebackup'. The 'backupskip' option prevents 'writebackup' from taking effect if it matches. So if a user is editing a file in the 'backupskip' pattern, potentially in a directory covered by this pattern BY DEFAULT, like /tmp, they risk losing data.
I don't think that default Vim settings should ever let Vim delete an entire file without being asked to do so.
At least this thread prompted me to double-check and make sure 'writebackup' is safely set on my system :-)
But, this way, how can Vim rollback if the conversion fails? Undoing everything in reverse order? IMHO, the 'writebackup' option should be ignored when a character encoding conversion is needed. Warning the user when that fails.