This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
vim_binding.js
107 lines (96 loc) · 2.79 KB
/
vim_binding.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* vim_binding.js
*
* A vim key binding plugin for Jupyter/IPython
*
* @author Alisue <[email protected]>
* @version 2.0.4
* @license MIT license
* @see http://github.com/lambdalisue/jupyter-vim-binding
* @copyright 2015-2016, Alisue, hashnote.net
*
* Refs:
* - https://github.com/ivanov/ipython-vimception
* - http://stackoverflow.com/questions/25730516/vi-shortcuts-in-ipython-notebook
* - http://mindtrove.info/#nb-server-exts
* - http://akuederle.com/customize-ipython-keymap/
*/
define([
'require',
'jquery',
'services/config',
'base/js/namespace',
'base/js/utils',
'notebook/js/cell',
'./lib/codemirror',
'./lib/jupyter/actions',
'./lib/jupyter/codecell',
'./lib/jupyter/completer',
'./lib/jupyter/keyboard',
'./lib/jupyter/notebook',
'./lib/jupyter/shortcuts',
'./lib/jupyter/quickhelp',
], function(require, $, config, ns, utils, cell) {
"use strict";
var undefined;
var exports = {};
var modules = Array.prototype.slice.call(arguments, 6);
var Cell = cell.Cell;
var conf = new config.ConfigSection('notebook', {
base_url: utils.get_body_data('baseUrl')
});
var params = {
'scroll_unit': 30,
};
var require_css = function(url) {
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = require.toUrl(url);
document.getElementsByTagName('head')[0].appendChild(link);
};
conf.loaded.then(function() {
params = $.extend(params, conf.data);
exports.attach();
});
exports.attach = function attach() {
for(var i=0; i<modules.length; i++) {
modules[i].attach(params);
}
// Include required CSS
require_css('./vim_binding.css');
// Initialize
var cm_config = Cell.options_default.cm_config;
cm_config.keyMap = 'vim';
cm_config.extraKeys = $.extend(cm_config.extraKeys || {}, {
'Esc': CodeMirror.prototype.leaveInsertMode,
'Shift-Esc': CodeMirror.prototype.leaveNormalMode,
'Ctrl-C': false, // To enable clipboard copy
});
// Apply default CodeMirror config to existing CodeMirror instances
ns.notebook.get_cells().map(function(cell) {
var cm = cell.code_mirror;
if (cm) {
cm.setOption('keyMap', cm_config.keyMap);
cm.setOption('extraKeys', $.extend(
cm.getOption('extraKeys') || {},
cm_config.extraKeys
));
}
});
for(var i=0; i<this.on_ready_callbacks.length; i++) {
this.on_ready_callbacks[i](this);
}
};
exports.detach = function detach() {
for(var i=0; i<modules.length; i++) {
modules[i].detach(params);
}
};
exports.load_ipython_extension = function load_ipython_extension() {
conf.load();
};
// Assumed to used in 'custom.js'
exports.on_ready_callbacks = [];
return exports;
});