Skip to content

Instantly share code, notes, and snippets.

@GuyCarver
Created November 25, 2012 10:28
Show Gist options
  • Save GuyCarver/4143014 to your computer and use it in GitHub Desktop.
Save GuyCarver/4143014 to your computer and use it in GitHub Desktop.
Pythonista editor script to unindent selected lines.
#unindent selection
import editor
text = editor.get_text()
selection = editor.get_line_selection()
selected_text = text[selection[0]:selection[1]]
replacement = ''
for line in selected_text.splitlines():
replacement += line[line.find('\t') + 1:] + '\n'
editor.replace_text(selection[0], selection[1], replacement)
editor.set_selection(selection[0], selection[0] + len(replacement) - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment