9

I want to be able to insert import ipdb; pdb.set_trace() on the line below where I am on a key press. For obvious reasons ;-)

2 Answers 2

17

Two fairly easy ways to do this:

Create a snippet... go to Tools>Developer>New snippet, bung this in:

<snippet>
    <content><![CDATA[import ipdb; pdb.set_trace()]]></content>
    <tabTrigger>p</tabTrigger>
</snippet>

save it.. should start working straight away.

  • Ctrl + Enter (puts you onto a new next line),
  • p + Tab (inserts your snippet).

4 key strokes.

OR

You could use the macro tool:

  • Ctrl+Alt+Q (start recording macro)
  • Ctrl+Enter (puts you onto a new next line)
  • type: import ipdb; pdb.set_trace()
  • Ctrl+Alt+Q (end recording macro)

Now save your_macro.sublime-macro (Tools>Save macro), and add this key binding to your user key bindings:

{ "keys": ["p"], "command": "run_macro_file", 
"args": {"file": "Packages/User/your_macro.sublime-macro"} }

now 'p' will insert your text, on the next line..

1 key stroke... but you must be careful to write code that never needs the letter p... ;)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! The ctr+alt+q doesn't work in OS X. But From the menu I got it to work. And of course changed the key to something else, ctr+p in this case.
Wow, this has to be the clunkiest way to set up key binds in an editor ever. Well, even setting settings is clunky. Too lazy to make a settings editor, I think.
3

On Mac OS X I have to save it with extension:

.sublime-snippet

to get it working.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.