Skip to content

Instantly share code, notes, and snippets.

@blindstitch
Last active December 2, 2019 17:03
Show Gist options
  • Save blindstitch/190dc237e13e87a93045defe87247e57 to your computer and use it in GitHub Desktop.
Save blindstitch/190dc237e13e87a93045defe87247e57 to your computer and use it in GitHub Desktop.
Execute python or r code in vim
" 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