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
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")
})
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With