vimcmdline: Send lines to interpreter
This plugin sends lines from either Vim or Neovim to a command line interpreter (REPL application). There is support for Clojure, Golang, Haskell, JavaScript, Julia, Jupyter, Kotlin, Lisp, Lua, Macaulay2, Matlab, Prolog, Python, Racket, Ruby, Sage, Scala, Shell script, Swift, Kdb/q and TypeScript (see Nvim-R for R support on Vim/Neovim). The interpreter runs in Neovim's built-in terminal. If Tmux is installed, the interpreter can also run in an external terminal emulator or in a tmux pane. The main advantage of running the interpreter in a Neovim terminal is that the output is colorized, as in the screenshot below, where we have different colors for general output, positive and negative numbers, and the prompt line:
If running in either a Neovim built-in terminal or an external terminal, the plugin runs one instance of the REPL application for each file type. If running in a tmux pane, it runs one REPL application for Vim instance.
Support for running the interpreter in Vim's built-in terminal was not implemented.
How to install
Either use a plugin manager such as Vim-Plug or copy the directories
ftplugin
, plugin
and syntax
and their files to your ~/.vim
or
~/.config/nvim
directory.
You have to install Tmux if you either want to run the interpreter in an external terminal emulator or are using Vim.
I have never adapted the plugin to run the interpreter within Vim's built-in terminal (as it does in Neovim) because Vim cannot colorize the output printed in its terminal.
Usage and options
Please, read the plugin's documentation for further instructions.
How to add support for a new language
-
Look at the Vim scripts in the
ftplugin
directory and make a copy of the script supporting the language closer to the language that you want to support. -
Save the new script with the name "filetype_cmdline.vim" where "filetype" is the output of
echo &filetype
when you are editing a script of the language that you want to support. -
Edit the new script and change the values of its variables as necessary.
-
Test your new file-type script by running your application in either Vim or Neovim and using either the built-in terminal or a Tmux split pane.
-
Look at the Vim scripts in the
syntax
directory and make a copy of the script supporting the language whose output is closer to the output of the language that you want to support. -
Save the new script with the name "cmdlineoutput_app.vim" where "app" is the name of the interpreter. For example, for the "matlab" file-type, the interpreter is "octave".
-
Edit the new script and change both the pattern used to recognize the input line and the pattern used to recognize errors.
-
Test your new syntax highlighting script by running your application in a Neovim built-in terminal.
See also
Plugins with similar functionality are neoterm, vim-slime and repl.nvim.