Wikia

Vim Tips Wiki

Changes: Send buffer to interpreter in a new xterm

Edit

Back to page

(Adjust previous/next navigation)
(Remove html character entities)
 
Line 23: Line 23:
 
then
 
then
 
echo "ERROR: not enough args."
 
echo "ERROR: not enough args."
echo "VIMRC USAGE: viminterpreter <interpretercommand>"
+
echo "VIMRC USAGE: viminterpreter <interpretercommand>"
 
exit 1
 
exit 1
 
fi
 
fi
Line 29: Line 29:
 
VM="$1" #command to run on the current buffer
 
VM="$1" #command to run on the current buffer
 
cp /dev/stdin $TMP
 
cp /dev/stdin $TMP
xterm -e "\"$VM\" $TMP &amp;&amp; rm $TMP &amp;&amp; read"
+
xterm -e "\"$VM\" $TMP && rm $TMP && read"
 
</pre>
 
</pre>
   
Line 35: Line 35:
   
 
<pre>
 
<pre>
map ,p :w !viminterpreter python &lt;CR&gt;
+
map ,p :w !viminterpreter python <CR>
map ,g :w !viminterpreter gosh &lt;CR&gt;
+
map ,g :w !viminterpreter gosh <CR>
 
</pre>
 
</pre>
   
Line 53: Line 53:
 
Following should help:
 
Following should help:
 
<pre>
 
<pre>
:map ,p :!xterm -e "python \"&lt;the_current_buffer&gt;\"" &amp;
+
:map ,p :!xterm -e "python \"<the_current_buffer>\"" &
 
</pre>
 
</pre>
   
Note that &amp; at the end of the line.
+
Note that & at the end of the line.
   
 
----
 
----

Latest revision as of 23:34, September 29, 2008

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.


Around Wikia's network

Random Wiki