Skip to content

Instantly share code, notes, and snippets.

@GuyCarver
Created November 25, 2012 10:31
Show Gist options
  • Save GuyCarver/4143021 to your computer and use it in GitHub Desktop.
Save GuyCarver/4143021 to your computer and use it in GitHub Desktop.
Pythonista editor script to paste clipboard to buffer.
#paste clipboard to buffer.
import clipboard
import editor
cliptext = clipboard.get()
if cliptext != '':
text = editor.get_text()
selection = editor.get_selection()
selected_text = text[selection[0]:selection[1]]
replacement = cliptext + selected_text
editor.replace_text(selection[0], selection[1], replacement)
# editor.set_selection(selection[0], selection[0] + len(replacement) - 1)
@GuyCarver
Copy link
Author

I find it easier to paste with this command rather than attempting to use the popup menu.

@cclauss
Copy link

cclauss commented Aug 20, 2013

# Paste the current clipboard text into the editor replacing the current selection.
import clipboard, editor
cliptext = clipboard.get()
if cliptext:
    selection = editor.get_selection()
    editor.replace_text(selection[0], selection[1], cliptext)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment