-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrepl.js
45 lines (35 loc) · 1.35 KB
/
repl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var rlv = require('..')
, repl = require('repl');
var r = repl.start({
prompt: "vim repl > ",
input: process.stdin,
output: process.stdout
});
var vim = rlv(r.rli)
, map = vim.map;
/*
* Mappings:
*
* It is important to note the following actions are present by default:
* - [esc] by default switches to normal mode
* - [ctrl-p] and [ctrl-n] navigate the history in insert mode
* - [j] and [k] navigate the history in normal mode
*
* The below mappings add other ways to invoke the same actions
*/
// [insert mode] allow switching to normal mode by typing 'jk' quickly
map.insert('jk', 'esc');
// [insert mode] go backward in history via 'ctrl-k'
map.insert('ctrl-k', 'ctrl-p');
// [insert mode] go backward in history via 'ctrl-k'
// (forward via 'ctrl-j' doesn't work since it is interpreted as 'enter')
map.insert('ctrl-space', 'ctrl-n');
// [normal mode] go backward in history via space bar
map.normal('space', 'k');
// [normal mode] go forward in history via space bar when ctrl is pressed
// (shift wouldn't work with space since nodejs readline checks for uppercase)
map.normal('ctrl-space', 'j');
console.log('The following mappings have been added:\n %s', require('util').inspect(map.mappings, false, 5, true));
console.log('\nConsult the comments inside examples/repl.js for more details.\n');
r.displayPrompt();