Describe the bug
In gvim for Windows, setting set file contents encoding to UTF-8 or UTF-16 makes file name incorrect, if the name contains e.g. Cyrillic letters.
To Reproduce
Create a file with Cyrillic letters in name or path (e.g. "мойфайл.txt"). Open the file in Notepad, enter some Cyrillic letters (e.g. "текст", save the file and close Notepad.
Open the file with gvim. See that the letters are displayed incorrectly ("текст", i.e. UTF characters displayed in some 8-bit encoding, maybe CP1251), but the file name is displayed OK ("мойфайл.txt").
To fix the issue with text, enter the command "set encoding=utf-16", or "set encoding=utf-8" (same effect). See that the text is now displayed correctly, but file name is not ("...", character codes instead of Cyrillic letters). Modify the text and save the file. See that the file is saved under incorrect name ("ìîéôàéë.txt" or like that, looks like CP1251 translated to US-ASCII).
Expected behavior
Both text and filename are correct. I.e. changing text encoding does NOT change encoding of the file name.
It is necessary to edit "regular" text files under Windows, which have both UTF contents and UTF names.
Environment:
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
You should add set encoding=utf-8 in your .vimrc (or _vimrc), and also set fileencodings properly.
As Ken wrote, if you change 'encoding' while Vim already has some text in memory, including a file name, it may become invalid. Vim cannot convert all text it has when you change 'encoding'. Either change 'encoding' before doing anything, or after changing 'encoding' re-edit files and don't use buffer contents.
Closed #7879.