vim-snippets/snippets/python.snippets

143 lines
2.9 KiB
Plaintext
Raw Normal View History

snippet #!
#!/usr/bin/env python
snippet imp
import ${1:module}
2011-10-19 17:56:00 -04:00
snippet from
from ${1:package} import ${2:module}
# Module Docstring
snippet docs
'''
File: ${1:`Filename('$1.py', 'foo.py')`}
Author: ${2:`g:snips_author`}
Description: ${3}
'''
snippet wh
while ${1:condition}:
${2:# TODO: write code...}
# dowh - does the same as do...while in other languages
snippet dowh
while True:
${1:# TODO: write code...}
if ${2:condition}:
break
snippet with
with ${1:expr} as ${2:var}:
${3:# TODO: write code...}
# New Class
snippet cl
class ${1:ClassName}(${2:object}):
"""${3:docstring for $1}"""
def __init__(self, ${4:arg}):
${5:super($1, self).__init__()}
self.$4 = $4
${6}
# New Function
snippet def
2011-08-03 10:59:11 -04:00
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
"""${3:docstring for $1}"""
${4:# TODO: write code...}
snippet deff
2011-08-03 10:59:11 -04:00
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
${3:# TODO: write code...}
# New Method
snippet defs
2011-08-03 10:59:11 -04:00
def ${1:mname}(self, ${2:arg}):
${3:# TODO: write code...}
# New Property
snippet property
def ${1:foo}():
doc = "${2:The $1 property.}"
def fget(self):
${3:return self._$1}
def fset(self, value):
${4:self._$1 = value}
2011-07-16 11:21:36 -04:00
# Ifs
snippet if
if ${1:condition}:
${2:# TODO: write code...}
2011-07-23 19:06:58 -04:00
snippet el
2011-07-16 11:21:36 -04:00
else:
${1:# TODO: write code...}
2011-07-23 19:06:58 -04:00
snippet ei
elif ${1:condition}:
${2:# TODO: write code...}
2011-07-16 11:21:36 -04:00
# For
snippet for
2011-12-10 14:02:31 -05:00
for ${1:item} in ${2:items}:
${3:# TODO: write code...}
2011-07-16 11:21:36 -04:00
# Encodes
2011-08-02 20:01:39 -04:00
snippet cutf8
2011-07-16 11:21:36 -04:00
# -*- coding: utf-8 -*-
snippet clatin1
# -*- coding: latin-1 -*-
snippet cascii
# -*- coding: ascii -*-
# Lambda
snippet ld
${1:var} = lambda ${2:vars} : ${3:action}
snippet .
guard left =~ '^\s*$'
self.
snippet try Try/Except
try:
${1:# TODO: write code...}
except ${2:Exception}, ${3:e}:
${4:raise $3}
snippet try Try/Except/Else
try:
${1:# TODO: write code...}
except ${2:Exception}, ${3:e}:
${4:raise $3}
else:
${5:# TODO: write code...}
snippet try Try/Except/Finally
try:
${1:# TODO: write code...}
except ${2:Exception}, ${3:e}:
${4:raise $3}
finally:
${5:# TODO: write code...}
snippet try Try/Except/Else/Finally
try:
${1:# TODO: write code...}
except ${2:Exception}, ${3:e}:
${4:raise $3}
else:
${5:# TODO: write code...}
finally:
${6:# TODO: write code...}
# if __name__ == '__main__':
snippet ifmain
if __name__ == '__main__':
${1:main()}
# __magic__
snippet _
__${1:init}__${2}
# python debugger (pdb)
snippet pdb
import pdb; pdb.set_trace()
# ipython debugger (ipdb)
snippet ipdb
import ipdb; ipdb.set_trace()
# ipython debugger (pdbbb)
snippet pdbbb
import pdbpp; pdbpp.set_trace()
2012-07-03 03:40:37 -04:00
snippet pprint
import pprint; pprint.pprint(${1})${2}
2011-07-07 14:41:13 -04:00
snippet "
"""
${1:doc}
"""
2011-10-31 13:01:25 -04:00
# test function/method
snippet test
def test_${1:description}(${2:`indent('.') ? 'self' : ''`}):
${3:# TODO: write code...}
2011-10-31 13:01:25 -04:00
# test case
snippet testcase
class ${1:ExampleCase}(unittest.TestCase):
def test_${2:description}(self):
${3:# TODO: write code...}
snippet fut
from __future__ import ${1}