First of all, you will need ** to write your python parts so that the data is read from stdin and then output to stdout. Then you can apply your code in the following style:
fun! DoMyPythonThing() range exec ":'<,'>! python ./path/to/your/script.py" endfun vnoremap <F3> :call DoMyPythonThing()<CR>
Ex Team Idea:! lies in the fact that you give it an executable program, and vim passes the rendered text to it and replaces the area with the program output.
Notice the range in the function definition. Pay attention to the mapping, which we restrict only to visual mode displays. If you also like to wave your mouse, think about how to display in select mode.
**) Well, you can write in-vim python to accomplish this, but it's harder to check, and you went with the program's external route by calling ! anyway.
source share