如何在崇高的文本2中启用Gemfile的语法高亮显示?

时间:2021-11-27 21:32:16

I recently started using Sublime Text 2. What an awesome editor. It does a great job of highlighting Ruby code, but it does not highlight my Gemfile.

我最近开始使用崇高的文本2。一个很棒的编辑器。它很好地突出了Ruby代码,但是它并没有突出显示我的Gemfile。

Is there a way to get it to do that?

有没有办法让它那样做?

I found this Gist but it has no instructions on how to use it.

我找到了这个要点,但是没有说明如何使用它。

4 个解决方案

#1


34  

There are at least three options:

至少有三种选择:

  1. Switch syntax manually (not preferred, but easy; no explanation required)
  2. 手动切换语法(不是首选,但很容易;不需要解释)
  3. Add "Gemfile" to the list of Ruby-syntax files
  4. 将“Gemfile”添加到ruby语法文件列表
  5. Use the plugin you link to and create a package for it
  6. 使用你链接到的插件并为它创建一个包。

1. No explanation, but handy trick

1。没有解释,不过是小把戏。

You can bind a keystroke to set syntax without moving to the mouse.

您可以绑定一个击键来设置语法,而无需移动鼠标。

I bound syntax changing to Ctrl-Opt-Space by adding the following to my user keybindings:

我将语法修改为Ctrl-Opt-Space,方法是在用户键绑定中添加以下内容:

[
  { "keys": ["ctrl+alt+space"], 
    "command": "show_overlay", 
    "args": { "overlay": "command_palette", "text": "Set Syntax: " } }
]

2. Add "Gemfile" to list of Ruby-syntax files

2。向ruby语法文件列表中添加“Gemfile”

  • Linux: ~/.config/sublime-text-2/Packages/Ruby/Ruby.tmLanguage
  • Linux:~ / config / / Ruby / Ruby.tmLanguage sublime-text-2 /包
  • OS X: ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.tmLanguage
  • OS X: ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.tmLanguage
  • Windows: %APPDATA%/Sublime Text 2/Packages/Ruby/Ruby.tmLanguage
  • Windows:% APPDATA % / 2 /包/ Ruby / Ruby.tmLanguage崇高文本

You can also get there by using the menu option Preferences -> Browse Packages and going into the Ruby package. Once you're in the file it'll be obvious: it's the <array> element with Ruby-looking filenames. Add <string>Gemfile</string> and you're all set.

您也可以通过使用菜单选项首选项->浏览包和进入Ruby包来实现。一旦进入文件,就很明显了:它是 元素,文件名像红宝石。添加 Gemfile ,设置完毕。

It's possible the setting could get overwritten on an upgrade; I'm not sure how that works with ST2–it may be cleaner to do it through code as in the snippet.

有可能在升级时覆盖设置;我不确定st2是如何工作的——像代码片段中那样,通过代码来完成它可能更简单。

3. Using the snippet you linked to

3所示。使用您链接到的代码片段

More work (and the correction of one syntax error). You can either do it manually, by creating a directory in Packages (see above for location) or create an actual package and allow ST2 to install it.

更多的工作(以及修正一个语法错误)。您可以通过在包中创建目录(参见上面的位置)或者创建一个实际的包并允许ST2安装它来手动完成。

I created a test package called "Syntax" and copied the snippet into it, restarted ST2, and opening a Gemfile worked as expected. The correction required an additional colon (new gist), nutshell:

我创建了一个名为“语法”的测试包,并将代码片段复制到其中,重新启动ST2,并打开一个Gemfile。修正需要一个额外的冒号(新的要点),果壳:

elif name[-3] == "erb": # Needed a semi-colon here.
  set_sintax(view, "HTML (Rails)", "Rails")

#2


4  

If you are here but are using Sublime Text 3 you might not be able able to find the 'list of Ruby-syntax files' in packages.

如果您在这里,但正在使用崇高的文本3,您可能无法找到“ruby语法文件列表”中的包。

Most other solutions found online were confusing to me.

在网上找到的大多数其他解决方案让我感到困惑。

I fixed this by manually changing Gemfile to Ruby in the bottom right hand corner file extension menu item when you have opened the file in Sublime Text 3 (which is what I had been doing each time I opened the file up until now).

我通过在右下角的文件扩展菜单项中手动将Gemfile更改为Ruby来修复这个问题,当您已经用Sublime Text 3打开文件时(这是我每次打开文件时一直在做的)。

Once you have selected ruby then go to Preferences -> Settings-More -> Syntax Specific-User

选择ruby之后,转到Preferences -> settingmore ->语法指定- user

{
  "extensions":
  [
    "Gemfile",
    "Gemfile.lock"
  ]
}

When you navigate to Syntax Specific User it opens a file specific to the language that the file has syntax highlighting for. You may need to change the file back to whatever it is defaulting too (mine was 'Rd (R Documentation).sublime-settings') and removing Gemfile from that Syntax highlighting file.

当您导航到语法特定的用户时,它会打开一个特定于该文件语法高亮显示的语言的文件。您可能需要将该文件更改为默认的文件(我的文件是“Rd (R文档).sublime-settings”),并从语法突出显示文件中删除Gemfile。

In Ubuntu these files are stored at

在Ubuntu中,这些文件存储在

~/.config/sublime-text-3/Packages/User

#3


2  

The DetectSyntax plugin for ST2 provides a more comprehensive solution to highlighting files - It allows file highlighting based on rules. It's smart enough to understand the difference between a Rails file, other files that use .rb as an extension and standard ruby files.

ST2的DetectSyntax插件为突出显示文件提供了更全面的解决方案——它允许根据规则突出显示文件。理解Rails文件、使用.rb作为扩展名的其他文件和标准ruby文件之间的差异已经足够智能了。

The standard rules include Gemfile, Rakefile, Guardfile and others matched to Ruby for Syntax formatting.

标准规则包括Gemfile、Rakefile、Guardfile和其他与Ruby匹配的语法格式。

See DetectSyntax on GitHub.

在GitHub看到DetectSyntax。

#4


-1  

You can achieve this by copying the HTML.tmLanguage file in the User/ folder, this way it won't be overwritten by an update.

您可以通过复制HTML来实现这一点。tmLanguage文件在用户/文件夹中,这样就不会被更新覆盖。

#1


34  

There are at least three options:

至少有三种选择:

  1. Switch syntax manually (not preferred, but easy; no explanation required)
  2. 手动切换语法(不是首选,但很容易;不需要解释)
  3. Add "Gemfile" to the list of Ruby-syntax files
  4. 将“Gemfile”添加到ruby语法文件列表
  5. Use the plugin you link to and create a package for it
  6. 使用你链接到的插件并为它创建一个包。

1. No explanation, but handy trick

1。没有解释,不过是小把戏。

You can bind a keystroke to set syntax without moving to the mouse.

您可以绑定一个击键来设置语法,而无需移动鼠标。

I bound syntax changing to Ctrl-Opt-Space by adding the following to my user keybindings:

我将语法修改为Ctrl-Opt-Space,方法是在用户键绑定中添加以下内容:

[
  { "keys": ["ctrl+alt+space"], 
    "command": "show_overlay", 
    "args": { "overlay": "command_palette", "text": "Set Syntax: " } }
]

2. Add "Gemfile" to list of Ruby-syntax files

2。向ruby语法文件列表中添加“Gemfile”

  • Linux: ~/.config/sublime-text-2/Packages/Ruby/Ruby.tmLanguage
  • Linux:~ / config / / Ruby / Ruby.tmLanguage sublime-text-2 /包
  • OS X: ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.tmLanguage
  • OS X: ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.tmLanguage
  • Windows: %APPDATA%/Sublime Text 2/Packages/Ruby/Ruby.tmLanguage
  • Windows:% APPDATA % / 2 /包/ Ruby / Ruby.tmLanguage崇高文本

