作者在 2026-03-23 13:45:47 发布以下内容
修改了两处:
1、去掉了 python 等注释结尾的 # 号
2、中文宽度 = 英文宽度 x 5/3
插件包:
使用方法:
下载解压后覆盖掉文件夹:
C:\Users\gs412\.vscode\extensions\stackbreak.comment-divider-0.4.0
(注意:蓝色部分是用户名和插件版本,换成你自己的)
附修改方法,你也可以安装官方插件按需要自己修改
1、去掉 python 等注释结尾的 # 号
打开 stackbreak.comment-divider-0.4.0\out\limiters.js ,把
return wrapLimiters('#', '#');
替换为
return wrapLimiters('#', '');
2、支持中文宽度
打开 stackbreak.comment-divider-0.4.0\out\builders.js
搜索“const withLimiters”,在其上面加入:
中文宽度每种字体不一样,我选择的字体在vscode下3个中文和5个英文宽度相等,所以我设置了 5 / 3,如果你的不一样可以在 vscode 中输入中文跟英文对比一下宽度,然后换成合适的值
1、去掉了 python 等注释结尾的 # 号
2、中文宽度 = 英文宽度 x 5/3
插件包:
stackbreak.comment-divider-0.4.0.zip (533.52 KB)
使用方法:
下载解压后覆盖掉文件夹:
C:\Users\gs412\.vscode\extensions\stackbreak.comment-divider-0.4.0
(注意:蓝色部分是用户名和插件版本,换成你自己的)
附修改方法,你也可以安装官方插件按需要自己修改
1、去掉 python 等注释结尾的 # 号
打开 stackbreak.comment-divider-0.4.0\out\limiters.js ,把
return wrapLimiters('#', '#');
替换为
return wrapLimiters('#', '');
2、支持中文宽度
打开 stackbreak.comment-divider-0.4.0\out\builders.js
搜索“const withLimiters”,在其上面加入:
const words_length = (words) => {
const hanWeight = 5 / 3 // 这里是关键,一个汉字是 5 / 3 个英文字母宽度
const asciiWeight = 1
const otherWeight = 1
let total = 0;
for (let i = 0; i < words.length; i++) {
const code = words.codePointAt(i);
// 处理 surrogate pair(emoji等)
if (code > 0xffff) i++;
if (
// 汉字
(code >= 0x4E00 && code <= 0x9FFF) ||
(code >= 0x3400 && code <= 0x4DBF) ||
// CJK 标点
(code >= 0x3000 && code <= 0x303F) ||
// 全角符号(关键!)
(code >= 0xFF00 && code <= 0xFFEF)
) {
total += hanWeight;
} else if (code <= 0x7F) {
total += asciiWeight;
} else {
total += otherWeight;
}
}
return Math.round(total);
}
全文替换 words.length 为 words_length(words) ,保存后重启 vscode 即可生效中文宽度每种字体不一样,我选择的字体在vscode下3个中文和5个英文宽度相等,所以我设置了 5 / 3,如果你的不一样可以在 vscode 中输入中文跟英文对比一下宽度,然后换成合适的值

