Note:

  1. The Sublime plug-in is written in Python
  2. This article does not involve practical projects
  3. This article is intended only to guide developers through writing and running the Hello World example

Plug-in creation and saving

Plug-in storage directory

The plugin is stored at: C:\Users\

\AppData\Roaming\Sublime Text 3\Packages

You can also use the Menu > Preferences > Browser Packages… Open the folder.

Creating a plug-in

Run the menu > Tools > Developer > New Plugin… Create a new plug-in:

import sublime
import sublime_plugin

class ExampleCommand(sublime_plugin.TextCommand) :
    def run(self, edit) :
        Insert "Hello, World!" at the beginning of the sublime editor (first row, first column)
        self.view.insert(edit, 0."Hello, World!")
Copy the code

Save the file to the plug-ins directory with the suffix “.py” and sublime will automatically reload and activate the module.

How to call a module

1. Invoke the command on the console

Open Menu > View > Show Console to enable the console.

Note that the class name we just wrote is “ExampleCommand”, and sublime is called by removing the “Command” at the end and writing the rest of the class in lowercase with an underscore.

So in the console, enter view.run_command(‘example’) to invoke the ExampleCommand class function.

Similarly, view.run_command(‘hello_world’) calls HelloWorldCommand, Type vie.run_command (‘h_t_m_l_viewer’) to call HTMLViewerCommand (just an example, most people don’t write this).

If the class to be called does not exist, no effect is displayed.

2. Invoke through key binding

Open menu > Prefereces > Key Bindings and edit the user file.

Suppose we want to bind ExampleCommand to the “CTRL +shift+v” shortcut, type: [{“keys”: [” CTRL +shift+v”], “command”: “example”}].

Sublime is automatically overloaded and activated after saving, and can now be used with fast keys to achieve the same effect on the command line.

3. Invoke through event binding

TODO

Ensure that the modules the plug-in depends on are running smoothly

TODO