Plugins 在Sublime Text 2插件中移动光标/点

Plugins 在Sublime Text 2插件中移动光标/点,plugins,sublimetext2,sublimetext,Plugins,Sublimetext2,Sublimetext,我正在为Sublime文本编写一个插件,它将光标移动到文档的开头 Vintage mode有一个键绑定用于这类事情: { "keys": ["g", "g"], "command": "set_motion", "args": { "motion": "vi_goto_line", "motion_args": {"repeat": 1, "explicit_repeat": true, "extend": true, "ending":

我正在为Sublime文本编写一个插件,它将光标移动到文档的开头

Vintage mode有一个键绑定用于这类事情:

{ "keys": ["g", "g"], "command": "set_motion", "args": {
    "motion": "vi_goto_line",
    "motion_args": {"repeat": 1, "explicit_repeat": true, "extend": true,
                    "ending": "bof" },
    "linewise": true },
    "context": [{"key": "setting.command_mode"}]
}

如何从插件中实现相同的效果或调用相同的命令?

在默认插件文件夹中,有一个名为goto_line.py的插件,它几乎完全实现了这一点

import sublime, sublime_plugin

class PromptGotoLineCommand(sublime_plugin.WindowCommand):

    def run(self):
        self.window.show_input_panel("Goto Line:", "", self.on_done, None, None)
        pass

    def on_done(self, text):
        try:
            line = int(text)
            if self.window.active_view():
                self.window.active_view().run_command("goto_line", {"line": line} )
        except ValueError:
            pass

class GotoLineCommand(sublime_plugin.TextCommand):

    def run(self, edit, line):
        # Convert from 1 based to a 0 based line number
        line = int(line) - 1

        # Negative line numbers count from the end of the buffer
        if line < 0:
            lines, _ = self.view.rowcol(self.view.size())
            line = lines + line + 1

        pt = self.view.text_point(line, 0)

        self.view.sel().clear()
        self.view.sel().add(sublime.Region(pt))

        self.view.show(pt)
导入升华,升华插件
类PromptGotoLineCommand(升华插件.WindowCommand):
def运行(自):
self.window.show_input_面板(“转到行:,”,self.on_done,None,None)
通过
def on_done(自我,文本):
尝试:
line=int(文本)
如果self.window.active\u view():
self.window.active_view().run_命令(“goto_-line”,“line”:line})
除值错误外:
通过
类GotoLineCommand(升华插件.TextCommand):
def运行(自我、编辑、行):
#从基于1的行号转换为基于0的行号
行=int(行)-1
#从缓冲区末尾开始计算负行号
如果行<0:
行,u=self.view.rowcol(self.view.size())
行=行+行+1
pt=自.视图.文本\点(线,0)
self.view.sel().clear()
self.view.sel().add(升华区域(pt))
self.view.show(pt)

谢谢!那是另一个我绝对应该去看的地方!:-)