"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