@@ -643,21 +643,17 @@ Function ran when creating the nvim-tree buffer.
643
643
This can be used to attach keybindings to the tree buffer.
644
644
When on_attach is "disabled", it will use the older mapping strategy, otherwise it
645
645
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
- <
659
646
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
+ <
661
657
*nvim-tree.remove_keymaps*
662
658
This can be used to remove the default mappings in the tree.
663
659
- Remove specific keys by passing a `string ` table of keys
@@ -1172,15 +1168,15 @@ A good functionality to enable is |nvim-tree.hijack_directories|.
1172
1168
1173
1169
Nvim-tree's public API can be used to access features.
1174
1170
>
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()
1178
1174
<
1179
1175
This module exposes stable functionalities, it is advised to use this in order
1180
1176
to avoid breaking configurations due to internal breaking changes.
1181
1177
1182
1178
The api is separated in multiple modules, which can be accessed with
1183
- `require ( " nvim-tree. api" ).moduleName.functionality` .
1179
+ `api. <module> . <function> `
1184
1180
1185
1181
Functions that needs a tree node parameter are exposed with an abstraction
1186
1182
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.
1520
1516
1521
1517
| nvim_tree_registering_handlers |
1522
1518
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 .
1525
1521
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")
1529
1524
local Event = api.events.Event
1530
1525
1531
1526
api.events.subscribe(Event.NodeRenamed, function(data)
1532
1527
print("Node renamed from " .. data.old_name .. " to " .. data.new_name)
1533
1528
end)
1534
1529
<
1535
-
1536
1530
| nvim_tree_events_kind |
1537
1531
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
-
1544
1532
- Event.Ready
1545
1533
When NvimTree has been initialized
1546
1534
• Note: Handler takes no parameter.
0 commit comments