Vim one-click Compilation

Source: Internet
Author: User
"Map compilation for a single file <F5>: Call do_onefilemake () <CR> function do_onefilemake () If expand (" %: P: H ")! = Getcwd () echohl warningmsg | echo "fail to make! This file is not in the current Dir! Press <F7> to redirect to the Dir of this file. "| echohl none return endif let sourcefileename = expand (" %: t ") if (sourcefileename =" "| (& filetype! = "CPP" & filetype! = "C") echohl warningmsg | echo "fail to make! Please select the right file! "| Echohl none return endif let deletedspacefilename = substitute (sourcefileename,'', '', 'G') If strlen (deletedspacefilename )! = Strlen (sourcefileename) echohl warningmsg | echo "fail to make! Please delete the spaces in the filename! "| Echohl none return endif if & filetype =" C "If G: iswindows = 1 Set makeprg = GCC \-O \ % <. exe \ % else set makeprg = GCC \-O \ % <\ % endif elseif & filetype = "CPP" If G: iswindows = 1 Set makeprg = g ++ \-O \ % <. exe \ % else set makeprg = g ++ \-O \ % <\ % endif "elseif & filetype =" CS "" set makeprg = CSC \/nologo \\/ out: % <. exe \ % endif if (G: iswindows = 1) Let outfilename = substitute (sourcefileename ,'\(\. [^.] * \) ', '.exe ', 'G') Let toexename = outfilename else let outfilename = substitute (sourcefileename ,'\(\. [^.] * \) ', '', 'G') Let toexename = outfilename endif if filereadable (outfilename) if (G: iswindows = 1) Let outdeletedsuccess = Delete (getcwd (). "\\". outfilename) else let outdeletedsuccess = Delete (". /". outfilename) endif if (outdeletedsuccess! = 0) set makeprg = make echohl warningmsg | echo "fail to make! I cannot delete ". outfilename | echohl none return endif execute "Silent make" set makeprg = make execute "Normal:" If filereadable (outfilename) if (G: iswindows = 1) Execute "! ". Toexename else execute "!. /". Toexename endif execute "Copen" endfunction "to make the settings Map <F6>: Call do_make () <CR> Map <c-F6>: silent make clean <CR> function do_make () set makeprg = make execute "Silent make" execute "Copen" endfunction

Used to learn from vimer.cn address http://www.vimer.cn/2009/10/11.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.