Skip to content

Instantly share code, notes, and snippets.

@qur2
Created January 5, 2012 21:34
Show Gist options
  • Save qur2/1567442 to your computer and use it in GitHub Desktop.
Save qur2/1567442 to your computer and use it in GitHub Desktop.
SublimeText shuffle selection command
import sublime, sublime_plugin, random
class ShuffleCommand(sublime_plugin.TextCommand):
def run(self, edit):
regions = self.view.sel()
selections = [self.view.substr(s) for s in regions]
selections = [shuffle_string(s) for s in selections]
for i in range(len(selections)):
self.view.replace(edit, regions[i], selections[i])
def shuffle_string(s):
return ''.join(shuffle_list(list(s)))
# need to be used from sort.py, but how to import that file ?
def shuffle_list(l):
random.shuffle(l)
return l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment