Skip to content
Advertisement

Enable Vim mode in gist Ace Editor

I’m trying to enable the Ace’s keyBoard handler for my beloved Vim on github gists. This seems like it would be an easy thing to do, but I am struggling to:

  1. Find the object that the gist ace editor is attached to (the ace default editor is not defined)
  2. Set it to use VIM, via github’s hosted Vim binding: https://gist.github.com/assets/ace/keybinding/vim-b9f3b98dd13151f9b4c7279d8259b69e.js

I found the following snippet on the Ace Google Group:

env.editor.setKeyboardHandler(require("ace/keyboard/keybinding/vim").Vim)

But that doesn’t work (even if I substitute the github url) so i’m assuming that that applies to the Cloud9 IDE, and not selfhosted/custom Ace.

Advertisement

Answer

I posted on the ace Google Group (+rep to Harutyun) and received a reply with the following code:

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

Which works like a charm (Do note that the version of ace that github uses may change, which may break this).

It’s a pain to enter this into the console each time, so I plan on adding it to a greasemonkey script (a chrome plugin might be nice! — well see).

Update


I’ve written a small Chrome Extension that enables Vim bindings on most sites Ace.js and CodeMirror. Issues and contributions welcome at the github repo

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement