Search code examples
node.jsvimread-eval-print-loopneovim

Open vim (or editor of your choice) in nodejs REPL editor mode


As of nodejs 6.6.0, when using the nodejs REPL you can enter multiline text in the terminal with:

.editor

I would like the nodejs REPL to open an instance of vim (in the same manner that git does when prompting for commit information) so that I can enter the multiline text there.

Does anyone know how to configure this? I realize that I could just run the nodejs REPL within vim or neovim in the first place, but I'm looking for a pure fix here.


Solution

  • There doesn't appear to be an easy way to customize this behavior. Digging through the code for nodejs, it appears that the editor mode is simply streaming each line of together.

    See here for the relevant piece of code on GitHub.

    The closest solution to "use" vim in this NodeJS REPL is to enable Vi(m) mode in bash (if you're using the bash shell).

    set -o vi
    

    After running this or putting into your .bashrc file, the command line interface will act like Vim and have editing modes you have to navigate.

    Personally, even though I am a Vim user, don't like the Vi mode in bash because it is difficult to know which mode you're in, even if my go-to mode is Normal mode. Adding some text to indicate which mode you're in may be possible, but I don't think its worth looking into. But your mileage will vary.

    See https://sanctum.geek.nz/arabesque/vi-mode-in-bash/ for more on Vi mode in bash.