adi adi - 9 months ago 78
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