Skip to content

Instantly share code, notes, and snippets.

@jdearly
Last active February 1, 2022 02:52
Show Gist options
  • Save jdearly/5960f20e0e5f76682b39e374d3f700f5 to your computer and use it in GitHub Desktop.
Save jdearly/5960f20e0e5f76682b39e374d3f700f5 to your computer and use it in GitHub Desktop.
Vim Keymap for CodeMirror instances
// ==UserScript==
// @name Vim keymap for CodeMirror
// @version 0.1
// @author Josh Early
// @description Enables Vim keymap for CodeMirror instances
// @namespace https://gist.github.com/jdearly/5960f20e0e5f76682b39e374d3f700f5/raw/9aa0694f714ff31652183c3c8d3a5ca6569c167e/vim-keymap.js
// @updateURL https://gist.github.com/jdearly/5960f20e0e5f76682b39e374d3f700f5/raw/9aa0694f714ff31652183c3c8d3a5ca6569c167e/vim-keymap.js
// @downloadURL https://gist.github.com/jdearly/5960f20e0e5f76682b39e374d3f700f5/raw/9aa0694f714ff31652183c3c8d3a5ca6569c167e/vim-keymap.js
// @supportURL https://gist.github.com/jdearly/5960f20e0e5f76682b39e374d3f700f5
// @include https://*.servicenowservices.com/*
// @include https://*.service-now.com/*
// @require https://codemirror.net/keymap/vim.js
// @grant GM_addStyle
// @run-at document-idle
// ==/UserScript==
window.addEventListener('load', function() {
const themeName = 'gruvbox-dark'
GM_addStyle('@import "https://codemirror.net/theme/' + themeName + '.css"')
var instanceArray = document.querySelectorAll('.CodeMirror')
instanceArray.forEach((cm) => {
var instance = cm.CodeMirror
instance.state.keyMaps = instance.state.keyMaps.filter((x) => !x.Esc)
instance.setOption('keyMap','vim')
instance.setOption('theme', themeName)
instance.refresh()
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment