@@ -10,11 +10,12 @@ CONTENTS *nvim-tree*
10
10
3. Commands | nvim-tree-commands |
11
11
4. Setup/Configuration | nvim-tree-setup |
12
12
4.1 Vinegar Style | nvim-tree-vinegar |
13
- 5. Mappings | nvim-tree-mappings |
14
- 6. Highlight Groups | nvim-tree-highlight |
15
- 7. Events | nvim-tree-events |
16
- 7.1 Available Events | nvim-tree.events |
17
- 8. Bookmarks | nvim-tree-bookmarks |
13
+ 5. Api | nvim-tree-api |
14
+ 6. Mappings | nvim-tree-mappings |
15
+ 7. Highlight Groups | nvim-tree-highlight |
16
+ 8. Events | nvim-tree-events |
17
+ 8.1 Available Events | nvim-tree.events |
18
+ 9. Bookmarks | nvim-tree-bookmarks |
18
19
19
20
==============================================================================
20
21
1. INTRODUCTION *nvim-tree-introduction*
@@ -951,7 +952,97 @@ You'll also need to set |nvim-tree.hijack_netrw| to `true` during setup.
951
952
A good functionnality to enable is | nvim-tree.hijack_directories | .
952
953
953
954
==============================================================================
954
- 5. MAPPINGS *nvim-tree-mappings*
955
+ 5. API *nvim-tree-api*
956
+
957
+ Nvim-tree's public API can be used to access features.
958
+ >
959
+ local nt_api = require("nvim-tree.api")
960
+ <
961
+ This module exposes stable functionalities, it is advised to use this in order
962
+ to avoid breaking configurations due to internal breaking changes.
963
+
964
+ The api is separated in multiple modules, which can be accessed with
965
+ `require (" nvim-tree.api" ).moduleName.functionality` .
966
+
967
+ Functions that needs a tree node parameter are exposed with an abstraction
968
+ that injects the node from the cursor position in the tree when calling
969
+ the function. It will use the node you pass as an argument in priority if it
970
+ exists.
971
+
972
+ - api.tree: *nvim-tree.api.tree*
973
+ - open `(path?: string)`
974
+ - close
975
+ - toggle `(find_file?: bool, no_focus?: bool, path?: string)`
976
+ - focus
977
+ - reload
978
+ - change_root `(path: string)`
979
+ - change_root_to_parent
980
+ - get_node_under_cursor
981
+ - find_file `(filename: string)`
982
+ - search_node
983
+ - collapse_all `(keep_buffers?: bool)`
984
+ - expand_all
985
+ - toggle_gitignore_filter
986
+ - toggle_custom_filter
987
+ - toggle_hidden_filter
988
+ - toggle_help
989
+
990
+ - api.fs: *nvim-tree.api.fs*
991
+ - create
992
+ - remove
993
+ - trash
994
+ - rename
995
+ - rename_sub
996
+ - copy
997
+ - cut
998
+ - paste
999
+ - print_clipboard
1000
+ - copy.absolute_path
1001
+ - copy.filename
1002
+ - copy.relative_path
1003
+
1004
+ - api.node: *nvim-tree.api.node*
1005
+ - open.edit
1006
+ - open.vertical
1007
+ - open.horizontal
1008
+ - open.tab
1009
+ - open.preview
1010
+ - show_info_popup
1011
+ - run.cmd
1012
+ - run.system
1013
+ - navigate.sibling.next
1014
+ - navigate.sibling.prev
1015
+ - navigate.sibling.first
1016
+ - navigate.sibling.last
1017
+ - navigate.parent
1018
+ - navigate.parent_close
1019
+ - navigate.git.next
1020
+ - navigate.git.prev
1021
+ - navigate.diagnostics.next
1022
+ - navigate.diagnostics.prev
1023
+
1024
+ - api.git: *nvim-tree.api.git*
1025
+ - reload
1026
+
1027
+ - api.events: *nvim-tree.api.events*
1028
+ - subscribe `(eventType: Event, callback: function(...args))`
1029
+ - Event (enum type, please see | nvim_tree_events_kind | )
1030
+
1031
+ - api.live_filter: *nvim-tree.api.live_filter*
1032
+ - start
1033
+ - clear
1034
+
1035
+ - api.marks: *nvim-tree.api.marks*
1036
+ - get
1037
+ - list
1038
+ - toggle
1039
+ - bulk.move
1040
+ - navigate.next
1041
+ - navigate.prev
1042
+ - navigate.select
1043
+
1044
+ ==============================================================================
1045
+ 6. MAPPINGS *nvim-tree-mappings*
955
1046
956
1047
The `list ` option in `view .mappings.list ` is a table of
957
1048
@@ -1078,7 +1169,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings
1078
1169
} -- END_DEFAULT_MAPPINGS
1079
1170
<
1080
1171
==============================================================================
1081
- 6 . HIGHLIGHT GROUPS *nvim-tree-highlight*
1172
+ 7 . HIGHLIGHT GROUPS *nvim-tree-highlight*
1082
1173
1083
1174
All the following highlight groups can be configured by hand. Aside from
1084
1175
`NvimTreeWindowPicker` , it is not advised to colorize the background of these
@@ -1152,35 +1243,52 @@ NvimTreeBookmark
1152
1243
1153
1244
1154
1245
==============================================================================
1155
- 7 . EVENTS *nvim-tree-events*
1246
+ 8 . EVENTS *nvim-tree-events*
1156
1247
1157
1248
| nvim_tree_events |
1158
1249
1159
1250
nvim-tree will dispatch events whenever an action is made. These events can be
1160
1251
subscribed to through handler functions. This allows for even further
1161
1252
customization of nvim-tree.
1162
1253
1163
- A handler for an event is just a function which receives one argument -
1164
- the payload of the event. The payload is different for each event type. Refer
1254
+ A handler for an event is just a function which receives one argument, the
1255
+ payload of the event. The payload is different for each event type. Refer
1165
1256
to | nvim_tree_registering_handlers | for more information.
1166
- <
1167
1257
1168
1258
| nvim_tree_registering_handlers |
1169
1259
1170
- Handlers are registered by calling the `on_* ` functions available in the
1171
- `require (' nvim-tree.events' )` module. See | nvim-tree.events | .
1172
-
1260
+ Handlers are registered by calling the `events.subscribe` function available in the
1261
+ `require (" nvim-tree.api" )` module.
1173
1262
1174
- For example, registering a handler for when a node is renamed is done like this: >
1175
-
1176
- local events = require('nvim-tree.events ')
1263
+ For example, registering a handler for when a node is renamed is done like this:
1264
+ >
1265
+ local api = require('nvim-tree.api ')
1177
1266
1178
- events.on_node_renamed( function(data)
1267
+ api. events.subscribe(Event.NodeRenamed, function(data)
1179
1268
print("Node renamed from " .. data.old_name .. " to " .. data.new_name)
1180
1269
end)
1270
+ <
1271
+
1272
+ | nvim_tree_events_kind |
1273
+
1274
+ You can access the event enum with:
1275
+ >
1276
+ local Event = require('nvim-tree.api').events.Event
1277
+ <
1278
+ Here is the list of available variant of this enum:
1279
+
1280
+ - Event.Ready
1281
+ - Event.NodeRenamed
1282
+ - Event.TreeOpen
1283
+ - Event.TreeClose
1284
+ - Event.FileCreated
1285
+ - Event.FileRemoved
1286
+ - Event.FolderCreated
1287
+ - Event.FolderRemoved
1288
+ - Event.Resize
1181
1289
1182
1290
==============================================================================
1183
- 7 .1 Lua module: nvim-tree.events *nvim-tree.events*
1291
+ 8 .1 Lua module: nvim-tree.events *nvim-tree.events*
1184
1292
1185
1293
*nvim-tree.events.on_nvim_tree_ready()*
1186
1294
on_nvim_tree_ready({handler} )
@@ -1267,14 +1375,14 @@ on_tree_resize({handler})
1267
1375
signature `function (size)` .
1268
1376
1269
1377
==============================================================================
1270
- 8 . BOOKMARKS *nvim-tree-bookmarks*
1378
+ 9 . BOOKMARKS *nvim-tree-bookmarks*
1271
1379
1272
1380
You can toggle marks on files/folders with
1273
- `require (" nvim-tree.marks " ).toggle_mark (node)` which is bound to `m ` by
1381
+ `require (" nvim-tree.api " ).marks . toggle (node)` which is bound to `m ` by
1274
1382
default.
1275
1383
1276
1384
To get the list of marked paths, you can call
1277
- `require (" nvim-tree.marks " ).get_marks ()` . This will return `{node}` .
1385
+ `require (" nvim-tree.api " ).marks . list ()` . This will return `{node}` .
1278
1386
1279
1387
*nvim-tree.bookmarks.navigation*
1280
1388
@@ -1284,8 +1392,8 @@ want to focus the tree view each time we wish to switch to another mark.
1284
1392
This requires binding bookmark navigation yourself.
1285
1393
1286
1394
-- in your lua configuration
1287
- vim.keymap.set("n", "<leader> mn", require("nvim-tree.marks.navigation") .next)
1288
- vim.keymap.set("n", "<leader> mp", require("nvim-tree.marks.navigation") .prev)
1289
- vim.keymap.set("n", "<leader> ms", require("nvim-tree.marks.navigation") .select)
1395
+ vim.keymap.set("n", "<leader> mn", require("nvim-tree.api").marks.navigate .next)
1396
+ vim.keymap.set("n", "<leader> mp", require("nvim-tree.api").marks.navigate .prev)
1397
+ vim.keymap.set("n", "<leader> ms", require("nvim-tree.api").marks.navigate .select)
1290
1398
1291
1399
vim:tw=78:ts=4:sw=4:et:ft=help:norl:
0 commit comments