zoukankan      html  css  js  c++  java
  • 如何根据自己的实际需求开发属于自己的sublime text插件

    In my spare time I would like to use Sublime Text to write some small pieces of HTML5 code. Every time after I finish the edit, I have to manually open the html page via Chrome manually, which is very inconvenient. Thanks to the great flexibility of Sublime Text, we can create our own plugin with minor effort to make things done automatically:

    Edit html page in Sublime Text -> click some short key defined by ourselves -> html page is opened by Chrome

    (1) Open Sublime Text, menu Tools->New Plugins, then a python file is automatically created for us as below.

    Then paste the following simple python source code:

    import sublime, sublime_plugin
    import webbrowser
    class OpenBrowserCommand(sublime_plugin.TextCommand):
        def run(self,edit):
            window = sublime.active_window()
            window.run_command('save')
            url = 'file://' + self.view.file_name()
            webbrowser.open_new(url)
    

    The logic is quite easy: first save the currently edited file, get its path and open it via the default browser installed in your laptop.
    Save it into /Packages/User. Rename the file as you wish, for example “open_browser.py”.

    (2) Tools->Command Palette, then click “Preferences: Key Bindings – User”:

    paste the following source code:

    [{ "keys": ["ctrl+shift+b"], "command": "open_browser" }]

    it means you tell Sublime Text to execute your plugin “open_browser” when the combination key “ctrl+shift+b” is pressed.
    Now it is done. After you press the keys you configured, the default browser will be opened by your plugin.

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    Linux各目录及每个目录的详细介绍
    centos7 + mysql5.7 tar包解压安装
    Hive2.0的新特性介绍
    Hadoop HIVE
    PIG执行MR时报Connection refused错误
    Zookeeper启动Permission denied
    Hadoop Pig
    Hadoop组件之-HDFS(HA实现细节)
    Datanode启动问题 FATAL org.apache.hadoop.hdfs.server.datanode.DataNode: Initialization failed for Block pool <registering>
    HDFS Federation
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/13625648.html
Copyright © 2011-2022 走看看