Like a lot of people, I write in Markdown, which has great reference-style links.

This is [some text][st] that I am writing.
[st]: http://sometext.com

I do my writing in Sublime Text 2, and I use these links all the time, but I never like to interrupt what I’m writing by searching for URLs. Instead, after I’ve finished writing, I then go through grab out the reference links to be researched.

With this goal, and with the documentation here’s how to create a simple plugin or package for Sublime Text 2.

Hit Save, which will open a dialog in the Packages/User directory.
We don’t want this. Instead, create a new directory within
the Packages directory. Call it Extract Markdown Links.
So, after this, there should be a directory called
Packages/Extract Markdown Links. Save the file there, and
call it Markdown Links.py.

import the necessary modules—the two sublime modules for access to the API and re for regular expressions.

MarkdownLinksCommand is the name of the class. Note that this name has to correspond to markdown_links (under the key command) in the file Default.sublime-commands. Strip Command, convert camel-case to underscores, and make everything lowercase to get from the class name to the command.

self.view.substr with this region gets the contents of the currently active document, from the first character to the last.

Extract the matches from the contents.

Insert the matches, inserting colons and new lines, at the current cursor location.

Now you should be able to run your command. Open up a Markdown file with some reference links, hit Command + Shift + P, and search for ‘Extract Markdown Reference Links’.