8

I'm currently doing a lot of work with both Ruby and JavaScript. I know that I can run my Ruby files with :! ruby % and likewise my JavaScript with :! node %, and that I can bind either of those to, eg, ,b. How can I set things up so that I can just bind a single command that will check the extension of the file I'm editing and run the appropriate command?

1 Answer 1

10

You could use :make for this; you can set makeprg (short for make program) to any command.

Some examples:

au FileType ruby set makeprg=ruby\ %
au FileType javascript set makeprg=node\ %
au FileType python set makeprg=python\ %
au FileType coffeescript set makeprg=coffee\ -c\ %

noremap ,b :make<CR>

:make was originally intended to run the make tool to build the project, but languages such as Ruby or Javascript don't need compiling, to setting it to something that will run the code makes sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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