Introducing REPL.nvim
published:
categories: vim
Integrating a REPL in Vim has been a difficult issue in the past, but with Nvim's built-in terminal emulator it is just a few commands away. My new REPL.nvim plugin now puts the REPL only one command away, for any programming language you wish. The end goal is to have a complete generic and configurable REPL framework which can be customised to the needs of any language and which forms a solid foundation for other plugins as well.
What is REPL.nvim and why should you care?
In its most simple form REPL.nvim is a wrapper around Nvim's built-in terminal
emulator. You execute the :Repl
command and a new window containing a running
REPL instance opens up. Behind the scenes :Repl
opens a new buffer, sets the
parameters, executes :terminal
and launches the REPL process. Originally
REPL.nvim started out as just a REPL for GNU Guile, but I quickly noticed
that all Guile-specific code could be completely isolated, leaving me with a
language-agnostic plugin.
This means that the plugin consists roughly speaking of two parts: the actual plugin that does all the work, and the configuration data which controls the plugin. The configuration can be set per file type, so any language will have its own separate settings. As an example, here are the Python settings:
let g:repl['python']: {
\ 'bin': 'python',
\ 'args': [],
\ 'syntax': '',
\ 'title': 'Python REPL',
\ },
All settings are stored inside a dictionary and each entry can be overridden by user settings or plugins.
The current state of REPL.nvim
REPL.nvim is already a fully working REPL wrapper. Not many REPLs are supported at the moment, but adding those is trivial. They can be added to the user's own Nvim settings, as a plugin, or you could submit a patch to the official repository.
The next step is to grow the API. As I mentioned above, my goal is to have a complete framework which other plugins can hook up to. This means that even if they want to completely re-route the signal to their own functions they should be able to do so. For instance, a plugin which uses a regular Nvim buffer instead of wrapping the terminal emulator should be able to add one entry to the configuration:
" This is not yet implemented
let g:repl.python.launch_repl = {type -> some_function(type)}
Thanks to the introduction of lambdas in Vim 8 and Nvim 0.2 it is possible to make the plugin fully functional.
Contributions are welcome
If you want to support a REPL or if you have ideas for the API let me know. I want to be able to support as many REPLs out of the box with reasonable settings as possible. Head over to the repository and get your hands on it.