benweet / stackedit

In-browser Markdown editor
https://stackedit.io/
Apache License 2.0
21.6k stars 2.71k forks source link

Vim / Emacs Keybindings #254

Open aurecchia opened 10 years ago

aurecchia commented 10 years ago

Since StackEdit uses the ACE editor, is it possible for you to enable Vim and Emacs keybindings?

rozaxe commented 10 years ago

I find a way to do that When StackEdit is loaded, open the web console (Ctrl + Shift + K under Firefox) and paste this

var ace = {}
ace.require = require
ace.define = define
ace.require(["ace/lib/net"], function(acenet) {
    acenet.loadScript("https://rawgithub.com/ajaxorg/ace-builds/master/src-min-noconflict/keybinding-vim.js", function() {
        e = document.querySelector(".ace_editor").env.editor
        ace.require(["ace/keyboard/vim"], function(acevim) {
            e.setKeyboardHandler(acevim.handler);
        })
    })
})

But, you need to do this each time you load the page,

So, I'm searching for a way more user friendly

But i enjoy that do what you want

aurecchia commented 10 years ago

Just tried that and it works! I think I could automate it with a greasemonkey script.

Thank you very much!

benweet commented 10 years ago

You can wrap this code into a StackEdit extension:

userCustom.onReady = function() {
    var ace = {}
    ace.require = require
    ace.define = define
    ace.require(["ace/lib/net"], function(acenet) {
        acenet.loadScript("https://rawgithub.com/ajaxorg/ace-builds/master/src-min-noconflict/keybinding-vim.js", function() {
            e = document.querySelector(".ace_editor").env.editor
            ace.require(["ace/keyboard/vim"], function(acevim) {
                e.setKeyboardHandler(acevim.handler);
            });
        });
    });
    window.ace = ace;
};

Just copy/paste in Settings->Extensions->UserCustom.

rozaxe commented 10 years ago

And here the emacs version (if someone is interested)

userCustom.onReady = function() {
    var ace = {}
    ace.require = require
    ace.define = define
    ace.require(["ace/lib/net"], function(acenet) {
        acenet.loadScript("https://rawgithub.com/ajaxorg/ace-builds/master/src-min-noconflict/keybinding-emacs.js", function() {
            e = document.querySelector(".ace_editor").env.editor
            ace.require(["ace/keyboard/emacs"], function(acekey) {
                e.setKeyboardHandler(acekey.handler);
            })
        })
    })
    window.ace = ace
}
oantolin commented 10 years ago

It's not polite to use rawgithub.com to serve the keybindings script, and in fact, it currently doesn't work, and instead returns "The requested URI has been blacklisted due to abuse.".

The ACE embedding guide suggests using a CDN like cdnjs, //cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/keybinding-vim.js, or jsDelivr, //cdn.jsdelivr.net/ace/1.1.01/min/keybinding-vim.js. Using either of those in place of the rawgithub URI in the above function seems to work.

I also read somewhere that ACE 1.1.1 comes with both vim and emacs by default. I think this means that if StackEdit updates its ACE version, the extension could be simplified to just

document.querySelector(".ace_editor").env.editor.setKeyboardHandler("ace/keyboard/vim");
cben commented 10 years ago

2014-01-29 oantolin notifications@github.com

It's not polite to use rawgithub.com to serve the keybindings script, and in fact, it currently doesn't work, GitHub returns "The requested URI has been blacklisted due to abuse.".

Small clarification: as http://rawgithub.com explains, it's not run by GitHub, it's a private service.

oantolin commented 10 years ago

Thanks for the clarification, @cben.

benweet commented 10 years ago

I also read somewhere that ACE 1.1.1 comes with both vim and emacs by default. I think this means that if StackEdit updates its ACE version...

StackEdit uses a revision of ACE master branch ahead of version 1.1.1. document.querySelector(".ace_editor").env.editor.setKeyboardHandler("ace/keyboard/vim"); doesn't work on https://stackedit.io simply because StackEdit is bundled with required modules only.

ostrain commented 10 years ago

This would be nice to have as a built-in feature. As an OS X user, I expect all text fields to support basic emacs keybindings. It's jarring to use a text editor that doesn't support them, especially since all and