问题描述
比如在编辑.cpp文件时,想把<F5>映射为 :call CompileCpp()<CR>.在编译.html文件时,想把<F5>映射为:call RunHtml()<CR><Spcae>.请问可以做到吗?
问题解答
回答1:大概使用这种
autocmd FileType vim call RunHtml()
但是建议 autocmd FileType 时设置makeprg,然后F5的时候直接make就行了。这样可以显示错误消息到quickfix这是我设置的其它语言的
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 | endifaugroup ENDfunction! 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