After some suggestions by Peter Battaglia, I rewrote the send.vim script to work better for its original purpose: sending text from vim to ipython. See the original post for the idea.
The send.vim script is now in the vim script repository:
The problem was that it’s not enough to send the text as-is. The ipython shell needs additional newlines to tell it when a code block ends at indentation level zero. Another problem are blank lines: a blank line in your source code might unintentionally end a code block when you send it to ipython. Hence, it’s best not to send empty lines at all.
The special behavior required for ipython meant that I had to extend the functionality of the script somewhat. I still want the plugin to be of general purpose, with all the ipython-specific behavior being optional. So, in addition to setting the
g:sendToProgramName variable, you also have to set the
g:sendToProgramMode to ‘ipython’ now in order to enable it.
It seems very feasible to add modes like this for other situations in the future.
In the reimplementation of the plugin, I also made it more robust to work per-buffer. In addition to the global settings (
g:sendToProgramName etc.), you can also give settings local to the buffer by setting (for example) the
b:sendToProgramName variable. Local settings, if present, override global settings. The plugin also keeps its internal state per buffer.