How to Implement a Simple Code Runner in Neovim
VS code like code runner in Neovim with a simple script.
Table of contents
No headings in the article.
To implement a code runner in neovim you'll have to write a script, you can just copy the following script, written in VimScript into you init.vim
:
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!gcc % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
elseif &filetype == 'js'
exec "!node %"
exec "!time java -cp %:p:h %:t:r"
elseif &filetype == 'sh'
exec "!time bash %"
elseif &filetype == 'python'
exec "!time python3 %"
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'go'
exec "!go build %<"
This script is mapped to F5
you can change the mapping as per your workflow.