Chuck Mason wrote:
Try this the function below.  I'm a very novice vim programmer so
forgive me if there's an easier way to do this.  However, what's below
seemed to work for me.
Chuck




function! ExecuteCurBufAsPython()
        let buffer = getline(1, line("$"))
        let newbuf = ""
        let index = 0
        while index < len(buffer)
                let line = buffer[index]
                let newbuf = newbuf . "\n" . line
                let index = index + 1
        endwhile
        execute "python " . newbuf
endfunc

:nmap <F5> :call ExecuteCurBufAsPython()

To pass the current buffer (which must have a valid filename) to the Python interpreter and run it as a Python script:

        :w
        :pyfile %

or
        :map    <F5>      w<Bar>pyfile %

If ":pyfile %" doesn't work (I think it will), then use

        :exec "pyfile" expand("%")

instead.


Best regards,
Tony.

Reply via email to