Created
March 9, 2013 08:51
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
{ "keys": ["ctrl+shift+u"], "command": "insert_uuid" }, | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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