I have zero experience with Python but I would like to create, what I hope will be, a fairly simple personal plugin.
When editing text and markdown files, I would like to be able to skip from sentence to sentence. This is table-stakes stuff for emacs/Vim but I miss it in Sublime.
I have been watching most of Odatnurd’s Youtube playlist on plugin dev so now have some basic understanding of how plugins work. What I am struggling with, besides trying to understand how Python does things, is knowing what the appropriate methods are from the API for what I want to achieve. I’ll admit to being a little overwhelmed!
My intention is two have two commands: move_to_character
and move_back_to_character
, with the idea being that when you set the keymap, you can pass the character (maybe regex pattern as a string??) you are interested in moving forwards/backwards to.
My humble beginnings look like this:
def run(self, edit):
sels = self.view.sel()
for sel in sels:
if self.view.substr(sel).find('.') != -1:
foundForward = True
What methods exist to move backwards through the buffer? Is rfind
with the cursor pos as the index the way to go? Something like character_behind = self.view.substr(sel).rfind('.', 0, cursorPos)
??
Once I have moved to the location, what methods should I be using to set the new cursor position?
Thanks for any pointers!