Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run command on save in Sublime Text 3?

Tags:

sublimetext3

Sublime Text offers built-in commands, such as paste, new_window, toggle_comment etc. In addition, some plugins offer their own commands that can be used for key binding.

Can I force any of these commands to be ran on file save? The reason I need is because I'd like to run CSScomb on file save instead of / in addition to having key binding for it. The command name is css_comb.

like image 796
Robo Robok Avatar asked Jul 18 '15 19:07

Robo Robok


People also ask

How do I run a command in Sublime Text?

To open a command palette in Sublime Text editor, you can use the shortcut key combination Ctrl+Shift+P on Windows and Cmd+Shift+P on OSX.

How do I save in Sublime Text 3?

Save a File with Sublime TextIn Sublime Text's top menu bar, choose File > New File. An untitled, blank file will appear. Next, choose File > Save or Save As.

Which command is used to run a command after saving it?

run_command("exec", {"cmd": ["hindent", "$file"]}) in a custom command .


1 Answers

Sublime-hooks package allows you to run packages based on event (on new, on save, etc.), so you can use it to achieve your goal. Just add this code to CSS syntax settings:

"on_pre_save_language": [
    {
        "command": "css_comb"
    }
]

If you are familiar with plugins maybe you can make a plugin that extends EventListener and override on_post_save or on_pre_save methods.

like image 106
sergioFC Avatar answered Sep 23 '22 23:09

sergioFC