See
http://vim-ruby.rubyforge.org.
The released files are quit out of date (/me smacks himself), so grab
a CVS tarball. It'll all be sorted out when Vim 6.3 arrives.
And please share your Python vim extension scripts. I'm eager to see
what they do.
Cheers,
Gavin
Most of this is pretty grotesque, but it works relatively well. I wanted
to come up with a way to make redirect stdout so that print would send
content to a scratch buffer. I set it up so that I could assign an
execution command to filetypes using autocmd. It executes that command on
the content, and then puts the output in the scratch buffer. if the
scratch buffer doesnt exist yet, it creates it. The way it finds the
scratch buffer is really kludgy, but I couldnt think of a better way.
The 'PyValOut' function is kind of neat. It takes the selected content in
the current buffer and evaluates it through the embedded interpreter and
dumps the content to the scratch buffer. I use this instead of interactive
mode a lot of the time. I use this stuff regularly for several languages
including ruby.
My CamlComment function is kind of funky, it puts ocaml comments around
the text of the current line, respecting starting whitespace. The
CamlRunAct function is a quick and dirty shortcut I use to control whether
I want the file to be run through the ocaml interpreter, or the compiler,
or something else entirely. I'll probably port all this to ruby as soon as
I get ruby/vim working, and figure out how to redirect stdout.
"""""" SegPhault's .vimrc
""" Python Stuff
python << EOF
from vim import *
import sys,commands
def first(c,l):
for x in l:
if c(x): return x
txtsplit = '-'*20
CB = lambda: current.buffer
io = sys.stdout,sys.stderr
getBuf = lambda x:first(x,buffers)
pybuf = lambda x:x[0].startswith('Program Output')
prepend = lambda l,t: l[:len(l)-len(l.lstrip())] + t + l.lstrip()
def rep(t,l):
for x in l.items():
t = t.replace(x[0],x[1])
return t
def getSel(l1,l2):
return '\n'.join(current.buffer.range(int(l1),int(l2))[:])+'\n'
class vBuf:
def __init__(s,b=None):
s.buf = b and b or getBuf(pybuf)
if not s.buf:
command(':bel new')
command(':set bt=nofile')
s.buf = current.buffer
s.clear()
def write(s,t):
if '\n' in t: map(s.buf.append,t.split('\n'))
else: s.buf[-1]+=t
def clear(s):
s.buf[:] = None
s.buf[-1] = 'Program Output Buffer'
s.buf.append('-'*20)
s.buf.append('')
def redirbuf(b=None):sys.stdout = sys.stderr = vBuf(b)
def resetbuf():sys.stdout,sys.stderr = io
def PyValOut(r):
redirbuf()
exec(r)
print txtsplit
resetbuf()
def PyExOut(r):
redirbuf()
print commands.getstatusoutput(r)[1]
print txtsplit
resetbuf()
def FileDir(x): return '/'.join(x.split('/')[:-1])
def ToFileDir(): command('lcd '+FileDir(current.buffer.name))
EOF
"""" General Stuff
let mapleader = ","
map <Leader>s :source %<cr>
map <leader>b :MiniBufExplorer<cr>
imap <C-S> <Esc>:w<cr>a
imap <C-D> <C-R>=strftime("%x")<cr>
imap <M-;> <Esc>
imap <C-L> <Esc>$a<Return>
imap <C-E> <Esc>,c:w<cr>,,a
command! ToFileDir py ToFileDir()
"""" C Stuff
map <Leader>mc :source /usr/share/vim/vim62/extraPlugins/c.vim<cr>:syntax on<cr>
map <Leader>ind :%!indent<cr>
"""" Python Stuff
command! -range Pval py PyValOut(getSel(<f-line1>,<f-line2>))
map <leader>c
y vBuf().clear()<cr>
autocmd BufEnter *.py map <Leader>,
y PyExOut('python '
+current.buffer.name)<cr>
"""" XML Stuff
autocmd BufEnter *.xsl map <Leader>.
y curxsldoc = current.buffer.name<cr>
autocmd BufEnter *.xml map <Leader>,
y PyExOut('xsltproc %s
%s'%(curxsldoc,current.buffer.name))<cr>
"""" Ocaml Stuff
python << EOF
def camlComment():
l = current.line
current.line = l.strip().startswith('(*')\
and rep(l,{'(* ':'',' *)':''})\
or prepend(l,'(* ') + ' *)'
def camlRunAct():
return CB()[0].startswith('(* Build:')\
and CB()[0][CB()[0].find(':')+2:].replace('%',CB().name)\
or 'ocaml %s'%CB().name
EOF
autocmd BufEnter *.ml map <Leader>,
y PyExOut(camlRunAct())<cr>
autocmd BufEnter *.ml imap <C-C> (* *)<Esc>hhi
autocmd BufEnter *.ml map <C-C>
y camlComment()<cr>
""" Makefile Stuff
autocmd BufEnter Makefile map <Leader>,
y PyExOut('make exec')<cr>
autocmd BufEnter Makefile map <Leader>.
y PyExOut('make clean')<cr>
""" Ruby Stuff
autocmd BufEnter *.rb map <Leader>,
y PyExOut('ruby '+current.buffer.name)<cr>
""" colorscheme
command! FoldDarkBG :highlight Folded guifg=purple guibg=black