Linux下vim编写python脚本一键运行

这一生的挚爱 提交于 2019-12-28 09:18:20

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

    vim编辑器的配置文件为:/etc/vimrc
    通过:sudo vim /etc/vimrc 打开vim的配置文件
    在结尾添加如下内容即可指定F5为测试脚本的快捷键:
    注:此方式便于对脚本进行单元测试。

map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
        exec "!g++ % -o %<"
        exec "!time ./%<"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "!time ./%<"
    elseif &filetype == 'java'
        exec "!javac %"
        exec "!time java %<"
    elseif &filetype == 'sh'
        :!time bash %
    elseif &filetype == 'python'
        exec "!time python2.7 %"
        exec "!time python3.6 %"
    elseif &filetype == 'html'
        exec "!firefox % &"
    elseif &filetype == 'go'
        exec "!go build %<"
        exec "!time go run %"
    elseif &filetype == 'mkd'
        exec "!~/.vim/markdown.pl % > %.html &"
        exec "!firefox %.html &"
    endif
endfunc

   
    vim编写的脚本内容 vim 编写的testF5.py内容

vim编写完成后不退出直接按F5后结果:
一键执行结果

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!