Sublime Forum

Set/Cycle Syntax to Previous/Next in list with shortcut?

#1

I often end up working with different types of data files that have various markup, yet are either in no known syntax, or the syntax detected for the file type is wrong, and the highlighting is a mess.

I really wish I could just assign a shortcut that would let me cycle the syntax through the list of syntaxes (previous/next, with wrapping from the first to last and vice versa). That would allow me to quickly find a syntax with contextual highlighting that works well for whatever file I am editing - much faster than switching the syntax using the view menu or the command palette.

Is there any way I could script this behavior in Sublime Text? Is there a plugin or package currently available that would let me do this?

0 Likes

#2

Can you give examples of such data files ? It should be fairly simple to write a syntax cycler but looking at the data files might be important.

0 Likes

#3

If there is a characteristic among files, like file content, first line, file path, file name, file size, file neighbors, etc… it’s probably that its syntax can be auto set via a plugin. But if it is true randomness, yeah… human power.

0 Likes

#4

Sure. Here’s one example. Others are often saved settings files for various audio DAWs/plugins. A lot of VST developers tend to use their own unique formatting for presets/settings files.

[PMC Code v5.1.0]|+^/||1|Window,RegEx,Fast,1,1,Input,-1,-1,1|1|RprFindHotkey
Groups=Start:1
1|If Window Active|Actions|1|0|If_Statement|||||1|
2|[Pause]||1|200|Sleep|||||3|
03|[MsgBox]|ACTIONS ACTIVE|1|0|MsgBox|0||||4|
4|[Text]|{tab}^+/|1|2|SendEvent|||||6|
5|[Else]|Else|1|0|If_Statement|||||11|
6|[Pause]||1|200|Sleep|||||14|
07|[MsgBox]|ELSE|1|0|MsgBox|0||||15|
8|[Text]|^+/|1|0|Send|||||17|
9|[End If]|EndIf|1|0|If_Statement|||||19|

[PMC Code v5.1.0]|F12||1|Window,RegEx,Fast,1,1,Input,-1,-1,1|1|RprFocusArrange
Groups=Start:1
1|If Window Active|ahk_exe reaper.exe|1|0|If_Statement|||||1|
02|[Pause]||1|200|Sleep|||||3|
3|[Text]|{F12}|1|10|Send|||||5|
4|WinActivate||1|333|WinActivate||REAPER.*x64 ahk_class REAPERwnd|||8|
05|[MsgBox]|F12pressed|1|0|MsgBox|0||||10|
06|[Text]|{tab}{F12}|1|0|Send|||||12|
7|[Else]|Else|1|0|If_Statement|||||13|
8|[Pause]||1|200|Sleep|||||17|
09|[MsgBox]|ELSE|1|0|MsgBox|0||||18|
10|[Text]|{F12}|1|0|Send|||||20|
11|[End If]|EndIf|1|0|If_Statement|||||22|
0 Likes

#5

With certain types of files, there is some consistency or header info. but often they still just open as plain text. In those cases, it would be really helpful to cycle through syntaxes quickly to see if any of them provide useful highlighting.

0 Likes