Fandom

Vim Tips Wiki

Send buffer to interpreter in a new xterm

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 944 Printable Monobook Previous Next

created June 4, 2005 · complexity intermediate · author Thomas Rowe · version 5.7


Without saving the current buffer you want to send its contents to an interpreter (python, scheme, whatever), and you want that interpreter to run in a freshly spawned xterm. A new xterm window is useful because running the shell within Vim does not allow simultaneously inspection of program output and the code buffer, and Vim's shell is weak in several respects.

Put this script in your path and make it executable:

#!/bin/sh
# This is for use from .vimrc files. It sends vim buffers to the specified
# interpreter.
if [ "$#" -lt 1 ]
then
  echo "ERROR: not enough args."
  echo "VIMRC USAGE: viminterpreter <interpretercommand>"
  exit 1
fi
TMP=`mktemp`
VM="$1" #command to run on the current buffer
cp /dev/stdin $TMP
xterm -e "\"$VM\" $TMP && rm $TMP && read"

Add the following to vimrc:

map ,p :w !viminterpreter python <CR>
map ,g :w !viminterpreter gosh <CR>

Now you can edit scheme code in an unsaved vim buffer and hit ",g" to see what it does. Or ",p" for python code.

CommentsEdit

Edit the last line in the script to read:

xterm -e "\"$VM\" $TMP; rm $TMP; read"

The original doesn't let you see the errors if your script fails.


Following should help:

:map ,p :!xterm -e "python \"<the_current_buffer>\"" &

Note that & at the end of the line.


Also on Fandom

Random Wiki