Skip to content

Instantly share code, notes, and snippets.

@bluemont
Created March 9, 2013 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluemont/5123538 to your computer and use it in GitHub Desktop.
Save bluemont/5123538 to your computer and use it in GitHub Desktop.
Generate and insert a random UUID. Works with multiple selections: * If there are no selections, insert the UUID at each cursor position. * If there are one or more selections, replace the selection(s) with the UUID. I've tested this in Sublime Text 3, but it may also work for Sublime Text 2.
[
{ "keys": ["ctrl+shift+u"], "command": "insert_uuid" },
]
import sublime, sublime_plugin, uuid
class InsertUuidCommand(sublime_plugin.TextCommand):
def run(self, edit):
uuid_string = str(uuid.uuid4())
for region in self.view.sel():
if region.empty():
self.view.insert(edit, region.a, uuid_string)
else:
self.view.replace(edit, region, uuid_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment