Custom filetype per file

我只是一个虾纸丫 提交于 2019-12-11 12:14:57

问题


Let's say that i have file /home/foo/myfile without extension. Is there option to add syntax setting into this file? In vim it's :set syntax=javascript. I know that in Sublime you can set default syntax color.
There's similar question Changing default syntax based on filename but there you set specific filename. I need to set it in file itself, since i have a lot of different files without extension.


回答1:


The package ApplySyntax should be able to do what you want.

ApplySyntax is a plugin for Sublime Text 2 and 3 that allows you to detect and apply the syntax of files that might not otherwise be detected properly. For example, files with the .rb extension are usually Ruby files, but when they are found in a Rails project, they could be RSpec spec files, Cucumber step files, Ruby on Rails files (controllers, models, etc), or just plain Ruby files. This is actually the problem I was trying to solve when I started working on this plugin.

Set your rules/filenames in the ApplySyntax.sublime-settings file:

// "rules" is a list (array) of checks that you want to make against the file in the current view. A rule is either a regular expression or a function. If using a regular expression, you can specify whether you want it tested against the "file_name" or the first line of the file (think shebangs and xml files). If the rule is a function, you must provide the path to the file containing the function and the name of the function to call. When this function is called, the "file_name" will be passed to it as the only argument. You are free to do whatever you want in your function, just return True or False.




回答2:


you can do this on the fly through the command menu (on OSX cmd+shift+p, windows ctrl+shift+p) then type what you need (e.g. javascript) and it will come up in the list set syntax: JavaScript.

Sublime will remember this until you close the file



来源:https://stackoverflow.com/questions/23775559/custom-filetype-per-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!