How to select next bookmark in sublime text 3

Is there a way to select text between the current cursor position and the next / previous bookmark in SublimeText3?

Key combinations shiftdo not work: shift F2goes to the previous bookmark ( shift+ F2= "go to the next bookmark"). Holding down shiftwhile selecting the "Next Bookmark" menu item also does not work.

+3


source to share


2 answers


You probably need a plugin for this. I just made this simple plugin that selects from the current cursor position to the next / previous bookmark based on the value of the front argument.

This is the plugin:

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)

      

Use "Tools"> "New Plugin" and use the provided plugin. Save it as SelectToBookmark.py. Finally, add keyBindings to your user file using something like this:



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

      

Use another keyBinding with the forward parameter set to false to select from the current position to the previous bookmark.

Edit: As user @MattDMo commented: "make sure you save the .py file in packages / User - you can find the directory on your system (if it doesn't appear automatically) by going to Settings -> Browse Packages ..." menu"

+5


source


Like @ sergioFC's answer. This version is used for the SublimeBookmark package .



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)

      

+2


source







All Articles