我已经开始编写一些 bash 脚本来增强 git,使用 Visual Studio Code并且我希望编辑器在这样做时使用语法突出显示。
这些文件没有扩展名,否则 git 不会将它们作为附加命令进行选择。
这是此类脚本的示例名称:git-review
所以问题是,如何配置 Visual Studio Code 以对这些文件使用 Bash 语法高亮显示?
如果我将 Visual Studio Code 中的文件重命名为 .sh
, 喜欢 git-review.sh
然后回到无扩展名( git-review
),Visual Studio Code 似乎记住了这一点并显示语法突出显示,但我添加到文件夹中的任何新文件都以纯文本形式突出显示(直到我进行重命名舞蹈)。即使我关闭文件并重新启动 Visual Studio Code 并重新打开文件,Visual Studio Code 似乎也记住了这一点。多久我不知道。
我可以使用纯文本文件,因为某些原因没有将扩展名突出显示为 bash 脚本,但显然,如果有办法使 Visual Studio Code 更加智能,比如查看 #!/bin/sh
的第一行那么那就更好了。
我尝试使用“为 '.xyz' 配置文件关联”来查看这些关联是如何存储在设置文件中的,并发现这正确地将 Bash 突出显示应用于 .xyz
文件:
"files.associations": {
"*.xyz": "shellscript"
},
但是,这不会:
"files.associations": {
"*.": "shellscript"
},
这也不是:
"files.associations": {
"*": "shellscript"
},
有什么办法可以让这个设置适用于无扩展名的文件?
如果这很重要的话,这就是适用于 Windows 的 Visual Studio Code。
最佳答案
if there is a way to make Visual Studio Code even smarter, like looking at the first line for
#!/bin/sh
then that would be even better.
VSCode 实际上已经将文件与
shellscript
关联起来基于shebang。但是,请注意,它不会动态检测它 - 如果添加 shebang,则需要关闭并重新打开文件,以便 VSCode 注意到它。
关于visual-studio-code - 获取 Visual Studio Code 将无扩展名文件的语法高亮显示为 bash 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47636026/