如何防止 VScode 向特定文件扩展名添加尾随换行符

问题描述 投票:0回答:1

您已经在 VScode 中编辑了

master.key
credentials.yml.enc
文件,并且在保存文件时遇到了问题,因为您的编辑器配置为确保文件有尾随换行符,并且 rails 在解密之前不会删除内容它.

ruby-on-rails credentials trailing-newline
1个回答
0
投票

我通常只在 Vi 或 BBEdit 中读/写该类型的文件,但您可以在 VScode 中通过配置这些文件扩展名以使用特定语言模式,然后禁用该语言模式的设置来解决此问题:

// .vscode/settings.json
{
  // Global Settings:
  "editor.tabSize": 2,
  "editor.indentSize": "tabSize",
  "files.insertFinalNewline": true,
  "files.trimTrailingWhitespace": true,
  "files.trimFinalNewlines": true,
  // Define the Language Mode for specific file extensions:
  "files.associations": {
    "*.enc": "shellscript",
    "*.key": "shellscript"
  },
  // Define override settings for specific Language Mode:
  "[shellscript]": {
    "files.insertFinalNewline": false
  }
}

注意:设置文档还有一些不足之处,但您实际上需要使用被识别为 VScode 有效语言模式的标识符(即 VScode 用来确定文件要使用哪种语法突出显示的功能)。我在这里使用

shellscript
,这是 VScode 的
Shell Script
语言模式标识符。

© www.soinside.com 2019 - 2024. All rights reserved.