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.

Comments on How do I set UTF8 in a Vim modeline?

Post

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 attention from curators or moderators?
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)
Muss es in Vim sein? Könntest du nicht ein Skript erstellen das alle Dateien im Projekt prüft und aut...
H_H‭ wrote 11 months ago

Muss es in Vim sein? Könntest du nicht ein Skript erstellen das alle Dateien im Projekt prüft und automatisch iconv anwendet, bei denen die UTF16 kodiert sind?

Vielleicht verstehe ich auch das Problem nicht ganz. Warum muss es genau in Vim sein? Ich meine du:

  1. Bearbeitest eine Datei A mit Programm B, Datei A ist nun UTF16 kodiert.
  2. Du willst diese Änderungen dem Versionskontrollprogramm übergeben, aber dieses sieht zu viele Änderungen (wegen der geänderten Kodierung).
  3. Hier öffnest du die Datei in Vim und willst das Vim die Kodierung zu UTF8 ändert. Warum genau? Wäre ein iconv-Aufruf nicht einfacher?
Quasímodo‭ wrote 11 months ago

Warum gehst du denn davon aus, dass der Fragender Deutsch spricht?

In any case it would be better to stick to English, as that's what most people can understand.

H_H‭ wrote 11 months ago

Wenn er es nicht kann soll er DeepL, Google Übersetzer, oder etwas ähnlich verwenden oder es lernen.

In any case it would be better to stick to English, as that's what most people can understand.

Nein.