mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
feat(keys): more advanced options for setting lazy key mappings
This commit is contained in:
parent
28f1511e0a
commit
1c07ea15a3
4 changed files with 111 additions and 46 deletions
73
README.md
73
README.md
|
@ -78,29 +78,29 @@ require("lazy").setup({
|
|||
|
||||
## 🔌 Plugin Spec
|
||||
|
||||
| Property | Type | Description |
|
||||
| ---------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `[1]` | `string?` | Short plugin url. Will be expanded using `config.git.url_format` |
|
||||
| **dir** | `string?` | A directory pointing to a local plugin |
|
||||
| **url** | `string?` | A custom git url where the plugin is hosted |
|
||||
| **name** | `string?` | A custom name for the plugin used for the local plugin directory and as the display name |
|
||||
| **dev** | `boolean?` | When `true`, a local plugin directory will be used instead. See `config.dev` |
|
||||
| **lazy** | `boolean?` | When `true`, the plugin will only be loaded when needed. Lazy-loaded plugins are automatically loaded when their lua modules are `required`, or when one of the laz-loading handlers triggers |
|
||||
| **enabled** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be used |
|
||||
| **dependencies** | `LazySpec[]` | A list of plugin specs that should be loaded when the plugin loads. Dependencies are always lazy-loaded unless specified otherwise |
|
||||
| **init** | `fun(LazyPlugin)` | `init` functions are always executed during startup |
|
||||
| **config** | `fun(LazyPlugin)` | `config` is executed when the plugin loads |
|
||||
| **build** | `fun(LazyPlugin)` | `build` is executed when a plugin is installed or updated |
|
||||
| **branch** | `string?` | Branch of the repository |
|
||||
| **tag** | `string?` | Tag of the repository |
|
||||
| **commit** | `string?` | Commit of the repository |
|
||||
| **version** | `string?` | Version to use from the repository. Full [Semver](https://devhints.io/semver) ranges are supported |
|
||||
| **pin** | `boolean?` | When `true`, this plugin will not be included in updates |
|
||||
| **event** | `string?` or `string[]` | Lazy-load on event |
|
||||
| **cmd** | `string?` or `string[]` | Lazy-load on command |
|
||||
| **ft** | `string?` or `string[]` | Lazy-load on filetype |
|
||||
| **keys** | `string?` or `string[]` | Lazy-load on key mapping |
|
||||
| **module** | `false?` | Do not automatically load this lua module when it's required somewhere |
|
||||
| Property | Type | Description |
|
||||
| ---------------- | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `[1]` | `string?` | Short plugin url. Will be expanded using `config.git.url_format` |
|
||||
| **dir** | `string?` | A directory pointing to a local plugin |
|
||||
| **url** | `string?` | A custom git url where the plugin is hosted |
|
||||
| **name** | `string?` | A custom name for the plugin used for the local plugin directory and as the display name |
|
||||
| **dev** | `boolean?` | When `true`, a local plugin directory will be used instead. See `config.dev` |
|
||||
| **lazy** | `boolean?` | When `true`, the plugin will only be loaded when needed. Lazy-loaded plugins are automatically loaded when their lua modules are `required`, or when one of the laz-loading handlers triggers |
|
||||
| **enabled** | `boolean?` or `fun():boolean` | When `false`, or if the `function` returns false, then this plugin will not be used |
|
||||
| **dependencies** | `LazySpec[]` | A list of plugin specs that should be loaded when the plugin loads. Dependencies are always lazy-loaded unless specified otherwise |
|
||||
| **init** | `fun(LazyPlugin)` | `init` functions are always executed during startup |
|
||||
| **config** | `fun(LazyPlugin)` | `config` is executed when the plugin loads |
|
||||
| **build** | `fun(LazyPlugin)` | `build` is executed when a plugin is installed or updated |
|
||||
| **branch** | `string?` | Branch of the repository |
|
||||
| **tag** | `string?` | Tag of the repository |
|
||||
| **commit** | `string?` | Commit of the repository |
|
||||
| **version** | `string?` | Version to use from the repository. Full [Semver](https://devhints.io/semver) ranges are supported |
|
||||
| **pin** | `boolean?` | When `true`, this plugin will not be included in updates |
|
||||
| **event** | `string?` or `string[]` | Lazy-load on event |
|
||||
| **cmd** | `string?` or `string[]` | Lazy-load on command |
|
||||
| **ft** | `string?` or `string[]` | Lazy-load on filetype |
|
||||
| **keys** | `string?` or `string[]` or `LazyKeys[]` | Lazy-load on key mapping |
|
||||
| **module** | `false?` | Do not automatically load this lua module when it's required somewhere |
|
||||
|
||||
### Lazy Loading
|
||||
|
||||
|
@ -124,6 +124,33 @@ Plugins will be lazy-loaded when one of the following is `true`:
|
|||
- it defines an `init` method
|
||||
- `config.defaults.lazy == true`
|
||||
|
||||
#### ⌨️ Lazy Key Mappings
|
||||
|
||||
The `keys` property can be a `string` or `string[]` for simple normal-mode mappings, or it
|
||||
can be a `LazyKeys` table with the following key-value pairs:
|
||||
|
||||
- **[1]**: (`string`) lhs **_(required)_**
|
||||
- **[2]**: (`string|fun()`) rhs **_(optional)_**
|
||||
- **mode**: (`string|string[]`) mode **_(optional, defaults to `"n"`)_**
|
||||
- any other option valid for `vim.keymap.set`
|
||||
|
||||
Key mappings will load the plugin the first time they get executed.
|
||||
|
||||
When `[2]` is `nil`, then the real mapping has to be created by the `config()` function.
|
||||
|
||||
```lua
|
||||
-- Example for neo-tree.nvim
|
||||
{
|
||||
"nvim-neo-tree/neo-tree.nvim",
|
||||
keys = {
|
||||
{ "<leader>ft", "<cmd>Neotree toggle<cr>", desc = "NeoTree" },
|
||||
},
|
||||
config = function()
|
||||
require("neo-tree").setup()
|
||||
end,
|
||||
}
|
||||
```
|
||||
|
||||
### Versioning
|
||||
|
||||
If you want to install a specific revision of a plugin, you can use `commit`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue