Sublime Forum

Jump to line which matches regular expression

#1

Hey guys,

I am trying to write my first plugin and I need some help.
I want the plugin to jump to the next/previous line which matches the regular expression: ^\s*$
I also want to control selection.
(My end goal is 4 keybindings: next line match, next line match with selection, previous line match, previous line match with selection)

Thanks!

0 Likes

#2

Do you have any code or ideas so far as to how you want to tackle this?

If you use view.sel() you can determine the location that the cursor is at in the current file. view.find_all() can take a regular expression and tell you all of the locations in the file where it matches.

Using those two endpoints you can find all of the matches and determine which ones are closest to the location the cursor is at to know which one is next or previous.

You can also modify the result of view.sel() to change the cursor location; in doing so you can either jump the cursor to a specific point in the file or do that in addition to selecting text.

For this you want to create a TextCommand and use it’s self.view property to search in/manipulate the contents of whatever file is focused when you execute the command.

0 Likes