Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If editing some script in vim, a file with .py or .sh extension, is it any build-in vim command that allows to run such file? I know it's a lot of IDE-like addons for VIM that allows to execute files vim edit, but is it possible without addons?

share|improve this question
up vote 8 down vote accepted

I hope I'm not offending you by answering, that to run the current file (not buffer) you just


UPD: To run buffer to interpreter's standard input (without saving to a file first):

:w !/bin/sh

The latter can be also used with python, with perl -w, etc.

By the way, a super useful technique is to filter a buffer through external command:

1G!Ggrep -v unwanted_regex

All these are vi compatible.

share|improve this answer
Thanks! I suppose vim don't know about file extension and #!/bin/python in order to run file via correct interpreter? – Eye of Hell Jun 22 '09 at 9:34
Updated with additional tip. Of course, the "#!/xxx" header is parsed inside execve() system call (i.e. when you run an executable file), so it will definately work with the :!% way. But I don't know how to script vim to automatically execute the proper interpreter in the :w !interpreter way. This can be trivially done with external shell script. File extension does not matter in these cases at all. – kubanczyk Jun 22 '09 at 9:51
Fantastic idea! Simple too - one of those "Why didn't I think of that?" moments.... – Mei Jun 23 '09 at 18:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.