> 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/ja/narejjibsu/049-how-can-i-define-custom-vim-macros-in-a-vimrc-file-on-overleaf.md).

# OverleafのvimrcファイルでカスタムVimマクロを定義するにはどうすればよいですか？

## はじめに

Overleaf は、Vim と Emacs のキーバインドを提供しており、 [プロジェクトメニュー](/latex/ja/narejjibsu/148-using-the-overleaf-project-menu.md#keybindings)。ただし、これらのキーバインドはエディタによってエミュレートされているため（つまり、実際の Vim や Emacs が動作しているわけではありません）、Tampermonkey を使用して Overleaf 内で Vim の標準的な方法で新しいものを追加することはできません。ここでは、この制限を克服するのに役立つ方法を示します。

### Tampermonkey と UserScripts に関する Overleaf のポリシー

UserScripts と Tampermonkey は Overleaf による公式サポート対象ではなく、カスタムスクリプトは Overleaf の通常動作に干渉する可能性があることにご留意ください。これらのスクリプトを使用しており、技術サポートのために Overleaf に連絡する必要がある場合は、恐れ入りますが、すべての Tempermonkey スクリプトを無効にして、状況が改善するかご確認ください。スクリプトを無効にしても問題が解決しない場合は、 [お問い合わせください](https://www.overleaf.com/contact) サポートのために。

## Tampermonkey の UserScript

これは *含まれていません* 公式にサポートされている方法であり、インターフェースは将来変更される可能性があるため、“`UNSTABLE_editor`” という命名になっています。

```latex
// ==UserScript==
// @name         Overleaf エディタのカスタム VIM キーバインド
// @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;

    // カスタムキーバインドを追加 - 挿入モードでは挿入時に適用されます
    CodeMirrorVim.Vim.map("jj", "<Esc>", "insert");
    // 通常モードはエスケープ状態の間に適用されます
    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/ja/narejjibsu/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.
