doc: tidy quick start, enhance on_attach

This commit is contained in:
Alexander Courtis 2023-04-18 14:38:57 +10:00
parent 5cc18d4f2f
commit e99616bebe

View File

@ -1,6 +1,6 @@
*nvim-tree.lua* A File Explorer For Neovim Written In Lua
Author: Yazdani Kiyan <yazdani.kiyan@protonmail.com>
Author: Yazdani Kiyan
==============================================================================
CONTENTS *nvim-tree*
@ -73,11 +73,7 @@ Requirements
==============================================================================
2. QUICK START *nvim-tree-quickstart*
Setup should be run in a lua file or in a |lua-heredoc| if using in a vim file.
-- examples for your init.lua
>
-- disable netrw at the very start of your init.lua (strongly advised)
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
@ -93,11 +89,6 @@ Setup should be run in a lua file or in a |lua-heredoc| if using in a vim file.
sort_by = "case_sensitive",
view = {
width = 30,
mappings = {
list = {
{ key = "u", action = "dir_up" },
},
},
},
renderer = {
group_empty = true,
@ -1729,27 +1720,25 @@ Active mappings may be viewed via HELP, default `g?`. The mapping's description
is used when displaying HELP.
The `on_attach` function is passed the `bufnr` of nvim-tree. Use
|vim.keymap.set()| or |nvim_set_keymap()| to define mappings as usual. e.g.
>
local M = {}
|vim.keymap.set()| or |nvim_set_keymap()| to define mappings as usual. e.g. >
local api = require("nvim-tree.api")
local function my_on_attach(bufnr)
local api = require('nvim-tree.api')
function M.on_attach(bufnr)
-- put some default mappings here
vim.keymap.set('n', 'h', api.tree.toggle_help, { desc = 'Help', buffer = bufnr, noremap = true, silent = true, nowait = true })
vim.keymap.set('n', '?', api.tree.toggle_help, { desc = 'Help', buffer = bufnr, noremap = true, silent = true, nowait = true })
vim.keymap.set('n', 'p', M.print_node_path, { desc = 'Print', buffer = bufnr, noremap = true, silent = true, nowait = true })
local function opts(desc)
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
function M.print_node_path()
local node = api.tree.get_node_under_cursor()
print(node.absolute_path)
-- put some default mappings here
-- user mappings
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
end
require("nvim-tree").setup({
on_attach = M.on_attach,
--
---
on_attach = my_on_attach,
---
})
<
Mouse support is defined in |KeyBindings|
@ -1758,6 +1747,17 @@ Single left mouse mappings can be achieved via `<LeftRelease>`.
Single right / middle mouse mappings will require changes to |mousemodel| or |mouse|.
You may execute your own functions as well as |nvim-tree-api| functions e.g. >
local function print_node_path()
local api = require('nvim-tree.api')
local node = api.tree.get_node_under_cursor()
print(node.absolute_path)
end
-- on_attach
vim.keymap.set('n', '<C-P>', print_node_path, opts('Print Path'))
<
==============================================================================
6.1 DEFAULT MAPPINGS *nvim-tree-mappings-default*