For example, in editing.cpp
When filing, want to put<F5>
Map to:call CompileCpp()<CR>
.
In compilation.html
When filing, want to put<F5>
Map to:call RunHtml()<CR><Spcae>
.
Can you do it?
Probably use this
autocmd FileType vim call RunHtml()
However, it is recommended to set makeprg when autocmd FileType is used, and then directly make when F5 is used. This displays an error message to quickfix.
This is for other languages I have set up.augroup make_autocmd autocmd Filetype javascript setlocal makeprg=jsl\ -nologo\ -nofilelisting\ -nosummary\ -nocontext\ -conf\ /etc/jsl.conf\ -process\ % autocmd FileType json setlocal makeprg= autocmd FileType php \ setlocal makeprg=php\ -l\ -n\ -d\ html_errors=off\ % | \ setlocal errorformat=%m\ in\ %f\ on\ line\ %l autocmd BufWritePost * call Make() " auto close quickfix if it is the last window autocmd WinEnter * if winnr('$') == 1 && getbufvar(winbufnr(winnr()), "&buftype") == "quickfix" | quit | endif augroup END function! Make() if &modified | silent write | endif if &makeprg == 'make' | return | endif let regname = '"~' let old_pos = getpos('.') silent make execute 'cw' if ! has('gui_running') | redraw! | end call setpos('.', old_pos) endfunction