EditorConfig for VS Code无法正常工作

web*_*.ic 21 html css visual-studio-code editorconfig

我使用VS Code作为编辑器.我们有一个.editorconfig格式配置的文件.我们在编辑器中使用extenion EditorConfig来格式化我们的HTML和CSS一般.我从这里安装了VS Code的扩展EditorConfig:https://github.com/editorconfig/editorconfig-vscode

我们的.editorconfig文件如下所示:

# This is the top-most .editorconfig file (do not search in parent directories)
root = true

### All files
[*]
# Force charset utf-8
charset = utf-8
# Indentation
indent_style = tab
indent_size = 4
# line breaks and whitespace
insert_final_newline = true
trim_trailing_whitespace = true
# end_of_line = lf

### Frontend files
[*.{css,scss,less,js,json,ts,sass,php,html,hbs,mustache,phtml,html.twig}]

### Markdown
[*.md]
indent_style = space
indent_size = 4
trim_trailing_whitespace = false

### YAML
[*.yml]
indent_style = space
indent_size = 2

### Specific files
[{package,bower}.json]
indent_style = space
indent_size = 2
Run Code Online (Sandbox Code Playgroud)

我找不到任何键盘快捷键,设置或其他.如何让我的扩展程序从.editorconfig文件中执行操作?

web*_*.ic 29

我自己的解决方案:

我遇到的问题是,我将扩展名添加editorconfig到了我vscode,但没有安装npm package它.所以仅仅将扩展名添加到你的vscode是不够的,你还要安装包,这样它就可以运行了.

npm package像这样安装了全局:npm install -g editorconfig

之后我添加了扩展并启用了它.现在它完美无缺.

以下是所需npm包的链接:https://www.npmjs.com/package/editorconfig

以下是vscode所需扩展的链接:https://marketplace.visualstudio.com/items itemName = EditConfig.EditorConfig

  • 它对我来说仍然不起作用。我安装了节点、editorconfig 包和 vscode 扩展。是不是少了点什么?也许是在 vscode 设置中? (6认同)
  • 这个解决方案也对我有用。扩展没有检查并警告您这一点很疯狂! (3认同)
  • @johey至少,我希望能在`vscode`扩展名的描述中找到此信息...我自己自己弄清楚了,很幸运:) (2认同)
  • @Nachokhan 确保您没有“竞争”插件来处理样式并覆盖您的“editorconfig”设置。 (2认同)

小智 8

此外,我还需要打开“保存时编辑器格式”选项。

{
   "editor.formatOnSave": true
}
Run Code Online (Sandbox Code Playgroud)