Last active
December 2, 2019 17:03
-
-
Save blindstitch/190dc237e13e87a93045defe87247e57 to your computer and use it in GitHub Desktop.
Execute python or r code in vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Run standard compile/run commands | |
function! RunBuildCommand() | |
" Choose between python3, Rscript based on extension | |
w | |
cd %:p:h | |
let filename = expand('%t') | |
let extension = expand('%:e') | |
let basename = expand('%:r') | |
" rscript | |
if extension == 'r' | |
execute '!Rscript ' . filename | |
endif | |
" python | |
if extension == 'py' | |
execute '!python3 ' . filename | |
endif | |
" latex | |
if extension == 'tex' || extension == 'tikz' | |
execute '!latexmk -pdf ' . filename . '; mv *.log *.fls *latexmk *.blg *.aux *.bbl *.run.xml *.bcf log/' | |
endif | |
" markdown -> pandoc | |
if extension == 'md' | |
execute '!pandoc -o ' . basename . '.docx ' . filename | |
endif | |
endfunction | |
map <Leader>rr :call RunBuildCommand()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment