Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bat文件,修改编码格式, 经常无法生效 #394

Closed
Davider-code opened this issue Nov 14, 2021 · 11 comments
Closed

bat文件,修改编码格式, 经常无法生效 #394

Davider-code opened this issue Nov 14, 2021 · 11 comments
Milestone

Comments

@Davider-code
Copy link

以前也用过 notepad2 修改bat文件, 当时就感觉奇怪. 修改之后就不能运行了, 后来同事提醒, 让看一下是不是ansi编码格式, 硬实在保存后,成了utf-8格式, 改回ansi之后就能运行了

最近, 修改bat文件有些频繁, 再次注意到了这个编码的问题, 情况如下:

  1. 有时打开bat后, 状态栏 显示ansi , 修改后直接保存, 再次打开却变成了 utf-8
  2. 有时bat文件是utf-8的, 改成ansi编码后, 再次打开确认时, 有时是成功的, 有时不管怎么改, 都是utf-8 请看下面的gif动画演

没有找到相关的设置, 请求开发人员验证一下问题, 非常感谢

abc

@zufuliu
Copy link
Owner

zufuliu commented Nov 15, 2021

By default 7-bit ASCII is opened in UTF-8 mode, to enforce it's been opened in UTF-8 mode, you can put some Chinese charterers (e.g. comments) after reload the file as ANSI encoding (File -> Reload -> As ANSI).

Possible we should prefer (or always use) ANSI encoding for Batch files, as we already use OEM (DOS-437) for ANSI Art files.

@m2nlight
Copy link

以前也用过 notepad2 修改bat文件, 当时就感觉奇怪. 修改之后就不能运行了, 后来同事提醒, 让看一下是不是ansi编码格式, 硬实在保存后,成了utf-8格式, 改回ansi之后就能运行了

最近, 修改bat文件有些频繁, 再次注意到了这个编码的问题, 情况如下:

  1. 有时打开bat后, 状态栏 显示ansi , 修改后直接保存, 再次打开却变成了 utf-8
  2. 有时bat文件是utf-8的, 改成ansi编码后, 再次打开确认时, 有时是成功的, 有时不管怎么改, 都是utf-8 请看下面的gif动画演

没有找到相关的设置, 请求开发人员验证一下问题, 非常感谢

abc

utf-8是变长字符集,在英文字符集的编码范围和ansi英文编码是一样的。所以只有英文的情况,他们一样。如果担心以后加入中文编码不一致,可以用utf-8带签名(BOM)的版本。

@Davider-code
Copy link
Author

感谢回复,
有没有选项, 可以将bat 默认设置为ansi编码? ansi编码下,也可以保存中文吧, 总之感觉有些麻烦, 用自带的记事本, 也没有这个问题, 我加的一个群里反馈这个问题的, 也太多了, 清一色的回复, 重新存成ansi

@Davider-code
Copy link
Author

Davider-code commented Nov 15, 2021 via email

@m2nlight
Copy link

不知道如何针对某个扩展名设置编码,但是可以设置“全局的”默认编码格式,在菜单“文件” - “编码” - “默认”。有些复选框你可以看看。

我想作者默认用 utf-8 ,是为了兼容 Linux 系统。

@ghost
Copy link

ghost commented Nov 15, 2021

赞同楼主!
我也认同要为批处理文件(bat/cmd)限定ANSI编码,这样对新手更友好些。
VScode就可以指定扩展名对应某个编码。

楼主可以通过楼上介绍的方式取消默认打开为UTF8,也可以手工添加这样两行到配置文件Notepad2.ini:
LoadANSIasUTF8=0
LoadASCIIasUTF8=0

@zufuliu zufuliu added this to the v4.22.01 milestone Nov 16, 2021
@zufuliu
Copy link
Owner

zufuliu commented Nov 16, 2021

Similar bug has been reported before. Will add a option to load 7-bit Batch file in ANSI encoding.

@ghost
Copy link

ghost commented Nov 16, 2021

那么可以在自定义语法高亮里面,增加功能指定文件类型的编码吗?

@zufuliu
Copy link
Owner

zufuliu commented Nov 20, 2021

那么可以在自定义语法高亮里面,增加功能指定文件类型的编码吗?

That requires large amount of work: currently file type (and line endings, indentation settings) is identified after encoding detection.
I agree that per-scheme default encoding and line ending settings should be the preferred solution.

@ghost
Copy link

ghost commented Nov 20, 2021

看来真是隔行如隔山,我不懂编程细节。我以为是先读取文件名和后缀,然后根据后缀分配语法高亮,实际是恰恰相反的。
如果不改变任何设置界面,不需要下拉式选框,仅仅是在样式设置框里补充填写默认编码和换行标记,会不会减少工作量呢?

zufuliu added a commit that referenced this issue Nov 21, 2021
zufuliu added a commit that referenced this issue Nov 21, 2021
@zufuliu zufuliu added the 🛠workaround Workaround available label Nov 21, 2021
@zufuliu
Copy link
Owner

zufuliu commented Nov 21, 2021

Temporary fixes committed as 1e0d3be and ed030ac, further improvements moved to issue #399.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants