From 00b553bb12f67cbb966804bde4be75ee5f740f7e Mon Sep 17 00:00:00 2001 From: PratyayPande Date: Fri, 31 Jul 2020 17:34:38 +0530 Subject: [PATCH] Added java support to run_code.vim --- vimrcs/run_code.vim | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/vimrcs/run_code.vim b/vimrcs/run_code.vim index 18ebbf78..c5e0bd71 100644 --- a/vimrcs/run_code.vim +++ b/vimrcs/run_code.vim @@ -1,8 +1,36 @@ +"================================================================================= +" +" Following code contains the commands on how to run the currently open code. +" The default mapping is set to F5 like most code editors out there. +" Change it as you feel comfortable with, keeping in mind that it does not +" clash with any other keymapping. +" +" NOTE: Compilers for different systems may differ. For example, in the case +" of C and C++, we have assumed it to be gcc and g++ respectively, but it may +" not be the same. It is suggested to check first if the compilers are installed +" before running the code, or maybe even switch to a different compiler. +" +" NOTE: Adding support for more programming languages +" +" Just add another elseif block before the 'endif' statement in the same +" way it is done in each case. Take care to add tabbed spaces after each +" elseif block (similar to python). For example: +" +" elseif &filetype == '' +" exec '! %' +" +" NOTE: The '%' sign indicates the name of the currently open file with extension. +" The time command displays the time taken for execution. Remove the +" time command if you dont want the system to display the time +" +"================================================================================= + map :call CompileRun() imap :call CompileRun() +vmap :call CompileRun() func! CompileRun() -exec "w" +exec "w" if &filetype == 'c' exec "!gcc % -o %<" exec "!time ./%<" @@ -11,7 +39,7 @@ elseif &filetype == 'cpp' exec "!time ./%<" elseif &filetype == 'java' exec "!javac %" - exec "!time java -cp %:p:h %t:r" + exec "!time java %" elseif &filetype == 'sh' exec "!time bash %" elseif &filetype == 'python'