[vim/vim] gvim for Windows: setting file contents encoding to UTF-8/16 makes filename incorrect (#7879)

248 views
Skip to first unread message

vbalashov

unread,
Feb 20, 2021, 11:02:46 AM2/20/21
to vim/vim, Subscribed

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:

  • Vim 8.12 or other 8.x
  • OS: Windows 10 Pro Russian x64, 18363 (looks like any Windows with UTF for text files and file names)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

K.Takata

unread,
Feb 20, 2021, 6:35:16 PM2/20/21
to vim/vim, Subscribed

You should add set encoding=utf-8 in your .vimrc (or _vimrc), and also set fileencodings properly.

Bram Moolenaar

unread,
Feb 21, 2021, 10:26:51 AM2/21/21
to vim/vim, Subscribed

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.

Bram Moolenaar

unread,
Feb 21, 2021, 10:26:54 AM2/21/21
to vim/vim, Subscribed

Closed #7879.

Reply all
Reply to author
Forward
0 new messages