> 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/vi/co-so-tri-thuc/049-how-can-i-define-custom-vim-macros-in-a-vimrc-file-on-overleaf.md).

# Làm thế nào để tôi định nghĩa macro Vim tùy chỉnh trong tệp vimrc trên Overleaf?

## Giới thiệu

Overleaf cung cấp các phím tắt Vim và Emacs có thể được bật trong [menu dự án](/latex/vi/co-so-tri-thuc/148-using-the-overleaf-project-menu.md#keybindings). Tuy nhiên, vì các phím tắt này được trình soạn thảo mô phỏng (tức là không có Vim hay Emacs thật đang chạy), nên không thể dùng các phương pháp chuẩn của Vim để thêm phím tắt mới trong Overleaf bằng Tampermonkey. Ở đây chúng tôi trình bày các cách có thể giúp khắc phục hạn chế này.

### Chính sách của Overleaf về Tampermonkey và UserScripts

Xin lưu ý rằng UserScripts và Tampermonkey không được Overleaf hỗ trợ chính thức và các script tùy chỉnh có thể gây ảnh hưởng đến hoạt động bình thường của Overleaf. Nếu bạn đang sử dụng các script như vậy và cần liên hệ với Overleaf để được hỗ trợ kỹ thuật, thì chúng tôi kính đề nghị bạn vô hiệu hóa mọi script Tempermonkey và kiểm tra xem tình hình có cải thiện không. Nếu việc vô hiệu hóa các script không giải quyết được vấn đề của bạn, vui lòng [liên hệ với chúng tôi](https://www.overleaf.com/contact) để được hỗ trợ.

## UserScript Tampermonkey

Xin lưu ý rằng đây là *không* một phương pháp được hỗ trợ chính thức và giao diện có thể thay đổi trong tương lai, do đó có tên “`UNSTABLE_editor`”.

```latex
// ==UserScript==
// @name         Phím tắt VIM tùy chỉnh cho trình soạn thảo Overleaf
// @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;

    // thêm các phím tắt tùy chỉnh - chế độ chèn áp dụng khi chèn
    CodeMirrorVim.Vim.map("jj", "<Esc>", "insert");
    // chế độ bình thường áp dụng khi thoát
    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/vi/co-so-tri-thuc/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.
