Skip to content

Instantly share code, notes, and snippets.

@hslyu
Created January 26, 2022 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hslyu/6e5de9dd9eb4e9cb8dc34b85f0ed74f2 to your computer and use it in GitHub Desktop.
Save hslyu/6e5de9dd9eb4e9cb8dc34b85f0ed74f2 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Overleaf jump $
// @namespace http://tampermonkey.net/
// @version 0.1
// @match https://www.overleaf.com/project/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// poll until editor is loaded
const retry = setInterval(() => {
if (window._debug_editors === undefined) return
clearInterval(retry)
// get current editor instance
const editor = window._debug_editors[window._debug_editors.length -1]
// vim keyboard plugin
const vimKeyboard = window.ace.require("ace/keyboard/vim")
// add custom keybindings - insert mode applies on insert
vimKeyboard.Vim.map(";", "f$a", "normal")
// normal mode applies while escaped
vimKeyboard.Vim.map(";", "<esc>;", "insert")
vimKeyboard.Vim.map("{", "{}", "insert")
vimKeyboard.Vim.map("(", "()", "insert")
// set the modified keyboard handler for editor
editor.setKeyboardHandler(vimKeyboard.handler)
console.log("Custom key bindings applied")
}, 100)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment