My ideal scenario would be to have Vim split into two windows – first containing the script (python) that I am currently working on and the other showing the result of evaluating that script. This is what I have so far:
:autocmd BufWritePost *.py redir @p | execute 'silent w !python -' | redir END
When saving the script, the contents of the script is piped to the python command, the output of that command is stored in register p. What is the best way to get p into a new/empty buffer displayed in the other window?
Some things I have tried is blast | normal! "pp | bfirst (blast: new/empty buffer, bfirst: buffer containing python script) but this seems to leave me in the “output” buffer and for whatever reason I lose syntax highlighting and need to flip back and forth between the buffers to get it back. I would really like to do this all in place and avoid generating a temp dump file where I pipe the output of running the script and would prefer to avoid using any other external tools to “watch” the python script file and do something when it changes.
My approach was to use the preview window. This allows you to always move to the correct window no matter how many windows you have. It also allows you to “ignore” the fact that the preview window is open when you want to exit vim (you can just do
:qrather than:qafor instance).There may be a less verbose way to accomplish this but it appears to work pretty well as is.