首页 文章

如何选择sublime文本3中的下一个书签

提问于
浏览 1983
3

有没有办法在SublimeText3中选择当前光标位置和下一个/上一个书签之间的文本?

使用shift键的组合不起作用:shiftF2转到上一个书签(移位F2 = "go to the next bookmark") . 选择"next bookmark"菜单项时按住shift也不起作用 .

2 回答

  • 7

    为了做到这一点,你可能需要一个插件 . 我刚刚创建了这个简单的插件,它根据forward参数的值从当前光标位置选择下一个/上一个书签 .

    这是插件:

    import sublime, sublime_plugin
    
    class SelectToBookmarkCommand(sublime_plugin.TextCommand):
        def run(self, edit, **args):
            """Get initial position"""
            initialPoint = self.view.sel()[0].begin()
    
            """Clear selected things (if any)"""
            self.view.sel().clear()
    
            """Move to next bookmark or previous bookmark"""
            forward = args.get('forward','true')
            if forward is True:
                self.view.run_command("next_bookmark")
            else:
                self.view.run_command("prev_bookmark")
    
    
            """Get current position (position of the bookmark)"""
            finalPoint = self.view.sel()[0].begin()
    
            """Clear selected things (if any)"""
            self.view.sel().clear()
    
            """Region to select"""
            regionToSelect = sublime.Region(initialPoint, finalPoint)
    
            """Add the region to the selection"""
            self.view.sel().add(regionToSelect)
    

    使用工具>新插件并使用提供的插件 . 将其另存为SelectToBookmark.py . 最后,使用以下内容将keyBindings添加到用户文件中:

    {
        "keys": ["ctrl+alt+e"],
        "command": "select_to_bookmark",
        "args": {"forward": true}
    }
    

    使用另一个keyBinding,并将forward参数设置为false,以从当前位置选择到上一个书签 .

    编辑:正如用户@MattDMo评论:“确保将.py文件保存在Packages / _751173中 - 您可以通过选择首选项 - >浏览包来找到系统上的目录(如果它没有自动出现) . ..菜单选项“

  • 3

    类似于@ sergioFC的回答 . 此版本用于SublimeBookmark包 .

    import sublime, sublime_plugin
    
    class SelectToBookmarkCommand(sublime_plugin.TextCommand):
        def run(self, edit, **args):
            """Get initial position"""
            initialPoint = self.view.sel()[0].begin()
    
            """Clear selected things (if any)"""
            self.view.sel().clear()
    
            """Move to next bookmark or previous bookmark"""
            forward = args.get('forward','true')
            if forward is True:
                self.view.window().run_command("sublime_bookmark",{ "type" : "goto_previous" })
            else:
                self.view.window().run_command("sublime_bookmark",{ "type" : "goto_next" })
    
    
            """Get current position (position of the bookmark)"""
            finalPoint = self.view.sel()[0].begin()
    
            """Clear selected things (if any)"""
            self.view.sel().clear()
    
            """Region to select"""
            regionToSelect = sublime.Region(initialPoint, finalPoint)
    
            """Add the region to the selection"""
            self.view.sel().add(regionToSelect)
    

相关问题