Neovim Code Runner
In this article, let’s explore the different ways to run our code, with and without plugins.
We are going to
- Use the built-in
ftpluginfeatures to have a consistent way to build or run our code for different programming languages.
- Configure Lua-based code runner plugins to run our code.
- Explore plugins to run our code interactively and partially.
- Use terminal-integration plugins to run our code.
- Explore language-specific and test plugins.
Compiler and File Type Plugins
In this article, we walked through how to run, debug and monitor a Python application using different key mappings.
E.g. to run a Python application, we use the following mapping.
nnoremap <leader>rr ":update<CR>:exec '!python3' shellescape(@%, 1)<CR>
For debugging, we use the built-in terminal and
nnoremap <leader>rd :update<CR>:sp term://python3 -m pdb %<CR>
To monitor the application, we can use
nnoremap <leader>rn :update<CR>:sp term://nodemon -e py %<CR>
However, to have a consistent way to build and run applications in different languages, we can also use the built-in
ftplugin (file type) plugins.
$VIMRUNTIME folder and we can see the
ftplugin folders. E.g. below is the
compiler plugin for Java.
We are going to write a simple
compiler plugin (
:h write-compiler-plugin) to run Python files.