AFAIK, there's no way to execute the find/replace dialog as a command (which would make this easy, and also would make me very happy because I often want to be able to include find/replace in a macro).
You'll need to ask the view for the lines, and then insert a tab or replace the line with a tab at the beginning. You'll need to be careful, because as soon as you insert a tab, this will shift the offset for all subsequent lines. Here is some sample code that should do what you want:
- Code: Select all
def run(self, edit):
for r in reversed(self.view.sel()):
for line_r in reversed(self.view.lines(r)):
# Alternatively, use view.insert() here if you're not
# concerned about tabs getting converted to spaces.
text = self.view.substr(line_r)
self.view.replace(edit, line_r, '\t'+text)
An alternative approach is to extract all the line regions into a python list, clear self.view.sel(), and then add them to self.view.sel(). Then iterate over self.view.sel() and call substr/replace or insert(). When you modify regions in a RegionSet, they automatically get adjusted (so you don't have to do things in reverse). But this would be a bit more complex than the above example.