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?
Run shell commands on current file based on file extension
key bindings;external command;filetype
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.