Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Codes Format - 行注释对齐New to Visual Studio Code? Get it now.
Codes Format - 行注释对齐

Codes Format - 行注释对齐

lupee

| (0) | Free
一键对齐文件中代码右侧的 // 行注释
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Codes Format - 行注释对齐

一键对齐当前文件中代码右侧的 // 行注释。

使用方式

安装后,打开任意文本文件,编辑器右上角标题栏会出现一个 // 图标按钮,点击即可对整个文件执行对齐。 也可以在命令面板(Cmd/Ctrl + Shift + P)中执行 Codes Format: 对齐行注释。

对齐前:

int a = 1; // 变量 a
int longer = 2;   // 变量 longer
// 整行注释不受影响
x++;// 自增

对齐后:

int a = 1;      // 变量 a
int longer = 2; // 变量 longer
// 整行注释不受影响
x++;            // 自增

规则

  • 只处理 // 左边有代码 的行;整行都是注释(// 前只有空白)的行原样保留。
  • 整个文件统一对齐到「最长代码显示宽度 + 最小空格数」的列。
  • 字符串("..."、'...'、`...`)与块注释 /* ... */ 内的 // 不会被误判为注释。
  • Tab 缩进按编辑器当前 tabSize 换算为显示列;中文等全角字符按 2 列计算,保证等宽字体下视觉对齐。
  • 整个操作是一次编辑,可用 Ctrl/Cmd + Z 一步撤销。

配置项

配置 默认值 说明
codesFormat.minSpaces 1 代码与 // 之间的最小空格数
codesFormat.wideCharWidth 2 全角字符(中文、日文、韩文、emoji 等)占用的列数

开发

npm install
npm test          # 编译并运行单元测试
npm run package   # 打包为 .vsix

本地安装:code --install-extension release/codes-format-1.0.0.vsix,或在 VSCode 扩展面板右上角 ... → 从 VSIX 安装。

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft