Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to the Power Users community on Codidact!

Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.

How do I set UTF8 in a Vim modeline?

+3
−0

Occasionally someone* occasionally modifies one of the files I'm responsible for with an archaic tool that decides to convert the updated file to UTF-16 (probably lossless) or an even more archaic tool that converts the file to Latin1 (ISO-8859-1) (probably lossy).

Is there a Vim modeline I can put in these files so that the next time I edit and save the file with Vim, it will automatically convert the file back to UTF-8?

(My understanding is that converting to UTF-8 is always lossless, so it should be OK to do this automatically). (The help text for ":help encoding" specifically says that the "encoding" option cannot be used in a modeline. I'm hoping there's some other option that can be used in a modeline. Perhaps something related to fileencodings ? ). I need to convert the file back to UTF8 so that my version control tools can tell me what really changed -- both the desired updates from the tool and the undesired damage (if any) from the unwanted conversion to Latin1. Version control tools (incorrectly) tell me that the file is completely different on every line when comparing a UTF-16 file to the nearly identical text stored in version control (in UTF-8).

*(that someone may be me).

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

3 comment threads

Muss es in Vim sein? Könntest du nicht ein Skript erstellen das alle Dateien im Projekt prüft und aut... (3 comments)
fileencoding vs encoding (1 comment)
Autocmd (1 comment)

0 answers

Sign up to answer this question »