Defining vim maps: Need to call js function CodeMirror.Vim.map(lhs, rhs, context). Ideas?

53 views
Skip to first unread message

Matthew Phelps

unread,
Jan 2, 2020, 10:35:48 AM1/2/20
to TiddlyWiki
I am trying to remap a keybind for the <esc> sequence within CodeMirror's vim editor in TW5. The vim editor does support the use of the ex command 
:imap kj <Esc>
however this is not a global approach. As outlined in https://github.com/codemirror/CodeMirror/issues/2840, it would seem I need to call the js function
CodeMirror.Vim.map('kj', '<Esc>', 'insert')

I  have tried including the above call within $:/plugins/tiddlywiki/codemirror/keymap/vim.js but to no avail. However, I may not be implementing the call correctly. 

Is there a method to run the necessary script whenever vim.js is called?

For reference, here is the defined vim.js https://codemirror.net/keymap/vim.js. I was trying to include  
CodeMirror.Vim.map('kj', '<Esc>', 'insert')
after 
CodeMirror.Vim = Vim();
near the very bottom of vim.js.

Thanks for any help!

Matthew Phelps

unread,
Jan 9, 2020, 6:23:35 PM1/9/20
to tiddl...@googlegroups.com
Figured it out. Go to
$:/plugins/tiddlywiki/codemirror/edit-codemirror.js

and add desired function calls as follows

/*\
title: $:/plugins/tiddlywiki/codemirror/edit-codemirror.js
type: application/javascript
module-type: widget


Edit-codemirror widget


\*/

(function(){


/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";


var editTextWidgetFactory = require("$:/core/modules/editor/factory.js").editTextWidgetFactory,
 
CodeMirrorEngine = require("$:/plugins/tiddlywiki/codemirror/engine.js").CodeMirrorEngine;


exports
["edit-codemirror"] = editTextWidgetFactory(CodeMirrorEngine,CodeMirrorEngine);


/* place  codemirror function calls here */
CodeMirror.Vim.map('kj', '<Esc>', 'insert');
})();

Reply all
Reply to author
Forward
0 new messages