Skip to content

Commit 3c5d9dd

Browse files
committed
doc: consolidate and clarify :help examples
1 parent c5dc80c commit 3c5d9dd

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

doc/nvim-tree-lua.txt

+18-30
Original file line numberDiff line numberDiff line change
@@ -643,21 +643,17 @@ Function ran when creating the nvim-tree buffer.
643643
This can be used to attach keybindings to the tree buffer.
644644
When on_attach is "disabled", it will use the older mapping strategy, otherwise it
645645
will use the newer one.
646-
>
647-
on_attach = function(bufnr)
648-
local inject_node = require("nvim-tree.utils").inject_node
649-
650-
vim.keymap.set("n", "<leader>n", inject_node(function(node)
651-
if node then
652-
print(node.absolute_path)
653-
end
654-
end), { buffer = bufnr, noremap = true })
655-
656-
vim.bo[bufnr].path = "/tmp"
657-
end
658-
<
659646
Type: `function(bufnr)`, Default: `"disable"`
660-
647+
e.g. >
648+
local api = require("nvim-tree.api")
649+
650+
local function on_attach(bufnr)
651+
vim.keymap.set("n", "<C-P>", function()
652+
local node = api.tree.get_node_under_cursor()
653+
print(node.absolute_path)
654+
end, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = "print the node's absolute path" })
655+
end
656+
<
661657
*nvim-tree.remove_keymaps*
662658
This can be used to remove the default mappings in the tree.
663659
- Remove specific keys by passing a `string` table of keys
@@ -1172,15 +1168,15 @@ A good functionality to enable is |nvim-tree.hijack_directories|.
11721168

11731169
Nvim-tree's public API can be used to access features.
11741170
>
1175-
local nt_api = require("nvim-tree.api")
1176-
1177-
nt_api.tree.toggle()
1171+
e.g. >
1172+
local api = require("nvim-tree.api")
1173+
api.tree.toggle()
11781174
<
11791175
This module exposes stable functionalities, it is advised to use this in order
11801176
to avoid breaking configurations due to internal breaking changes.
11811177

11821178
The api is separated in multiple modules, which can be accessed with
1183-
`require("nvim-tree.api").moduleName.functionality`.
1179+
`api.<module>.<function>`
11841180

11851181
Functions that needs a tree node parameter are exposed with an abstraction
11861182
that injects the node from the cursor position in the tree when calling
@@ -1520,27 +1516,19 @@ to |nvim_tree_registering_handlers| for more information.
15201516

15211517
|nvim_tree_registering_handlers|
15221518

1523-
Handlers are registered by calling the `events.subscribe` function available in the
1524-
`require("nvim-tree.api")` module.
1519+
Handlers are registered by calling |nvim-tree-api| `events.subscribe`
1520+
function with an `events.Event` kind.
15251521

1526-
For example, registering a handler for when a node is renamed is done like this:
1527-
>
1528-
local api = require('nvim-tree.api')
1522+
e.g. handler for node renamed: >
1523+
local api = require("nvim-tree.api")
15291524
local Event = api.events.Event
15301525
15311526
api.events.subscribe(Event.NodeRenamed, function(data)
15321527
print("Node renamed from " .. data.old_name .. " to " .. data.new_name)
15331528
end)
15341529
<
1535-
15361530
|nvim_tree_events_kind|
15371531

1538-
You can access the event enum with:
1539-
>
1540-
local Event = require('nvim-tree.api').events.Event
1541-
<
1542-
Here is the list of available variant of this enum:
1543-
15441532
- Event.Ready
15451533
When NvimTree has been initialized
15461534
• Note: Handler takes no parameter.

0 commit comments

Comments
 (0)