adi adi - 3 years ago 226
Python Question

Running Python code in Vim

I am writing Python code using Vim, and every time I want to run my code, I type this inside Vim:

:w !python

This gets frustrating, so I was looking for a quicker method to run Python code inside Vim. Executing Python scripts from a terminal maybe?
I am using Linux.

Answer Source

how about adding an autocmd, when FileType python, create a mapping:

nnoremap <buffer> <F9> :exec '!python' shellescape(@%, 1)<cr>

then you could press <F9> to execute the current buffer with python

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download