Sublime Development Plugin-First taste

Source: Internet
Author: User

I have a template plugin on the Web: article address

:Https://github.com/kairyou/SublimeTmpl

I researched his code and tried to change it myself to create my own template.

Why create a template?

Because some of the framework of the code, each file will have, so the code is written directly in the template, each time the new file automatically loaded, save every time to copy.

After downloading from GitHub, unzip, the directory behind Sublime/packages/sublimetmpl must be this, put the extracted files into this directory.

In the Sublime menu, the file tag will come out new file (sublime Tmpl) to create a template written by the author.


Template written in the Templates directory, I wrote a LUA (name: Lua.tmpl parameter and name is the corresponding) template code: ${1:} This is the place where you can quickly edit the file by pressing the TAB key.

--[[  anchor:zkydate: ${1:2015/1/30}target: ${2: Target}]]local event_net_package          =--lua Parse Protocol entry function Closeme ()  thisform:sethide (True) endfunction onLoad () ${3:thisform:addlistener ("NetWork")}${4:thisform: AddListener ("Myself")}initengish () Initset () endfunction initengish () endfunction initset () endfunction onshow () Endfunction onEvent (ID, is) if Id==event_net_package then        parsenetpackage (IS)    endendfunction parsenetpackage (IS)    Is:setoffset (0)    local msgid=is:readint ()    MYLOG ("parsenetpackage--msgid-->"). String.Format ("0X%x", MsgID))    if MsgID = = ${5:msg_id} then  --$6 $    endend

about how to add the menu you want to sublime, in the file of the plugin you developed, define the following file name, that is, you can add a new menu on the sublime corresponding menu

Main.sublime-menu The file defines the top menu of the sublime

Side Bar.sublime-menu the right mouse button out of the Side Bar menu

Context.sublime-menu left side of file right-click Action Folder popup menu


Look at the code under Main.sublime-menu: it means adding a New file (Sublimetmpl) menu to the file's tag,

The child node of the menu is Lehoo-lua,

The command transmits the accepted file for Sublime_tmpl, because Sublime is developed in Python, and the plugin is also developed in Python, so this command will point to the sublime_tmpl.py executable file.

Args is the pass-through argument. You can gator a child tag.

[{"id": "File", "Children": [{"caption": "New file (Sublimetmpl)",                        "Children": [{"caption": "Lehoo-lua",                        "Command": "Sublime_tmpl", "args": {"type": "Lua" }},                    {                         "caption": "HTML",                        "command": "Sublime_tmpl",            &NBS P           "args": {                      & nbsp     ' type ': ' HTML '                        }  &N Bsp   &NBSp            }]}]},


If we add a new language template, we need to modify sublimetmpl.sublime-settings this file, in order to save the file is the corresponding suffix, and the syntax is highlighted.

{"    xml-960*640": {        "syntax": "Packages/xml/xml.tmlanguage"    },    "Lua": {        "syntax": "Packages/lua /lua.tmlanguage "        //," extension ":" HTML "# Default_extension    },    " html ": {        " syntax ":" packages/html/ Html.tmlanguage "        //," extension ":" HTML "# Default_extension    },    " Disable_keymap_actions ": false,//" All "; "Html,css"    "Date_format": "%y-%m-%d%h:%m:%s",    "attr": {        "author": "Your Name",        "email": "[email Protected] ",        " link ":" Http://example.org "    }}

Above is the association of a LUA language I added, xml-960*640 is the parameter passed, and the name of the template is the name.

The following attr is written by the author, it is possible to join the date and author-related, please see the above link article

Lua.tmlanguage in the corresponding directory are have this file, associated with the time, look at the confirmation under


Add the remaining two menus to try, create a new file name such as: Side Bar.sublime-menu placed in this directory, write (another, now click on the corresponding menu will also appear new file (Sublimetmpl) This menu, And the operation is effective

[    {        "caption": "New File (Sublimetmpl)",        "Children":        [            {                "caption": "Lua",                "command": " Sublime_tmpl ",                " args ": {                    " type ":" Lua "                }            },            {                " caption ":" HTML ",                " command ":" Sublime_tmpl ",                " args ": {                    " type ":" HTML "                }        ]    }]

We added the template, no shortcut key command, say, how to add shortcut keys, here we need to change two files

Default.sublime-keymap added: Lua that we set the shortcut key is CTRL + ALT + L

[    {"        keys": ["Ctrl+alt+l"], "command": "Sublime_tmpl",        "args": {"type": "Lua"}, "context": [{"Key": " Sublime_tmpl.lua "}]    }    , {"        keys ": [" Ctrl+alt+h "]," command ":" Sublime_tmpl ",        " args ": {" type ":" HTML " }, "context": [{"Key": "Sublime_tmpl.html"}]    }]


Added in Default.sublime-commands:

[    {        "caption": "Tmpl:create Lua", "command": "Sublime_tmpl",        "args": {"type": "Lua"}    },    {        "caption": "Tmpl:create html", "command": "Sublime_tmpl",        "args": {"type": "HTML"}    ]

So shortcut keys, set up, try, but also can use.


These settings are sublime common, and you can use them to develop other plugins as well.

Encountered the problem, the creation of the file, not in the directory I want, but in my user directory, but now did not learn python, and so on later study, change here.

The official File-new file from the above menu establishes the new files in the user directory, while the left-click folder is created under the corresponding folder.

This should be done, but there is a memory function that does not need to be re-selected every time.

If you want to create a new file in a directory, first in the file list on the left side of the sublime, first select a file under that record, so that the first file is in this directory.


Extended reading: How to develop sublime Text2 plugins








Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Sublime Development Plugin-First taste

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.