You can also get there by using the menu option Preferences -> Browse Packages and going into the Ruby package. Once you're in the file it'll be obvious: it's the <array> element with Ruby-looking filenames. Add <string>Gemfile</string> and you're all set.

您也可以通过使用菜单选项首选项->浏览包和进入Ruby包来实现。一旦进入文件,就很明显了:它是 元素,文件名像红宝石。添加 Gemfile ,设置完毕。

It's possible the setting could get overwritten on an upgrade; I'm not sure how that works with ST2–it may be cleaner to do it through code as in the snippet.

有可能在升级时覆盖设置;我不确定st2是如何工作的——像代码片段中那样,通过代码来完成它可能更简单。

3. Using the snippet you linked to

3所示。使用您链接到的代码片段

More work (and the correction of one syntax error). You can either do it manually, by creating a directory in Packages (see above for location) or create an actual package and allow ST2 to install it.

更多的工作(以及修正一个语法错误)。您可以通过在包中创建目录(参见上面的位置)或者创建一个实际的包并允许ST2安装它来手动完成。

I created a test package called "Syntax" and copied the snippet into it, restarted ST2, and opening a Gemfile worked as expected. The correction required an additional colon (new gist), nutshell:

我创建了一个名为“语法”的测试包,并将代码片段复制到其中,重新启动ST2,并打开一个Gemfile。修正需要一个额外的冒号(新的要点),果壳:

elif name[-3] == "erb": # Needed a semi-colon here.
  set_sintax(view, "HTML (Rails)", "Rails")

#2


4  

If you are here but are using Sublime Text 3 you might not be able able to find the 'list of Ruby-syntax files' in packages.

如果您在这里,但正在使用崇高的文本3,您可能无法找到“ruby语法文件列表”中的包。

Most other solutions found online were confusing to me.

在网上找到的大多数其他解决方案让我感到困惑。

I fixed this by manually changing Gemfile to Ruby in the bottom right hand corner file extension menu item when you have opened the file in Sublime Text 3 (which is what I had been doing each time I opened the file up until now).

我通过在右下角的文件扩展菜单项中手动将Gemfile更改为Ruby来修复这个问题,当您已经用Sublime Text 3打开文件时(这是我每次打开文件时一直在做的)。

Once you have selected ruby then go to Preferences -> Settings-More -> Syntax Specific-User

选择ruby之后,转到Preferences -> settingmore ->语法指定- user

{
  "extensions":
  [
    "Gemfile",
    "Gemfile.lock"
  ]
}

When you navigate to Syntax Specific User it opens a file specific to the language that the file has syntax highlighting for. You may need to change the file back to whatever it is defaulting too (mine was 'Rd (R Documentation).sublime-settings') and removing Gemfile from that Syntax highlighting file.

当您导航到语法特定的用户时,它会打开一个特定于该文件语法高亮显示的语言的文件。您可能需要将该文件更改为默认的文件(我的文件是“Rd (R文档).sublime-settings”),并从语法突出显示文件中删除Gemfile。

In Ubuntu these files are stored at

在Ubuntu中,这些文件存储在

~/.config/sublime-text-3/Packages/User

#3


2  

The DetectSyntax plugin for ST2 provides a more comprehensive solution to highlighting files - It allows file highlighting based on rules. It's smart enough to understand the difference between a Rails file, other files that use .rb as an extension and standard ruby files.

ST2的DetectSyntax插件为突出显示文件提供了更全面的解决方案——它允许根据规则突出显示文件。理解Rails文件、使用.rb作为扩展名的其他文件和标准ruby文件之间的差异已经足够智能了。

The standard rules include Gemfile, Rakefile, Guardfile and others matched to Ruby for Syntax formatting.

标准规则包括Gemfile、Rakefile、Guardfile和其他与Ruby匹配的语法格式。

See DetectSyntax on GitHub.

在GitHub看到DetectSyntax。

#4


-1  

You can achieve this by copying the HTML.tmLanguage file in the User/ folder, this way it won't be overwritten by an update.

您可以通过复制HTML来实现这一点。tmLanguage文件在用户/文件夹中,这样就不会被更新覆盖。