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
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... ;)
2 Comments
Sjoerd
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.
Henrik Erlandsson
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.