Created
December 11, 2018 08:45
-
-
Save nampdn/1f576c90b0b3dd92a61b43bba21c9d47 to your computer and use it in GitHub Desktop.
Add vim for CodeMirror in glitch.me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var makeCursorFat = function() { | |
var style = document.createElement('style'); | |
style.textContent = | |
'div.CodeMirror div.CodeMirror-cursor { ' + | |
'width: auto; ' + | |
'border: 0; ' + | |
'background: transparent; ' + | |
'background: rgba(0, 200, 0, .4); ' + | |
'} '; | |
document.head.appendChild(style); | |
} | |
var addScript = function(callback) { | |
var scr = document.createElement('script'); | |
scr.src = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.22.0/keymap/vim.js'; | |
scr.onload = callback; | |
document.head.appendChild(scr); | |
} | |
var retryInterval = 1000; | |
var vimify = function () { | |
var editorElement = document.querySelector('#text-editor > div.CodeMirror'); | |
if (editorElement) { | |
editorElement.CodeMirror.options.keyMap = 'vim'; | |
editorElement.CodeMirror.options.showCursorWhenSelecting = 'vim'; | |
makeCursorFat(); | |
console.log('VIMification complete!'); | |
} else{ | |
retryInterval = retryInterval * 2; | |
if (retryInterval < 20000) { | |
console.log('Retrying to VIMify... ' + retriesLeft); | |
window.setTimeout(vimify, retryInterval); | |
} | |
return; | |
} | |
}; | |
addScript(vimify); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment