Skip to content

Instantly share code, notes, and snippets.

@aalok-sathe
Forked from allenjlw/overleaf-remap.js
Last active June 5, 2025 16:08
Show Gist options
  • Select an option

  • Save aalok-sathe/a5dab9274ac881bd20418a3530fbca70 to your computer and use it in GitHub Desktop.

Select an option

Save aalok-sathe/a5dab9274ac881bd20418a3530fbca70 to your computer and use it in GitHub Desktop.
Overleaf j k remap
// ==UserScript==
// @name Overleaf editor: map j to gj and k to gk
// @namespace http://tampermonkey.net/
// @version 0.2
// @match https://www.overleaf.com/project/*
// @grant none
// @description Remap j/k to gj/gk in Overleaf Vim normal/visual modes
// @downloadURL https://gist.githubusercontent.com/aalok-sathe/a5dab9274ac881bd20418a3530fbca70/raw/2f531157d115fd4010f6dc631cd4f1f086e41299/overleaf-remap.js
// @updateURL https://gist.githubusercontent.com/aalok-sathe/a5dab9274ac881bd20418a3530fbca70/raw/2f531157d115fd4010f6dc631cd4f1f086e41299/overleaf-remap.js
// ==/UserScript==
//Based on code from https://www.overleaf.com/learn/how-to/How_can_I_define_custom_Vim_macros_in_a_vimrc_file_on_Overleaf%3F
(function() {
'use strict';
window.addEventListener("UNSTABLE_editor:extensions", (event) => {
const { CodeMirror, CodeMirrorVim, extensions } = event.detail;
// normal mode applies while escaped
CodeMirrorVim.Vim.map("j", "gj", "normal");
CodeMirrorVim.Vim.map("k", "gk", "normal");
CodeMirrorVim.Vim.map("$", "g$", "normal");
CodeMirrorVim.Vim.map("^", "g^", "normal");
CodeMirrorVim.Vim.map("j", "gj", "visual");
CodeMirrorVim.Vim.map("k", "gk", "visual");
CodeMirrorVim.Vim.map("$", "g$", "visual");
CodeMirrorVim.Vim.map("^", "g^", "visual");
});
})();
@aalok-sathe
Copy link
Author

updated fork to also support remapping $ to work per-softwrapped-line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment