1
0
mirror of https://github.com/amix/vimrc synced 2025-02-28 14:12:51 +08:00
amix-vimrc-mirror/vimrcs/run_code.vim
PratyayPande 66a6ff5c98 Added feature to execute code directly from vim
included support for: C, C++, Java, Python, Bash, Go and HTML
2020-07-31 17:00:07 +05:30

28 lines
626 B
VimL

map <F5> :call CompileRun()<CR>
imap <F5> <Esc>:call CompileRun()<CR>
func! CompileRun()
exec "w"
if &filetype == 'c'
exec "!gcc % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java -cp %:p:h %t:r"
elseif &filetype == 'sh'
exec "!time bash %"
elseif &filetype == 'python'
exec "!time python %"
elseif &filetype == 'html'
exec "!google-chrome % &"
elseif &filetype == 'go'
exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'matlab'
exec "!time octave %"
endif
endfunc