vimrc - vim如何根据文件的后缀名来进行按键的映射?
某草草
某草草 2017-05-16 16:36:29
0
1
565

比如在编辑.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 | 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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!