听起来像我一样懒惰我想知道是否可以使用(命令行)使用sublime打开文件,并在同一命令中定义预期的语法。
让我们在mac上说我们安装了subl命令,因此运行$ subl .bash_something
会打开 .bash_something 然后我们必须选择" shel脚本(bash)的"列表中的语法。什么是非常好的(为了laze me)是将语法作为参数包含在命令中。即。
$ subl -x bash .bash_something
或类似的东西。这显然不起作用,但我想知道是否有类似的解决方案或是否可能包括一个
答案 0 :(得分:2)
Unfortunately, there is no way that I can find to dynamically set the syntax from the command line. w.write('\n'.join(eintraege))
has the subl
option, which allows you to run a Sublime command while loading the file, directory, or project indicated. However, the command to change the syntax of a view - --command
- takes an argument of the form set_file_type
(or ("syntax": "Packages/PackageName/SyntaxName.sublime-syntax")
). As far as I've been able to tell, you simply can't pass arguments to commands run via the command line. I've opened an issue to request an enhancement.
Now, this doesn't mean that all is lost. If you have just a few filetypes that are unknown to Sublime, open them, then select SyntaxName.tmLanguage
and select the syntax you want. If for some reason this isn't sufficient, or would like finer-grained control over exactly which filenames (not just which extensions) get opened as what, check out the ApplySyntax
plugin. It allows you to use regexes to open exactly which file patterns you define as what syntax.
答案 1 :(得分:1)
命令现在可以在Sublime 3中获取参数。我能够通过bash函数实现此功能。
您可以使用内联JSON和转义引号将参数传递给--command
选项。此命令将在Sublime中将当前活动文件的语法更改为Bash:
subl --command "set_setting {\"setting\": \"syntax\", \"value\": \"Packages/ShellScript/Shell-Unix-Generic.sublime-syntax\"}"
我创建了一个简单的bash函数并在我的.bash_profile
中获取它以将这两个命令包装在一起以激活/打开文件然后更改synax:
function subl_bash() {
subl "$1" && subl --command "set_setting {\"setting\": \"syntax\", \"value\": \"Packages/ShellScript/Shell-Unix-Generic.sublime-syntax\"}"
}