On Sunday, May 13, 2012 3:10:33 AM UTC-5, Toddintr wrote:
> For the first time ever since I started using Vim, I lost a file. I had
> a modeline that specified an "encoding" setting for a Python script.
> Vim complained when opening the file. I googled for a solution, decided
> to try fileencoding instead of encoding. When saving the file, I saw
> some error/warning messages, but went ahead with a ZZ or w! (don't quiet
> remember). Result: File length of zero. (Had backups disabled.)
>
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?
--
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