The mysterious read-only vim file

My standard text editor is Vim (now 8.X). When Vim is set up correctly for my language environment, it is a reliable workhorse that does pretty much what I want.

However, there is one glitch I have run across more than once: I open a text file in the usual way, and Vim insists that it is read only, despite any and all tricks I try to turn back into a regular writeable file.

Today, however, I noticed that the read-only file had what Vim calls an “illegal byte” in it. My understand is that this is a byte appearing in a string which Vim is unable to interpret using the fileencoding it is set for. People who mess with Chinese in more than once flavor (Big-5, GB, Hong Kong etc) can easily run into this situation. I noticed this because “illegal byte” appeared in Vim’s status line, including the line number. Despite the hint, however, “illegal bytes” are sometimes hard to spot: look for a question mark where there shouldn’t be one.

It seems that an illegal byte is at least one cause for a file to persistently open in read-only mode. Get rid of the cursed thing and save the file using -w! This resolved my problem for several files.

This entry was posted in Software. Bookmark the permalink.