【问题标题】:Expand selection to custom line将选择扩展到自定义行
【发布时间】:2016-04-27 01:30:07
【问题描述】:

我想知道是否有开箱即用的方式,或者可以在SublimeText3中实现以下行为的插件。

我想将插入符号放在某行。然后选择所有文本,直到另一个行号。行数应该是可变的。

例如,将插入符号放在 10 上,然后将选择范围扩展到第 21 行或第 104 行。

我讨厌必须按住键或使用鼠标来执行此操作。

【问题讨论】:

    标签: sublimetext2 sublimetext3 sublimetext


    【解决方案1】:

    我编写了一个简单的插件,允许您通过input_panel 输入要选择的行:


    特点:

    • 双向工作
    • 尊重当前选择
    • 仅在有单个选择时执行

    设置信息:

    @ GitHub


    代码:

    import sublime, sublime_plugin
    
    class SelectToLineCommand( sublime_plugin.TextCommand ):
    
        def run( self, edit ):
    
            window     = self.view.window()
            selections = self.view.sel()
    
            if len( selections ) != 1:
                return
    
            self.currentSelection = selections[0]
    
            if self.currentSelection.a > self.currentSelection.b:
                self.currentSelection = sublime.Region( self.currentSelection.b, self.currentSelection.a )
    
            window.show_input_panel( "Select To Line Number", "", self.get_LineNumber, None, None )
    
        def get_LineNumber( self, userInput ):
    
            lineToRow_Offset = 1
            row = int( userInput ) - lineToRow_Offset
            selectionEnd_Row = self.view.text_point( row, 0 )
    
            currentSelection = self.currentSelection
    
            if selectionEnd_Row >= currentSelection.b:
                selectionStart = currentSelection.a
                selectionEnd   = self.view.line( selectionEnd_Row ).b
            elif selectionEnd_Row < currentSelection.a:
                selectionStart = currentSelection.b
                selectionEnd   = self.view.line( selectionEnd_Row ).a
    
            newSelection = sublime.Region( selectionStart, selectionEnd )
    
            self.view.selection.clear()
            self.view.selection.add( newSelection )
    

    【讨论】:

    • 该页面某处是否有下载链接?
    • @ScottF:不幸的是,GitHub 不允许下载特定的子目录,出于组织目的,我将所有答案脚本保存在一个存储库中。但是,您可以;下载我的Scripts Repo,解压子目录-SCRIPTS--master\SublimeText\[Misc]\[Proof Of Concept] SelectToLine\SelectToLine,然后删除压缩包。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    相关资源
    最近更新 更多