1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:20:04 +08:00

docs(bootstrap): update doc of bootstrap functions

This commit is contained in:
Eric Wong 2024-12-24 10:56:21 +08:00
parent bf643b2463
commit d064660bc1
2 changed files with 22 additions and 12 deletions

View File

@ -289,8 +289,8 @@ SpaceVim 默认安装了一些插件,如果需要禁用某个插件,可以
### 启动函数 ### 启动函数
由于 toml 配置的局限性SpaceVim 提供了两种启动函数 `bootstrap_before``bootstrap_after`在该函数内可以使用 Vim script 由于 toml 语法的局限性SpaceVim 提供了两种启动函数选项 `bootstrap_before``bootstrap_after`这两个选项分别指定两个 Vim 自定义函数
通过 `~/.SpaceVim.d/init.toml``[options]` 片段中的这两个选项 `bootstrap_before``bootstrap_after` 来指定函数名称,例如: 以在 toml 配置文件 `~/.SpaceVim.d/init.toml``[options]` 字段中设置这两个选项 `bootstrap_before``bootstrap_after` 对应的函数名称,例如:
```toml ```toml
[options] [options]
@ -298,10 +298,13 @@ SpaceVim 默认安装了一些插件,如果需要禁用某个插件,可以
bootstrap_after = "myspacevim#after" bootstrap_after = "myspacevim#after"
``` ```
这两种启动函数的区别在于,`bootstrap_before`函数是在载入用户配置时候执行的, 这两种启动函数的区别在于,`bootstrap_before` 函数是在载入用户配置时候执行的,
而`bootstrap_after`函数是在触发`VimEnter`事件时执行的。 `bootstrap_after` 函数是在触发 `VimEnter` 事件时执行的。因此,可以在 `bootstrap_after`
函数内对默认的快捷键进行修改。
启动函数文件应放置在 Vim &runtimepath 的 autoload 文件夹内。例如: 下面展示一个启动函数的示例,包含 `bootstrap_before``bootstrap_after` 两个函数:
定义启动函数的 Vim 脚本文件应放置在 Vim &runtimepath 的 autoload 文件夹内。例如:
文件名:`~/.SpaceVim.d/autoload/myspacevim.vim` 文件名:`~/.SpaceVim.d/autoload/myspacevim.vim`
@ -312,7 +315,10 @@ function! myspacevim#before() abort
endfunction endfunction
function! myspacevim#after() abort function! myspacevim#after() abort
iunmap jk " 删除默认快捷键 <F3>, 该快捷键原先设定为打开文件树
unmap <F3>
" 设定新的快捷打开文件树, 在这里假定文件树插件选择的是 defx.nvim
nnoremap <silent> <F3> :Defx<Cr>
endfunction endfunction
``` ```

View File

@ -282,11 +282,11 @@ you can use SpaceVim `disabled_plugins` in the `[options]` section of your confi
### Bootstrap Functions ### Bootstrap Functions
SpaceVim provides two kinds of bootstrap functions Due to the limitations of toml syntax, SpaceVim provides two bootstrap function options
for custom configurations and key bindings, `bootstrap_before` and `bootstrap_after`, which specify two Vim custom functions.
namely `bootstrap_before` and `bootstrap_after`.
To enable them you need to add the following into lines to the `[options]` section of your configuration file. To enable this feature you need to add the following config to the `[options]` section of your
configuration file `~/.SpaceVim.d/init.toml`.
```toml ```toml
[options] [options]
@ -295,7 +295,8 @@ To enable them you need to add the following into lines to the `[options]` secti
``` ```
The difference is that the bootstrap before function will be called before SpaceVim core, The difference is that the bootstrap before function will be called before SpaceVim core,
and the bootstrap after function is called on autocmd `VimEnter`. and the bootstrap after function is called on autocmd `VimEnter`, so you can override defaults
key bindings in `bootstrap_after` function.
The bootstrap functions should be placed in the `autoload` directory The bootstrap functions should be placed in the `autoload` directory
in `~/.SpaceVim.d/`. In our case, create file `~/.SpaceVim.d/autoload/myspacevim.vim` in `~/.SpaceVim.d/`. In our case, create file `~/.SpaceVim.d/autoload/myspacevim.vim`
@ -311,7 +312,10 @@ endfunction
function! myspacevim#after() abort function! myspacevim#after() abort
" you can remove key binding in bootstrap_after function " you can remove key binding in bootstrap_after function
iunmap kj " for example, remove F3 which is to open file tree by default.
unmap <F3>
" create new key binding to open file tree.
nnoremap <silent> <F3> :Defx<Cr>
endfunction endfunction
``` ```