微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VIM实现F5运行php/perl/python/c/java/erlang

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

function RunThisScript() 
    let file_name = expand("%:p")
    let file_ext = expand("%:e")
    let file_cmd = ""

    "python 直接调用
    if file_ext == "py"
        let file_cmd = '/usr/bin/python' 
        let file_args = ' ' . file_name
    "c 需要提取第一行的编译参数
    "如,当需要引入第三方库(以MysqL为例)时,则在第一行添加: //-lMysqLclient -L/usr/local/MysqL/include
    "文件中则可直接 #include <MysqL/MysqL.h>
    elseif file_ext == "c" 
        let file_first_line = getline(1)
        let file_arg = ""
        if strpart(file_first_line,2) == '//'
            let file_arg = strpart(file_first_line,2) "提取参数
        endif
        let file_output_file = strpart(file_name,strridx(file_name,'.c')) 
        let file_args = ' -o '. file_output_file .' '.  file_name . ' '. file_arg .' && '. file_output_file "将参数附加到编译命令之后
        let file_cmd = '/usr/bin/cc' 
    "PHP 直接调用
    elseif file_ext == "PHP"
        let file_cmd = "/usr/local/PHP/bin/PHP" "PHP执行路径
        let file_args = ' -f '. file_name
    "perl 直接调用
    elseif file_ext == "perl" || file_ext == "pl"
        let file_cmd = "/usr/bin/perl"
        let file_args = " ". file_name
    "erlang 调用 main 函数,可以确保 escript 和 noshell/shell 执行时一致
    elseif file_ext == "erl"
        let file_output_file = strpart(expand("%"),stridx(expand("%"),".erl"))
        let file_cmd = "/usr/bin/erlc" 
        let file_args = file_output_file .".". file_ext ." ; /usr/bin/erl -noshell -s ". file_output_file . " main  -s init stop"
    "java 先调用 javac,再调用java
    elseif file_ext == "java"
        let file_output_file = strpart(expand("%"),".java"))
        let file_cmd = 'javac'
        let file_args = file_name ." && java ". file_output_file
    else
        echo "错误: 没有任何编译器匹配此文件类型,请确认您的文件扩展名!"
    endif

    if file_cmd != ""
        if ! executable(file_cmd)
            echo file_cmd
            echo "The executable file to compile ". file_ext . " type files."
        else
            let cmd = "! ". file_cmd . ' ' . file_args
            "echo "执行命令: ". cmd
            exec cmd 
        endif
    endif
endfunction

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