The ultimate Vim configuration: vimrc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

456 lines
8.6 KiB

snippet #!
#!/usr/bin/env python3
snippet #!2
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
snippet #!3
#!/usr/bin/env python3
snippet imp
import ${0:module}
snippet uni
def __unicode__(self):
snippet from
from ${1:package} import ${0:module}
# Module Docstring
snippet docs
File: ${1:`vim_snippets#Filename('$', '')`}
Author: `g:snips_author`
Email: `g:snips_email`
Github: `g:snips_github`
Description: ${0}
# Unittest skip
snippet sk "skip unittests" b
snippet wh
while ${1:condition}:
# dowh - does the same as do...while in other languages
snippet dowh
while True:
if ${0:condition}:
snippet with
with ${1:expr} as ${2:var}:
snippet awith
async with ${1:expr} as ${2:var}:
# 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
snippet cla
class ${1:class_name}:
snippet clai
class ${1:class_name}:
def __init__(self, ${3:args}):
# New Function
snippet def
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
"""${3:docstring for $1}"""
snippet deff
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
snippet adef
async def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
"""${3:docstring for $1}"""
snippet adeff
async def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
# New Method
snippet defi
def __init__(self, ${1:args}):
snippet defm
def ${1:mname}(self, ${2:arg}):
snippet adefm
async def ${1:mname}(self, ${2:arg}):
# 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}
def fdel(self):
${0:del self._$1}
return locals()
$1 = property(**$1())
# Ifs
snippet if
if ${1:condition}:
snippet el
snippet ei
elif ${1:condition}:
# For
snippet for
for ${1:item} in ${2:items}:
# Encodes
snippet cutf8
# -*- coding: utf-8 -*-
snippet clatin1
# -*- coding: latin-1 -*-
snippet cascii
# -*- coding: ascii -*-
# Lambda
snippet ld
${1:var} = lambda ${2:vars} : ${0:action}
snippet ret
return ${0}
snippet .
snippet try Try/Except
except ${2:Exception} as ${3:e}:
${0:raise $3}
snippet trye Try/Except/Else
except ${2:Exception} as ${3:e}:
${4:raise $3}
snippet tryf Try/Except/Finally
except ${2:Exception} as ${3:e}:
${4:raise $3}
snippet tryef Try/Except/Else/Finally
except ${2:Exception} as ${3:e}:
${4:raise $3}
# if __name__ == '__main__':
snippet ifmain
if __name__ == '__main__':
# __magic__
snippet _
# python debugger (pdb)
snippet pdb
# bpython debugger (bpdb)
snippet bpdb
# ipython debugger (ipdb)
snippet ipdb
# embed ipython itself
snippet iem
# remote python debugger (rpdb)
snippet rpdb
# web python debugger (wdb)
snippet wdb
# ptpython
snippet ptpython
__import__('ptpython.repl', fromlist=('repl')).embed(globals(), locals(), vi_mode=${1:False}, history_filename=${2:None})
# python console debugger (pudb)
snippet pudb
# pdb in nosetests
snippet nosetrace
snippet pprint
snippet "
# assertions
snippet a=
self.assertEqual(${0}, ${1})
# test function/method
snippet test
def test_${1:description}(${2:`indent('.') ? 'self' : ''`}):
# test case
snippet testcase
class ${1:ExampleCase}(unittest.TestCase):
def test_${2:description}(self):
# test given when then
snippet tgwt
# given: ${1}
# when: ${2}
# then: ${3}
snippet fut
from __future__ import ${0}
snippet getopt
# Short option syntax: "hv:"
# Long option syntax: "help" or "verbose="
opts, args = getopt.getopt(sys.argv[1:], "${1:short_options}", [${2:long_options}])
except getopt.GetoptError, err:
# Print debug info
print str(err)
for option, argument in opts:
if option in ("-h", "--help"):
elif option in ("-v", "--verbose"):
verbose = argument
# argparse
snippet addp
parser = ${VISUAL:argparse.}ArgumentParser()
snippet addsp
${0:sub_parser} = parser.add_subparsers().add_parser("${1:name}")
snippet addarg
parser.add_argument("${0:short_arg}", "${1:long_arg}", default=${2:None}, help="${3:Help text}")
snippet addnarg
parser.add_argument("${0:arg}", nargs="${1:*}", default"${2:None}, help="${3:Help text}")
snippet addaarg
parser.add_argument("${0:arg}", "${1:long_arg}", action="${2:store_true}", default=${3:False}, help="${4:Help text}")
snippet pargs
"${VISUAL:return }"parser.parse_args()
# logging
# glog = get log
snippet glog
import logging
LOGGER = logging.getLogger(${0:__name__})
snippet le
# conflict with lambda=ld, therefor we change into Logger.debuG
snippet lg
snippet lw
snippet lc
snippet li${0:msg})
snippet epydoc
@param ${2:param}: ${3: Description}
@type $2: ${4: Type}
@return: ${5: Description}
@rtype : ${6: Type}
@raise e: ${0: Description}
snippet dol
def ${1:__init__}(self, *args, **kwargs):
super(${0:ClassName}, self).$1(*args, **kwargs)
snippet kwg
self.${1:var_name} = kwargs.get('$1', ${2:None})
snippet lkwg
${1:var_name} = kwargs.get('$1', ${2:None})
snippet args
snippet kwargs
snippet akw
*args, **kwargs${1:,}${0}
# comprehensions
snippet lcp list comprehension
[${1} for ${2} in ${3:${VISUAL}}]${0}
snippet dcp dict comprehension
{${1}: ${2} for ${3} in ${4:${VISUAL}}}${0}
snippet scp set comprehension
{${1} for ${2} in ${3:${VISUAL}}}${0}
snippet contain "methods for emulating a container type" b
def __len__(self):
def __getitem__(self, key):
def __setitem__(self, key, value):
def __delitem__(self, key):
def __iter__(self):
def __reversed__(self):
def __contains__(self, item):
snippet context "context manager methods" b
def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
snippet attr "methods for customizing attribute access" b
def __getattr__(self, name):
def __setattr__(self, name, value):
def __delattr__(self, name):
snippet desc "methods implementing descriptors" b
def __get__(self, instance, owner):
def __set__(self, instance, value):
def __delete__(self, instance):
snippet cmp "methods implementing rich comparison"
def __eq__(self, other):
def __ne__(self, other):
def __lt__(self, other):
def __le__(self, other):
def __gt__(self, other):
def __ge__(self, other):
def __cmp__(self, other):
snippet repr "methods implementing string representation"
def __repr__(self):
def __str__(self):
def __unicode__(self):
# note: reflected operands and augmented arithmeitc assignements have been
# intentionally ommited to reduce verbosity.
snippet numeric "methods for emulating a numeric type" b
def __add__(self, other):
def __sub__(self, other):
def __mul__(self, other):
def __div__(self, other):
def __truediv__(self, other):
def __floordiv__(self, other):
def __mod__(self, other):
def __divmod__(self, other):
def __pow__(self, other):
def __lshift__(self, other):
def __rshift__(self, other):
def __and__(self, other):
def __xor__(self, other):
def __or__(self, other):
def __neg__(self):
def __pos__(self):
def __abs__(self):
def __invert__(self):
def __complex__(self):
def __int__(self):
def __long__(self):
def __float__(self):
def __oct__(self):
def __hex__(self):
def __index__(self):
def __coerce__(self, other):