From 66a6ff5c98e49192c2ddc2b80e1fe7c6211727d0 Mon Sep 17 00:00:00 2001 From: PratyayPande Date: Fri, 31 Jul 2020 17:00:07 +0530 Subject: [PATCH] Added feature to execute code directly from vim included support for: C, C++, Java, Python, Bash, Go and HTML --- README.md | 9 +++++++++ install_awesome_parameterized.sh | 2 +- install_awesome_vimrc.sh | 2 +- vimrcs/run_code.vim | 27 +++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 vimrcs/run_code.vim diff --git a/README.md b/README.md index 95a7a35d..b683e931 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,15 @@ Shortcuts using `` instead of special characters: map sa zg map s? z= +### Running Code +To run code directly from vim, press `F5`. The currently open code will execute without you having to type anything. + +Can be used to execute code written in C, C++, Java, Python, Go, Octave, Bash scripts and HTML. To edit how you want your code to be executed, make changes in the file +``` + +~/vim_runtime/vimrcs/run_code.vim + +``` ### Cope Query `:help cope` if you are unsure what cope is. It's super useful! diff --git a/install_awesome_parameterized.sh b/install_awesome_parameterized.sh index ee4be411..f9b08ec2 100755 --- a/install_awesome_parameterized.sh +++ b/install_awesome_parameterized.sh @@ -10,7 +10,7 @@ source $1/vimrcs/basic.vim source $1/vimrcs/filetypes.vim source $1/vimrcs/plugins_config.vim source $1/vimrcs/extended.vim - +source $1/vimrcs/run_code.vim try source $1/my_configs.vim catch diff --git a/install_awesome_vimrc.sh b/install_awesome_vimrc.sh index 6b94e519..f83eb9a3 100755 --- a/install_awesome_vimrc.sh +++ b/install_awesome_vimrc.sh @@ -9,7 +9,7 @@ source ~/.vim_runtime/vimrcs/basic.vim source ~/.vim_runtime/vimrcs/filetypes.vim source ~/.vim_runtime/vimrcs/plugins_config.vim source ~/.vim_runtime/vimrcs/extended.vim - +source ~/.vim_runtime/vimrcs/run_code.vim try source ~/.vim_runtime/my_configs.vim catch diff --git a/vimrcs/run_code.vim b/vimrcs/run_code.vim new file mode 100644 index 00000000..18ebbf78 --- /dev/null +++ b/vimrcs/run_code.vim @@ -0,0 +1,27 @@ +map :call CompileRun() +imap :call CompileRun() + +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