Neovim Code Runner

Run code within Neovim, with and without plugins.

alpha2phi
5 min readJan 9, 2022

--

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 compiler and ftplugin features 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 pdb.

nnoremap <leader>rd :update<CR>:sp term://python3 -m pdb %<CR>

To monitor the application, we can use nodemon.

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 compiler and ftplugin (file type) plugins.

Navigate to $VIMRUNTIME folder and we can see the compiler and ftplugin folders. E.g. below is the compiler plugin for Java.

Vim Runtime

Compiler

We are going to write a simple compiler plugin (:h write-compiler-plugin) to run Python files.

--

--

alpha2phi

Software engineer, Data Science and ML practitioner.