(→Python) |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ScriptComments |
+ | {{ScriptComments|UltiSnips: ultimate snippet solution for Python enabled Vim}} |
==Useful snippets== |
==Useful snippets== |
||
====Python==== |
====Python==== |
||
− | While debugging, I often print out variable names and their values. I defined the snippets ''echo'' (python 2) and ''e3'' (python 3) for this purpose like so in the file < |
+ | While debugging, I often print out variable names and their values. I defined the snippets ''echo'' (python 2) and ''e3'' (python 3) for this purpose like so in the file <code>~/.vim/UltiSnips/python.snippets</code>. Note that this snippet needs UltiSnips >= version 1.2. |
<pre> |
<pre> |
||
global !p |
global !p |
||
Line 12: | Line 12: | ||
endglobal |
endglobal |
||
− | snippet echo |
+ | snippet echo "The echo snippet" b |
print "${2}`!p snip.rv = echo_vals(t)`" % (${1}) |
print "${2}`!p snip.rv = echo_vals(t)`" % (${1}) |
||
endsnippet |
endsnippet |
||
snippet e3 "Python 3 echo" b |
snippet e3 "Python 3 echo" b |
||
− | + | print("${2}`!p snip.rv = echo_vals(t, '{}')`".format(${1})) |
|
endsnippet |
endsnippet |
||
</pre> |
</pre> |
Latest revision as of 09:46, 14 July 2012
Use this page to discuss script 2715 UltiSnips: ultimate snippet solution for Python enabled Vim
- Add constructive comments, bug reports, or discuss improvements (see the guideline).
- Do not document the script here (the author should do that on vim.org).
- This page may be out of date: check the script's vim.org page above, and its release notes.
Useful snippets[]
Python[]
While debugging, I often print out variable names and their values. I defined the snippets echo (python 2) and e3 (python 3) for this purpose like so in the file ~/.vim/UltiSnips/python.snippets
. Note that this snippet needs UltiSnips >= version 1.2.
global !p # Echo helper code def echo_vals(t, placeholder="%s"): return ', '.join(["%s: %s" % (a.strip(), placeholder) for a in t[1].split(',') if len(a.strip())]) endglobal snippet echo "The echo snippet" b print "${2}`!p snip.rv = echo_vals(t)`" % (${1}) endsnippet snippet e3 "Python 3 echo" b print("${2}`!p snip.rv = echo_vals(t, '{}')`".format(${1})) endsnippet