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.

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

From: stackoverflow.com/q/18948491

Back to homepage or read more recommendations: