如何在Visual Studio Code中手动设置语言以突出显示语法

本文翻译自:How to manually set language for syntax highlighting in Visual Studio Code

Before the confusion begins, this question is about Code, the new lightweight Visual Studio Editor. 在混乱开始之前,这个问题是关于代码(新的轻量级Visual Studio编辑器)的。 You can get it from here: https://code.visualstudio.com/ 您可以从这里获取: https : //code.visualstudio.com/

I have a textfile (.txt) with CSS in it and want to get syntax hightlighting. 我有一个带有CSS的文本文件(.txt),并且想突出显示语法。 You can open the command palette with ctrl + shift + p . 您可以使用ctrl + shift + p 打开命令面板 But there you can not set syntax like in Sublime. 但是,您无法在Sublime中设置语法。

Is there any other way to get the CSS coloring in from my textfile? 还有其他方法可以从文本文件中获取CSS着色吗?


#1楼

参考:https://stackoom.com/question/2587r/如何在Visual-Studio-Code中手动设置语言以突出显示语法


#2楼

In the very right bottom corner, left to the smiley there was the icon saying "Plain Text". 在最右下角的笑脸左侧,有一个标有“纯文本”的图标。 When you click it, the menu with all languages appears where you can choose your desired language. 当您单击它时,将显示所有语言的菜单,您可以在其中选择所需的语言。

VSCode


#3楼

Press Ctrl + K M and then type in (or click) the language you want. Ctrl + K M ,然后输入(或单击)所需的语言。

Alternatively, to access it from the command palette, look for "Change Language Mode" as seen below: 或者,要从命令选项板访问它,请查找“更改语言模式”,如下所示:

在此处输入图片说明


#4楼

Another reason why people might struggle to get Syntax Highlighting working is because they don't have the appropriate syntax package installed. 人们可能难以使“语法突出显示”工作的另一个原因是,因为他们没有安装适当的语法包。 While some default syntax packages come pre-installed (like Swift, C, JS, CSS), others may not be available. 虽然预先安装了一些默认语法包(例如Swift,C,JS,CSS),但其他一些可能不可用。

To solve this you can Cmd + Shift + P → "install Extensions" and look for the language you want to add, say "Scala". 为了解决这个问题,您可以按Cmd + Shift + P →“安装扩展程序”,然后寻找要添加的语言,例如说“ Scala”。

在此处输入图片说明

Find the suitable Syntax package, install it and reload. 找到合适的语法包,安装并重新加载。 This will pick up the correct syntax for your files with the predefined extension, ie .scala in this case. 这将为您的文件定义预定义扩展名的正确语法,即本例中的.scala

On top of that you might want VS Code to treat all files with certain custom extensions as your preferred language of choice. 最重要的是,您可能希望VS Code将具有某些自定义扩展名的所有文件视为首选语言。 Let's say you want to highlight all *.es files as JavaScript, then just open "User Settings" ( Cmd + Shift + P → "User Settings") and configure your custom files association like so: 假设您要以JavaScript突出显示所有*.es文件,然后只需打开“用户设置”( Cmd + Shift + P →“用户设置”)并按如下方式配置自定义文件关联:

  "files.associations": {
    "*.es": "javascript"
  },

#5楼

Syntax Highlighting for custom file extension 自定义文件扩展名的语法突出显示

Any custom file extension can be associated with standard syntax highlighting with custom files association in User Settings as follows. 可以将任何自定义文件扩展名与“用户设置”中的custom files association与标准语法突出显示custom files association ,如下所示。

更改文件关联设置以永久突出显示语法

Note that this will be a permanent setting. 请注意,这将是一个永久设置。 In order to set for the current session alone, type in the preferred language in Select Language Mode box (without changing file association settings) 为了仅设置当前会话,请在“ Select Language Mode框中键入首选语言(不更改file association设置)

Installing new Syntax Package 安装新的语法包

If the required syntax package is not available by default, you can add them via the Extension Marketplace ( Ctrl+Shift+X ) and search for the language package. 如果所需的语法包默认情况下不可用,则可以通过Extension MarketplaceCtrl + Shift + X )添加它们,然后搜索语言包。

You can further reproduce the above steps to map the file extensions with the new syntax package. 您可以进一步重现上述步骤,以使用新的语法包映射文件扩展名。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值