Last Updated: September 09, 2019
·
7.186K
· oleiade

Sublime text 2 usefull python snippets

I find myself repeting some repetitive operations dozen times a day when coding in python.

So here are so of my Sublime Text 2 snippets to enhance my productivity, and simplify my life.

Type pdb and press tab to automatically insert import pdb; pdb.set_trace under current pointer

<snippet>
    <content><![CDATA[
        import pdb; pdb.set_trace()
    ]]></content>
    <tabTrigger>pdb</tabTrigger>
    <scope>source.python</scope>
</snippet>

Type docstring and press tab to automatically insert a numpy-style valid
docstring pattern right after your function definition

<snippet>
    <content><![CDATA[
    """${1:One liner description}

    Parameters
    ----------
    ${2}
    Returns
    -------
    ${3}
    """
    ]]></content>
    <tabTrigger>docstring</tabTrigger>
    <scope>source.python</scope>
    <description>Adds a docstring skeleton to function</description>
</snippet>

Type testcase and press tab to automatically insert a unittest.TestCase test class definition pattern

<snippet>
    <content><![CDATA[
    class ${1:ClassTestName}(unittest.TestCase):
        def setUp(self):
            ${2:pass}

        def tearDown(self):
            ${3:pass}

    ]]></content>
    <tabTrigger>testcase</tabTrigger>
    <scope>source.python</scope>
    <description>Adds a unittest TestCase skeleton at current pointer</description>
</snippet>

2 Responses
Add your response

where(in which file) to add the above snippets?

over 1 year ago ·

You can add snippet-files into -
~/.config/sublime-text-2/Packages/User/

Or somewhere else, in Sublime-Text config directory.

Use "tools->New Snippet..." for create new snippet.

over 1 year ago ·