skywind3000 / asyncrun.vim

:rocket: Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
https://www.vim.org/scripts/script.php?script_id=5431
MIT License
1.84k stars 109 forks source link

Chinese characters cannot be displayed properly when running asyncrun with `-mode=term` #220

Closed Dekay999 closed 3 years ago

Dekay999 commented 3 years ago

When I run a python file with

:AsyncRun -mode=term -pos=bottom -raw python %

Chinese character cannot be displayed properly: image

skywind3000 commented 3 years ago
:AsyncRun -mode=term -pos=external -raw python %
Dekay999 commented 3 years ago

Hi skywind, by using -pos=external, I got this: image still, chinese character can't be displayed properly.

skywind3000 commented 3 years ago

what is your file encoding ??

Dekay999 commented 3 years ago

utf-8

skywind3000 commented 3 years ago

add a header to your python source:

# -*- coding: utf-8 -*-
Dekay999 commented 3 years ago

image

image still the same output... By the way, I was using MSYS2 in windows10 system.

Dekay999 commented 3 years ago

And if I run python in the Terminal, everything is OK: image So, this is really weird.

skywind3000 commented 3 years ago

你别告诉我你是在用 windows 下的 gvim 操作 msys

Dekay999 commented 3 years ago

哈哈, 原来是中国人, 我是在windows下装了MYSYS2, 在MSYS2里面用pacman装了vim

Dekay999 commented 3 years ago

我是用的MSYS2终端, 那可能是MSYS2本身的编码问题, 我再研究研究, 多谢了

skywind3000 commented 3 years ago

不知道了,有点诡异。

Dekay999 commented 3 years ago

解决了, 确实是MSYS2的问题: 链接

Dekay999 commented 3 years ago

刚才的办法还有问题, 会把.py文件中的中文变成乱码(因为MSYS2和.py编码文件不一致). 下面的办法终于可以完美解决了. 首先明确根本原因是windows终端使用的是gbk编码, 而python使用utf-8编码, 所以解决方案如下: 把MSYS2的编码设置成utf-8来正常显示代码中的中文, 然后编写/bin/win文件:

#!/bin/bash
$@ |iconv -f gbk -t utf-8

然后使用asyncrun时在python前面加上win:

:AsyncRun -mode=term -pos=bottom -raw win python %

现在就一切正常了. /bin/win脚本的作用就是把一个终端的编码转化为utf-8编码再输出.

skywind3000 commented 3 years ago

你用 msys 里面的 python 不就行了?

Dekay999 commented 3 years ago

你说的对, 我刚刚试了, 直接安装pacman版本的python就没有这个问题了😂

skywind3000 commented 3 years ago

下次提 issue 应该先把自己运行环境,vim 版本号什么说清楚。