> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/knowledge-base/049-how-can-i-define-custom-vim-macros-in-a-vimrc-file-on-overleaf.md).

# How can I define custom Vim macros in a vimrc file on Overleaf?

## Introduction

Overleaf provides Vim and Emacs keybindings that can be switched on in the [project menu](/latex/knowledge-base/148-using-the-overleaf-project-menu.md#keybindings). However, as these keybindings are emulated by the editor (i.e., there is no real Vim or Emacs running), it’s not possible to use Vim’s standard methods of adding new ones within Overleaf using Tampermonkey. Here we show ways that should help overcome this limitation.

### Overleaf policy on Tampermonkey and UserScripts

Please be advised that UserScripts and Tampermonkey are not officially supported by Overleaf and that custom scripts can interfere with Overleaf’s normal operations. If you are using such scripts, and need to contact Overleaf for technical support, then we kindly ask you to disable any Tempermonkey scripts and check whether the situation improves. If disabling the scripts does not resolve your issue, please [contact us](https://www.overleaf.com/contact) for assistance.

## Tampermonkey UserScript

Please note that this is *not* an officially supported method and the interface may change in the future, hence the “`UNSTABLE_editor`” naming.

```latex
// ==UserScript==
// @name         Overleaf Editor Custom VIM Keybindings
// @namespace    http://tampermonkey.net/
// @version      0.1
// @match        https://www.overleaf.com/project/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener("UNSTABLE_editor:extensions", (event) => {
    const { CodeMirror, CodeMirrorVim, extensions } = event.detail;

    // add custom keybindings - insert mode applies on insert
    CodeMirrorVim.Vim.map("jj", "<Esc>", "insert");
    // normal mode applies while escaped
    CodeMirrorVim.Vim.map("h", "j", "normal");
    });
})();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/knowledge-base/049-how-can-i-define-custom-vim-macros-in-a-vimrc-file-on-overleaf.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
