mirror of
https://github.com/amix/vimrc
synced 2025-07-04 06:44:59 +08:00
Added feature to execute code directly from vim
included support for: C, C++, Java, Python, Bash, Go and HTML
This commit is contained in:
27
vimrcs/run_code.vim
Normal file
27
vimrcs/run_code.vim
Normal file
@ -0,0 +1,27 @@
|
||||
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
|
Reference in New Issue
Block a user