Reputation: 2735
I'm integrating the Ace Editor in a web app and using the vim key-bindings like so:
var editor = ace.edit('editor');
editor.setDisplayIndentGuides(false);
editor.setHighlightActiveLine(false);
editor.setShowFoldWidgets(false);
editor.setShowInvisibles(false);
editor.setShowPrintMargin(false);
editor.setKeyboardHandler('ace/keyboard/vim');
I also have this command mapped to Ctrl-S/Command-S just because I wanted to test the behaviour
editor.commands.addCommand({
name: 'saveFile',
bindKey: {
win: 'Ctrl-S', mac: 'Command-S',
sender: 'editor|cli'
},
exec: function (env, args, request) {
console.log('saving...', env, args, request);
}
});
While this works, the problem is that when using the ESCape key to enter "normal" mode in Vim, and using :w to save the file, the command's exec function defined above does not get invoked as it does with Ctrl-S/Command-S ...
And the keybinding-vim.js file throws an Error about CodeMirror.commands.save not being defined ...
I have looked at the API documentation and demos but have been unable to find the "correct" way to fix this.
Help appreciated. Thanks
Upvotes: 9
Views: 3660
Reputation: 370
brace
import ace from 'brace';
require('brace/keybinding/vim');
editor.setKeyboardHandler('ace/keyboard/vim');
ace.config.loadModule('ace/keyboard/vim', function(module) {
var VimApi = module.CodeMirror.Vim;
VimApi.defineEx('write', 'w', function(cm, input) {
cm.ace.execCommand('save');
});
});
Upvotes: 0
Reputation: 24104
There is no public api for doing this yet. But you can do
ace.config.loadModule("ace/keyboard/vim", function(m) {
var VimApi = require("ace/keyboard/vim").CodeMirror.Vim
VimApi.defineEx("write", "w", function(cm, input) {
cm.ace.execCommand("save")
})
})
Upvotes: 12