You are looking for the makeprg
option, :h 'makeprg'
:
*'makeprg'* *'mp'*
'makeprg' 'mp' string (default "make", VMS: "MMS")
global or local to buffer |global-local|
{not in Vi}
Program to use for the ":make" command. See :make_makeprg.
This option may contain '%' and '#' characters,
which are expanded to the current and alternate file name. Use |::S|
to escape file names in case they contain special characters.
Environment variables are expanded |:set_env|. See |option-backslash|
about including spaces and backslashes.
Note that a '|' must be escaped twice: once for ":set" and once for
the interpretation of a command. When you use a filter called
"myfilter" do it like this:
:set makeprg=gmake\ \\\|\ myfilter
The placeholder "$*" can be given (even multiple times) to specify
where the arguments will be included, for example:
:set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
The best way to use it is to define the option in an ftplugin. For example for python create ~/.vim/after/ftplugin/python.vim
containing:
setlocal makeprg=python\ %
Create a new ftplugin and adapt the makeprg
for each filetype you want to handle.
Then you can simply use the command :make
in the file you want to source or create a mapping like nnoremap <F5> :make<CR>
.
Some related help topics: