Sublime Forum

Apply syntax manually (due to load time)

#1

Hi, I’m a Sublime Text and AutoHotKey user. Both programs now seem to be essential for me; I can’t live without them.
But I realised Sublime has a shortcoming when it comes to syntax highlightning on long files. I have a AHK script with 20000 lines long. I also have a keyboard shortcut to launch it directly in Sublime Text (edit in ST), but it will take a lot of seconds to load; I can even see the fine progress bar.
But, when I save a copy of my 20k lines script in .txt, then Sublime Text will be blazing fast.

So, I’d like to have it take every file as txt by default, and apply the syntax manually only when I’m doing some difficult editions, so I can see the colors. Also, when hitting my keyboard shortcut to open the file in ST, I’d like it to treat as a .txt file and apply no syntax at first, so the document can load faster.

Is it possible?

My OS is Windows 8 with ST version 2.0.2 Build 2221.
Thanks!

0 Likes

#2

View > Syntax > Open all with current extension as > Plain Text.

Then you can later go View > Syntax > Autohotkey.

0 Likes

#3

Perfect, Adzenith! That was what I was looking for!
The only thing I need now is to know how to customize the Keybindings - user file to have a keyboard shortcut instantly apply the AutoHotKey syntax when I need it (navigating that drop-down menu is tedious, specially everytime…)

Thanks!

0 Likes

#4

In the console, run sublime.log_commands(True), and then change the syntax. That’ll tell you what you need to bind.

0 Likes

#5

Thanks, I got the command. I’m almost there.
I copied the syntax from the previous commands and got this:

{ "keys": "ctrl+ç"], "command": "set_file_type" {"syntax": "Packages/Autohotkey/Autohotkey.tmLanguage"} }

Then, upon saving, it displayed this message:
Error trying to parse file: Unexpected character, expected a comma or closing bracket in file path\Default (Windows).sublime-keymap:10:55

My whole keybindings file is as follows:

{ "keys": "alt+q"], "command": "close_file" }, { "keys": "alt+m"], "command": "run_macro_file", "args": {"file": "Packages/User/ponto-e-vírgula-e-jogo-da-velha.sublime-macro"} }, { "keys": "ctrl+shift+w"], "command": "toggle_setting", "args": {"setting": "word_wrap"} }, { "keys": "ctrl+Alt+0"], "command": "select_favorite_file" }, { "keys": "ctrl+-"], "command": "select_favorite_file" }, { "keys": "alt+-"], "command": "select_favorite_file" }, { "keys": "alt+-"], "command": "select_favorite_file" }, { "keys": "ctrl+="], "command": "select_favorite_file" }, { "keys": "ctrl+ç"], "command": "set_file_type" {"syntax": "Packages/Autohotkey/Autohotkey.tmLanguage"} } ]

What’s wrong? :smile:

0 Likes

#6

@Nolan, you are missing the “args” key.

{ "keys": "ctrl+ç"], "command": "set_file_type", "args": {"syntax": "Packages/Autohotkey/Autohotkey.tmLanguage"} }

When you get parse errors, it can be useful to run it through a linter. This came up first, but there are, of course, others. jsonlint.com/

0 Likes

#7

Thanks Skuroda, now I have it! :smiley:

0 Likes

#8

Glad you got this working!

0 Likes