vim / vim

The official Vim repository
https://www.vim.org
Vim License
36.68k stars 5.47k forks source link

vim opens multiple files with garbled GETTEXT messages #15752

Open lsq opened 1 month ago

lsq commented 1 month ago

Steps to reproduce

Install vim from vim-win32-installer, then open MINGW64 zsh in windows terminal or open cmd.exe/powershell; command

vim.exe main.c os_win32.c
杩樻湁 2 杓枃浠 chop 瓑寰呯紪杈

The prompt message is garbled; if chcp 65001 is used before the above command, cmd.exe and mingw64 zsh.exe are normal (the power shell environment is still garbled, and the input/output encoding is set to utf-8 and is normal) How to set up normal output of messages that does not depend on specific environment

https://github.com/user-attachments/assets/7701a124-b1c1-4fbf-8e15-9c2328716d64

Expected behaviour

A normal message should say that 2 个文件等待编辑

Version of Vim

9.1.X

Environment

OS: Windows 10 x86_64 Shell: zsh 5.9(mingw64) / cmd.exe /power shell windows terminal :lang output image

Logs and stack traces

No response

chrisbra commented 1 month ago

Hm, I did not see the error message from your video. Does it happen with vim --clean? Is there a reason, you do not run in UTF-8 codepage by default? I think this is now the default for the new Windows terminal anyhow.

lsq commented 1 month ago

Hm, I did not see the error message from your video. Does it happen with vim --clean? Is there a reason, you do not run in UTF-8 codepage by default? I think this is now the default for the new Windows terminal anyhow.

set play ratio 0.25, at 11s show the error message. I test vim --clean with same problem using latest Windows Terminal Preview. In Windows Chinese the system's default codepage is cp936. But powshell uses CHCP 65001 to no effect, even though the actual CHCP output code is already 65001. However, utF-8 Chinese characters are still garbled. One solution is to turn on utf-8 in the language set by the system. This does work, but some old applications not support utf8, so there will be some problems. Is it possible to set the LANG environment variable in windows and vim to read the lang environment variable not system's codepage?

lsq commented 1 month ago

@chrisbra hi,after a week of testing, I found the reason: setlocale setting code (cp936) is inconsistent with bind_textdomain_codeset (VIMPACKAGE, 'utf-8'). Before terminal output, the utf-8 encoding is recognized as the encoding set by setlocale (p936), so it appears Garbled code, is it possible to fixe it by vim application without changing terminal settings?

chrisbra commented 1 month ago

is inconsistent with bind_textdomain_codeset (VIMPACKAGE, 'utf-8')

Where do you have set? And isn't your Vim running with utf-8 encoding?

lsq commented 1 month ago

is inconsistent with bind_textdomain_codeset (VIMPACKAGE, 'utf-8')

Where do you have set? And isn't your Vim running with utf-8 encoding?

Yes, my vim set running with utf-8 encoding. In mbyte.c, I set bind_textdomain_codeset (VIMPACKAGE, 'cp936') replacing enc_utf8 ? "utf-8" : (char *)p_enc,then the message normal. And enc_utf8 ? "utf-8" : (char *)p_enc and p_enc always return utf-8,

chrisbra commented 1 month ago

well then try running vim with :set encoding=cp936. Then p_enc should be cp936. But I think you should rather convert to utf-8 instead.

lsq commented 1 month ago

But I think you should rather convert to utf-8 instead.

Right, with setting :set encoding=cp936, not only the message is garbled, but also the text file's content. And p_enc is still utf-8 , not cp936.