Node: vi style bindings in node interpreter

Created on 9 Mar 2016  路  14Comments  路  Source: nodejs/node

I have vi style bindings enabled in my .inputrc

set editing-mode vi

I have used these successfully in python's intrpreter and ruby's interpreter, but they do not seem to work correctly with node.

In this case, none of the key binds work except of b, which will move backwards once then glitch out and no longer work.

_Edit:_
When I disable vi style bindings in the .inputrc, the ruby and python interpreters behave in the same manner as node.

  • Version: v5.7.0
  • Platform: Darwin marmot 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
feature request repl

Most helpful comment

@tanium-kdp Thanks, just added to my .bashrc

if [ $(command -v rlwrap) ] ; then
  alias node='NODE_NO_READLINE=1 rlwrap node'
fi

All 14 comments

Is there some sort of .inputrc spec or reference? Currently impossible to tell how this should work..

It seems the functionality is provided through the GNU Readline Library.

Node doesn't use readline (neither the GNU nor the BSD version), it has its own JS-based line parser (also named readline but modeled - initially - after linenoise) that doesn't support .inputrc files.

I would be willing to consider it if there is some spec or reference that isn't just a single implementor. Also note that it needs to be portable to windows. :)

As far as I know, the reference for .inputrc is the bash reference manual.

@sbdchd I haven't used it, but there is this: https://github.com/thlorenz/readline-vim which supports a subset of the vi keybindings. A simple script like this might help you get what you are looking for.

#! /usr/bin/env node
var rlv = require('readline-vim'),
      repl = require('repl');

var r = repl.start({
  prompt: "vim repl > ",
  input: process.stdin,
  output: process.stdout
});

r.displayPrompt();

Name it something like vrepl and put it in your $PATH.

hmmmm yeah that sample file almost looks like it;s using a scripting language.

I wonder if something like node -r 'your-repl-module' wouldn't be a better option, though I'm not exactly sure how that would work.

It just uses /usr/bin/env node to invoke your default node executable and run the following Javascript. Just name the file vrepl, then chmod 755 vrepl, and stick it in your $PATH. Then npm install -g readline-vim, so no matter where vrepl is on disk, it can find the module. Works fine for me on OSX El Capitan.

FWIW, the syntax reference for GNU Readline: https://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC9

Was there a compelling reason to rewrite readline in Node? Portability?

I would alternately use rlwrap or similar facilities if I could get autocompletion working with them. Does node.readline or node.repl expose a readline:completion-friendly function?

@al-the-x GNU readline is GPL鈥檈d, so that鈥檚 not usable for Node core.

And the LICENSE rears its head again... Thanks for the clarity. Any advice on the completion function? I didn't see anything in REPLServer that looked promising, but I haven't dug into readline yet.

How nice this would be 鉂わ笍

This issue has been open for 18 months without movement. I'm closing it out but if (generic) you still want to see it happen, I encourage you to open a pull request. It would probably be well-received.

Colleague just informed me that there's a env. var. that can help with this ... NODE_NO_READLINE=1 rlwrap node totally gets me sorted here; hope this helps others, too.

@tanium-kdp Thanks, just added to my .bashrc

if [ $(command -v rlwrap) ] ; then
  alias node='NODE_NO_READLINE=1 rlwrap node'
fi
Was this page helpful?
0 / 5 - 0 ratings

Related issues

filipesilvaa picture filipesilvaa  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

jmichae3 picture jmichae3  路  3Comments

sandeepks1 picture sandeepks1  路  3Comments

cong88 picture cong88  路  3Comments