Sublimetext2 升华文本在自动完成后输入空格

Sublimetext2 升华文本在自动完成后输入空格,sublimetext2,sublime-text-plugin,Sublimetext2,Sublime Text Plugin,如何为HTML语言编写自定义键绑定或插件,在标记后添加enter 示例 当前升华文本在自动完成时执行此操作 <table></table> 我想要这个 <table> </table> 我希望你们能帮忙。提前感谢:)这些代码片段的完成是在HTML包中硬编码的 我认为最简单的归档方法是自己编写一个简单的插件。为此,请打开User文件夹(或包的其他子文件夹)并创建python文件(例如html\u complete\u tag.py) 然

如何为HTML语言编写自定义键绑定或插件,在标记后添加
enter

示例

当前升华文本在自动完成时执行此操作

<table></table>

我想要这个

<table>

</table>


我希望你们能帮忙。提前感谢:)

这些代码片段的完成是在HTML包中硬编码的

我认为最简单的归档方法是自己编写一个简单的插件。为此,请打开
User
文件夹(或包的其他子文件夹)并创建python文件(例如
html\u complete\u tag.py

然后打开python文件并粘贴以下代码:

import sublime, sublime_plugin
class HtmlCompleteTagCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        view.run_command("commit_completion")
        for sel in view.sel():
            if not sel.empty(): continue
            pos = sel.begin()
            # check we are inside a tag
            if view.substr(sublime.Region(pos-1, pos+1)) == "><":
                # we have: <tag>|<tag/>
                # insert \n< one position after the cursor
                # => <tag>|<\n<tag/>
                view.insert(edit, pos+1, "\n<")
                # remove the char after the cursor
                # => <tag>|\n<tag/>
                view.replace(edit, sublime.Region(pos, pos+1), "")
                # insert a newline and a tab at the cursor
                # => <tag>\n\t|\n<tag/>
                view.insert(edit, pos, "\n\t")

如果用
enter
确认自动完成,则用
enter
替换
tab
,或保留两个键绑定。

Hi@r-stein,我已经创建了
html\u complete\u tag.py
并将其放置在
User
目录中,还将键绑定放置在
Preferences>Key Bindings-User
中,并且我打开了一个我正在处理的html文件,但它似乎不起作用我错过什么了吗?谢谢如果您用
enter
键确认自动完成,您必须将键绑定从
“键”:[“选项卡”]
更改为
“键”:[“回车”]
{ "keys": ["tab"], "command": "html_complete_tag", "context":
    [
        { "key": "auto_complete_visible" },
        { "key": "selector", "operator": "equal", "operand": "text.html" }
    ]
},