docs: add on_attach to quickstart (#2236)
This commit is contained in:
parent
e2a4c9d09d
commit
58d1014324
26
README.md
26
README.md
@ -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?`
|
||||||
|
|||||||
@ -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?`
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user