vimrc - How does vim map keys based on the file extension?
某草草
某草草 2017-05-16 16:36:29
0
1
550

For example, when editing the.cppfile, you want to mapto:call CompileCpp().
When compiling the.htmlfile, I want to mapto:call RunHtml().
Can this be done?

某草草
某草草

reply all (1)
世界只因有你

Probably use this

autocmd FileType vim call RunHtml()

But it is recommended to set makeprg when using autocmd FileType, and then just make directly when using F5. This will display the error message to quickfix
This is the other language I set

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
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!