# 原生插件管理

## 說明

vim8 內建的插件管理器\
在 vim8 版本以前，請改用 [vim-plug](/workspace/vim/wai-gua-tui-jian/cha-jian-guan-li-qi/vim-plug.md)

## 目錄

vim 會在 .vim/pack 目錄下搜尋插件目錄

首先在 .vim/pack 目錄下建立一個目錄\
.vim/pack/<你的目錄>

## opt

### 目錄位置

.vim/pack/<你的目錄>/opt/插件

### 說明

此目錄底下的插件，可用於手動載入

### 指令

`:packadd <目錄名稱>`\
手動載入插件

延遲載入方法

{% code title=".vimrc" %}

```
" 當執行 :cmd 指令時才載入 <目錄名稱> 插件，並執行 :cmd
commannd ! -nargs=* cmd :packadd <目錄名稱> | cmd <f-args>

# 當文件類型為 type 時才載入 <目錄名稱> 插件，並執行插件指令
autocmd filetype type :packadd <目錄名稱> | {插件指令}
```

{% endcode %}

## start

### 目錄位置

.vim/pack/<你的目錄>/start/插件

### 說明

此目錄底下的插件，始終載入

## 設定

{% code title=".vimrc" %}

```
" 載入 start 目錄中所有的插件
" 預設會在載入 .vimrc 之後自動執行
packloadall

" 載入所有插件的幫助文件
silent! helptags ALL
```

{% endcode %}

## 使用 git 管理插件

### 初始化 git 倉庫

```
$ cd ~/.vim
$ git init
```

### 新增插件

```
$ git submodule add https://github.com/{插件網址} pack/<你的目錄>/start/<目錄名稱>
$ git commit -am "add: <目錄名稱>"
```

### 更新插件

```
$ git submodule update --recursive
$ git commit -am "mod: update plugins"
```

### 刪除插件

```
$ git submodule deinit -f --pack/<目錄名稱>
$ rm -rf .git/modules/pack/<你的目錄>/start/<目錄名稱>
$ git rm -f pack/<你的目錄>/start/<目錄名稱>
```


---

# Agent Instructions: 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:

```
GET https://kanneg881.gitbook.io/workspace/vim/wai-gua-tui-jian/cha-jian-guan-li-qi/yuan-sheng-cha-jian-guan-li-wei-wan-cheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
