Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 959
user3751385 Avatar asked Mar 22 '17 01:03

user3751385


People also ask

How do I open node JS REPL?

How to Start the REPL. Starting the REPL is simple - just run node on the command line without a filename. It then drops you into a simple prompt ('>') where you can type any JavaScript command you wish.


1 Answers

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.

like image 189
Eric Leung Avatar answered Sep 30 '22 17:09

Eric Leung