Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Plugins 要转到最后一行的插件_Plugins_Sublimetext2_Sublimetext_Sublimetext3 - Fatal编程技术网

Plugins 要转到最后一行的插件

Plugins 要转到最后一行的插件,plugins,sublimetext2,sublimetext,sublimetext3,Plugins,Sublimetext2,Sublimetext,Sublimetext3,我想为sublime text 3创建插件,它可以移动到打开文件的最后一行。现在,我可以通过它的编号转到第行: import sublime, sublime_plugin class prompt_goto_lineCommand(sublime_plugin.WindowCommand): def run(self): self.window.show_input_panel("Goto Line:", "", self.on_done, None, None)

我想为
sublime text 3
创建插件,它可以移动到打开文件的最后一行。现在,我可以通过它的编号转到第行:

import sublime, sublime_plugin

class prompt_goto_lineCommand(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 go_to_lineCommand(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)
导入升华,升华插件
类提示\u转到\u行命令(升华插件.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})
除值错误外:
通过
类go_to_lineCommand(升华插件.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)

但我不知道最后一排的号码。如何从object
sublime\u plugin.WindowCommand获取它?或者用另一种方法将光标移动到最后一行而不获取其编号?我试着在里面找?但是没有结果。

转到线路命令中的代码已经向您演示了如何计算最后一个行号
self.view.size()
返回文件中的字符数。因此
self.view.rowcol(self.view.size())
返回文档中最后一个
点的行号和列号。顺便说一句,
就像数组中的索引

因此,您可以通过计算最后一行号转到最后一行,或者只使用0作为行号

view.run_command("go_to_line", {'line':'0'})

go\u to\u lineCommand
中的代码已经向您演示了如何计算最后一个行号
self.view.size()
返回文件中的字符数。因此
self.view.rowcol(self.view.size())
返回文档中最后一个
点的行号和列号。顺便说一句,
就像数组中的索引

因此,您可以通过计算最后一行号转到最后一行,或者只使用0作为行号

view.run_command("go_to_line", {'line':'0'})

对于那些不打算专门构建插件并且正在使用Sublime Text 3的用户,您可能有兴趣了解ctrlend。我不太确定它是否也存在于Sublime Text 2中

当您特别想要构建一个插件时,您可以执行类似于buildinsublimetext3命令的操作,作为
goto\u行
解决方案的替代方案


{“keys”:[“ctrl+end”],“command”:“move_to”,“args”:{“to”:“eof”,“extend”:false}}

对于那些不打算专门构建插件并且正在使用Sublime Text 3的用户,您可能有兴趣了解ctrlend。我不太确定它是否也存在于Sublime Text 2中

当您特别想要构建一个插件时,您可以执行类似于buildinsublimetext3命令的操作,作为
goto\u行
解决方案的替代方案

{“keys”:[“ctrl+end”],“command”:“move_to”,“args”:{“to”:“eof”,“extend”:false}