Skip to content

Commit e99616b

Browse files
committed
doc: tidy quick start, enhance on_attach
1 parent 5cc18d4 commit e99616b

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

doc/nvim-tree-lua.txt

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*nvim-tree.lua* A File Explorer For Neovim Written In Lua
22

3-
Author: Yazdani Kiyan <yazdani.kiyan@protonmail.com>
3+
Author: Yazdani Kiyan
44

55
==============================================================================
66
CONTENTS *nvim-tree*
@@ -73,39 +73,30 @@ Requirements
7373

7474
==============================================================================
7575
2. QUICK START *nvim-tree-quickstart*
76+
>
77+
-- disable netrw at the very start of your init.lua (strongly advised)
78+
vim.g.loaded_netrw = 1
79+
vim.g.loaded_netrwPlugin = 1
7680
77-
Setup should be run in a lua file or in a |lua-heredoc| if using in a vim file.
78-
79-
-- examples for your init.lua
80-
81-
-- disable netrw at the very start of your init.lua (strongly advised)
82-
vim.g.loaded_netrw = 1
83-
vim.g.loaded_netrwPlugin = 1
84-
85-
-- set termguicolors to enable highlight groups
86-
vim.opt.termguicolors = true
81+
-- set termguicolors to enable highlight groups
82+
vim.opt.termguicolors = true
8783
88-
-- empty setup using defaults
89-
require("nvim-tree").setup()
84+
-- empty setup using defaults
85+
require("nvim-tree").setup()
9086
91-
-- OR setup with some options
92-
require("nvim-tree").setup({
93-
sort_by = "case_sensitive",
94-
view = {
95-
width = 30,
96-
mappings = {
97-
list = {
98-
{ key = "u", action = "dir_up" },
99-
},
100-
},
101-
},
102-
renderer = {
103-
group_empty = true,
104-
},
105-
filters = {
106-
dotfiles = true,
107-
},
108-
})
87+
-- OR setup with some options
88+
require("nvim-tree").setup({
89+
sort_by = "case_sensitive",
90+
view = {
91+
width = 30,
92+
},
93+
renderer = {
94+
group_empty = true,
95+
},
96+
filters = {
97+
dotfiles = true,
98+
},
99+
})
109100
<
110101
==============================================================================
111102
3. COMMANDS *nvim-tree-commands*
@@ -1729,35 +1720,44 @@ Active mappings may be viewed via HELP, default `g?`. The mapping's description
17291720
is used when displaying HELP.
17301721

17311722
The `on_attach` function is passed the `bufnr` of nvim-tree. Use
1732-
|vim.keymap.set()| or |nvim_set_keymap()| to define mappings as usual. e.g.
1733-
>
1734-
local M = {}
1723+
|vim.keymap.set()| or |nvim_set_keymap()| to define mappings as usual. e.g. >
17351724
1736-
local api = require("nvim-tree.api")
1725+
local function my_on_attach(bufnr)
1726+
local api = require('nvim-tree.api')
17371727
1738-
function M.on_attach(bufnr)
1739-
-- put some default mappings here
1740-
vim.keymap.set('n', 'h', api.tree.toggle_help, { desc = 'Help', buffer = bufnr, noremap = true, silent = true, nowait = true })
1741-
vim.keymap.set('n', '?', api.tree.toggle_help, { desc = 'Help', buffer = bufnr, noremap = true, silent = true, nowait = true })
1742-
vim.keymap.set('n', 'p', M.print_node_path, { desc = 'Print', buffer = bufnr, noremap = true, silent = true, nowait = true })
1728+
local function opts(desc)
1729+
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
17431730
end
17441731
1745-
function M.print_node_path()
1746-
local node = api.tree.get_node_under_cursor()
1747-
print(node.absolute_path)
1748-
end
1732+
-- put some default mappings here
17491733
1750-
require("nvim-tree").setup({
1751-
on_attach = M.on_attach,
1752-
--
1753-
})
1734+
-- user mappings
1735+
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
1736+
end
1737+
1738+
require("nvim-tree").setup({
1739+
---
1740+
on_attach = my_on_attach,
1741+
---
1742+
})
17541743
<
17551744
Mouse support is defined in |KeyBindings|
17561745

17571746
Single left mouse mappings can be achieved via `<LeftRelease>`.
17581747

17591748
Single right / middle mouse mappings will require changes to |mousemodel| or |mouse|.
17601749

1750+
You may execute your own functions as well as |nvim-tree-api| functions e.g. >
1751+
1752+
local function print_node_path()
1753+
local api = require('nvim-tree.api')
1754+
local node = api.tree.get_node_under_cursor()
1755+
print(node.absolute_path)
1756+
end
1757+
1758+
-- on_attach
1759+
vim.keymap.set('n', '<C-P>', print_node_path, opts('Print Path'))
1760+
<
17611761
==============================================================================
17621762
6.1 DEFAULT MAPPINGS *nvim-tree-mappings-default*
17631763

0 commit comments

Comments
 (0)