def run(self, edit):
# Get the content of the clipboard, trim leading and trailing white
# space and then split it into lines; turn the resulting value (a list
# of strings) into a list of integers that represent the line numbers.
clipboard = sublime.get_clipboard().strip().split('\n')
lines = [int(n) for n in clipboard]
self.view.window().status_message('clipboard contains non-numerics')
# The values we have are lines; convert them into positions into the
# buffer at which each of those lines would start; the values we pass
# are zero based.
points = [self.view.text_point(line - 1, 0) for line in lines]
# Using the points, clear the selection and then add in a new selection
# region for each; this positions a cursor at the start of each line.
for point in points:
This will do what you want, though I would recommend looking at the API documentation to see the methods used here and why/how they’re doing what they’re doing.
This includes some simple error checking for making sure that the contents of the clipboard is only numbers.
Additionally, if the clipboard contains lines that don’t exist, the cursor will get placed at the next closest line (so for example if the clipboard contained
30 but the file only has 27 lines, the cursor ends up on line 27). If you don’t want that then you need to limit the values in the
lines array to values smaller than
self.view.rowcol(len(self.view))+1, which is the 1 based line number of the last line of the file.
Cursors that end up at the same position are merged together automatically by Sublime.