> 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/overleaf-learn-latex-pt/base-de-conhecimento/049-how-can-i-define-custom-vim-macros-in-a-vimrc-file-on-overleaf.md).

# Como posso definir macros Vim personalizadas num ficheiro vimrc no Overleaf?

## Introdução

O Overleaf disponibiliza atalhos de teclado do Vim e do Emacs que podem ser ativados no [menu do projeto](/latex/overleaf-learn-latex-pt/base-de-conhecimento/148-using-the-overleaf-project-menu.md#keybindings). No entanto, como estes atalhos de teclado são emulados pelo editor (ou seja, não há um Vim ou Emacs reais em execução), não é possível usar os métodos padrão do Vim para adicionar novos dentro do Overleaf usando Tampermonkey. Aqui mostramos formas que deverão ajudar a ultrapassar esta limitação.

### Política do Overleaf sobre Tampermonkey e UserScripts

Tenha em atenção que UserScripts e Tampermonkey não são oficialmente suportados pelo Overleaf e que scripts personalizados podem interferir com o funcionamento normal do Overleaf. Se estiver a usar estes scripts e precisar de contactar o Overleaf para apoio técnico, pedimos-lhe que desative quaisquer scripts do Tempermonkey e verifique se a situação melhora. Se desativar os scripts não resolver o seu problema, por favor [contacte-nos](https://www.overleaf.com/contact) para obter assistência.

## UserScript do Tampermonkey

Tenha em atenção que este é *contém* um método oficialmente suportado e a interface pode mudar no futuro, daí a “`UNSTABLE_editor`” nomenclatura.

```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;

    // adicionar atalhos de teclado personalizados - o modo de inserção aplica-se na inserção
    CodeMirrorVim.Vim.map("jj", "<Esc>", "insert");
    // o modo normal aplica-se quando se sai
    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/overleaf-learn-latex-pt/base-de-conhecimento/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.
