mirror of
https://oauth2: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@github.com/m1ngsama/chopsticks.git
synced 2026-06-26 04:34:38 +08:00
28 lines
1.1 KiB
VimL
28 lines
1.1 KiB
VimL
" runner.vim — run the current file by filetype
|
|
|
|
function! s:RunFile() abort
|
|
write
|
|
let l:ft = &filetype
|
|
let l:file = shellescape(expand('%:p'))
|
|
if l:ft ==# 'python' | execute '!python3 ' . l:file
|
|
elseif l:ft ==# 'javascript' | execute '!node ' . l:file
|
|
elseif l:ft ==# 'typescript' | execute '!npx ts-node ' . l:file
|
|
elseif l:ft ==# 'go' | execute '!go run ' . l:file
|
|
elseif l:ft ==# 'rust' | execute '!cargo run'
|
|
elseif l:ft ==# 'sh' | execute '!bash ' . l:file
|
|
elseif l:ft ==# 'c'
|
|
let l:out_path = tempname()
|
|
let l:out = shellescape(l:out_path)
|
|
execute '!gcc -o ' . l:out . ' ' . l:file . ' && ' . l:out
|
|
call delete(l:out_path)
|
|
elseif l:ft ==# 'lua' | execute '!lua ' . l:file
|
|
elseif l:ft ==# 'ruby' | execute '!ruby ' . l:file
|
|
elseif l:ft ==# 'perl' | execute '!perl ' . l:file
|
|
else | echo 'No runner for filetype: ' . l:ft
|
|
endif
|
|
endfunction
|
|
if g:chopsticks_space_keymaps
|
|
nnoremap <leader>rr :call <SID>RunFile()<CR>
|
|
else
|
|
nnoremap <leader>cr :call <SID>RunFile()<CR>
|
|
endif
|