Sublime Forum

What are Edit objects?

#1

I’d like to make a Sublime Text 3 plugin that replaces some text in the current selection. To do this, I’m calling self.view.replace, which, according to the documentation, takes three arguments: replace(edit, region, string), returns None, and “replaces the contents of the region with the given string”. I’m confused about the first argument. The docs say that “edit objects are passed to TextCommands, and are not user createable” [1].

Let’s say I wanted to replace the selections with upper case versions. What can I replace “???” with below to make it work?

for r in self.view.sel():
    self.view.replace(???, r, self.view.substr(r).upper())
  1. sublimetext.com/docs/3/api_ … blime.Edit
0 Likes

#2

You get an edit object as default argument in the run methode by using the “sublime_plugin.TextCommand” - class.
But this object exists only inside this methode. It is not possible to pass the object as a parameter to a function.

class SomeCommand(sublime_plugin.TextCommand): def run(self, edit): # your code

0 Likes

#3

Perfect, thanks so much!

0 Likes