docs: add on_attach to quickstart (#2236)

This commit is contained in:
Alexander Courtis 2023-06-04 14:02:32 +10:00 committed by GitHub
parent e2a4c9d09d
commit 58d1014324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View File

@ -76,6 +76,32 @@ require("nvim-tree").setup({
}) })
``` ```
Optionally customise your mappings, see [:help nvim-tree-mappings](doc/nvim-tree-lua.txt)
```lua
local function my_on_attach(bufnr)
local api = require "nvim-tree.api"
local function opts(desc)
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- default mappings
api.config.mappings.default_on_attach(bufnr)
-- custom mappings
vim.keymap.set("n", "<C-t>", api.tree.change_root_to_parent, opts "Up")
vim.keymap.set("n", "?", api.tree.toggle_help, opts "Help")
end
-- pass to setup along with your other options
require("nvim-tree").setup {
---
on_attach = my_on_attach,
---
}
```
Open the tree: `:NvimTreeOpen` Open the tree: `:NvimTreeOpen`
Show the mappings: `g?` Show the mappings: `g?`

View File

@ -107,6 +107,30 @@ Setup the plugin in your `init.lua` >
}, },
}) })
< <
Optionally customise your |nvim-tree-mappings| via |nvim-tree.on_attach| >
local function my_on_attach(bufnr)
local api = require "nvim-tree.api"
local function opts(desc)
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- default mappings
api.config.mappings.default_on_attach(bufnr)
-- custom mappings
vim.keymap.set("n", "<C-t>", api.tree.change_root_to_parent, opts "Up")
vim.keymap.set("n", "?", api.tree.toggle_help, opts "Help")
end
-- pass to setup along with your other options
require("nvim-tree").setup {
---
on_attach = my_on_attach,
---
}
<
Open the tree: `:NvimTreeOpen` Open the tree: `:NvimTreeOpen`
Show the mappings: `g?` Show the mappings: `g?`