Python and Vim

From Schmid.wiki
Jump to: navigation, search

Contents

Python Evaluation

Single-line Evaluation

:py print "hello"

Output From Python into Vim

:r!python -c "import math;print math.pi"

Multi-line Evaluation

:py<<
for n in range(11):
 print n*n
.

Run Python Script On File

Try this little thing:

from vim import *
from math import *
command('exe "normal gg/#[-\ ]*end\ of\ code\<Cr>jdG"') # delete everything below 'end of code'
aa = " .:+*xX08"
for y in range(32):
    current.buffer.append("#"+" "*int(sin(y/3.)*36+40)+"*")
# --- end of code ---

Paste it into Vim, save it and execute the command :pyf <filename of program>

If you want more of this stuff, see Python ASCII Art for some pretty crazy examples...

Personal tools