Python breakpoints in Sublime Text

I love Sublime Text 2 - it has replaced Visual Studio and even the venerable TextMate for Python hacking. Sublime doesn't have great support for debugging - you have to add breakpoints using code the old-fashioned way. For example, if you have some Python code:

x = 5
x = x + 1

and you want to add a breakpoint, you typically do something like this:

x = 5
import ipdb; ipd.set_trace()
x = x +1

Now when you run this script, as long as you have ipdb installed, you will be able to start debugging in your Python interpreter. Adding this text can quickly become tedious in Sublime. Here's a quick trick to enter this breakpoint:

  1. Click Tools > New Snippet

  2. Save the following as /User/breakpoint.sublime-snippet

    ipdb source.python

Now, when you type ipdb you can tab-complete to enter this text.