Skip to content

Instantly share code, notes, and snippets.

@bstaint
Created April 3, 2017 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bstaint/a4063fc0b94b84336f2b25e4a3125a54 to your computer and use it in GitHub Desktop.
Save bstaint/a4063fc0b94b84336f2b25e4a3125a54 to your computer and use it in GitHub Desktop.
function! s:RunFunc(flag)
let cmdline = { 'c': 'gcc', 'cpp': 'g++' }
if exists('cmdline[&ft]')
exec 'VimProcBang '.cmdline[&ft].' %:t -Wall -g -o %:t:r.exe'
let output = expand('%:t:r').'.exe'
" 确保编译成功且生成exe
if a:flag == 1 && vimproc#get_last_status() == 0
\ && filereadable(output)
echo vimproc#cmd#system(output)
endif
endif
endfunction
command! Run call <SID>RunFunc(1)
" 仅编译不运行
command! RunOnly call <SID>RunFunc(0)
" 用来通过make编译py文件为pyc
au FileType python setlocal makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment