Execute a script directly within vim/mvim/gvim

randombits picture randombits · Jul 2, 2010 · Viewed 47.9k times · Source

TextMate has a nice feature that allows you to execute a script from within the current context and shows you the output in a separate window. This lets you write and test code on the go. I'm almost certain there is a similar feature with MacVim/gVIM, but I'm not sure what it is. Currently I save my buffers to disk, then go to the command line and execute the script in that respect. How do I improve that workflow with vim?

Answer

jts picture jts · Jul 2, 2010

You can do this in vim using the ! command. For instance to count the number of words in the current file you can do:

:! wc %

The % is replaced by the current filename. To run a script you could call the interpreter on the file - for instance if you are writing a perl script:

:! perl %