@@ -10,11 +10,11 @@ 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
+ 9 . Bookmarks | nvim-tree-bookmarks |
18
18
19
19
==============================================================================
20
20
1. INTRODUCTION *nvim-tree-introduction*
@@ -949,7 +949,99 @@ You'll also need to set |nvim-tree.hijack_netrw| to `true` during setup.
949
949
A good functionnality to enable is | nvim-tree.hijack_directories | .
950
950
951
951
==============================================================================
952
- 5. MAPPINGS *nvim-tree-mappings*
952
+ 5. API *nvim-tree-api*
953
+
954
+ Nvim-tree's public API can be used to access features.
955
+ >
956
+ local nt_api = require("nvim-tree.api")
957
+
958
+ nt_api.tree.toggle()
959
+ <
960
+ This module exposes stable functionalities, it is advised to use this in order
961
+ to avoid breaking configurations due to internal breaking changes.
962
+
963
+ The api is separated in multiple modules, which can be accessed with
964
+ `require (" nvim-tree.api" ).moduleName.functionality` .
965
+
966
+ Functions that needs a tree node parameter are exposed with an abstraction
967
+ that injects the node from the cursor position in the tree when calling
968
+ the function. It will use the node you pass as an argument in priority if it
969
+ exists.
970
+
971
+ - api.tree: *nvim-tree.api.tree*
972
+ - open `(path?: string)`
973
+ - close
974
+ - toggle `(find_file?: bool, no_focus?: bool, path?: string)`
975
+ - focus
976
+ - reload
977
+ - change_root `(path: string)`
978
+ - change_root_to_parent
979
+ - get_node_under_cursor
980
+ - find_file `(filename: string)`
981
+ - search_node
982
+ - collapse_all `(keep_buffers?: bool)`
983
+ - expand_all
984
+ - toggle_gitignore_filter
985
+ - toggle_custom_filter
986
+ - toggle_hidden_filter
987
+ - toggle_help
988
+
989
+ - api.fs: *nvim-tree.api.fs*
990
+ - create
991
+ - remove
992
+ - trash
993
+ - rename
994
+ - rename_sub
995
+ - copy
996
+ - cut
997
+ - paste
998
+ - print_clipboard
999
+ - copy.absolute_path
1000
+ - copy.filename
1001
+ - copy.relative_path
1002
+
1003
+ - api.node: *nvim-tree.api.node*
1004
+ - open.edit
1005
+ - open.vertical
1006
+ - open.horizontal
1007
+ - open.tab
1008
+ - open.preview
1009
+ - show_info_popup
1010
+ - run.cmd
1011
+ - run.system
1012
+ - navigate.sibling.next
1013
+ - navigate.sibling.prev
1014
+ - navigate.sibling.first
1015
+ - navigate.sibling.last
1016
+ - navigate.parent
1017
+ - navigate.parent_close
1018
+ - navigate.git.next
1019
+ - navigate.git.prev
1020
+ - navigate.diagnostics.next
1021
+ - navigate.diagnostics.prev
1022
+
1023
+ - api.git: *nvim-tree.api.git*
1024
+ - reload
1025
+
1026
+ - api.events: *nvim-tree.api.events*
1027
+ - subscribe `(eventType: Event, callback: function(...args))`
1028
+ - Event (enum type, please see | nvim_tree_events_kind | )
1029
+
1030
+ - api.live_filter: *nvim-tree.api.live_filter*
1031
+ - start
1032
+ - clear
1033
+
1034
+ - api.marks: *nvim-tree.api.marks*
1035
+ - get
1036
+ - list
1037
+ - toggle
1038
+ - bulk.move
1039
+ - navigate.next
1040
+ - navigate.prev
1041
+ - navigate.select
1042
+
1043
+ ==============================================================================
1044
+ 6. MAPPINGS *nvim-tree-mappings*
953
1045
954
1046
The `list ` option in `view .mappings.list ` is a table of
955
1047
@@ -1076,7 +1168,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings
1076
1168
} -- END_DEFAULT_MAPPINGS
1077
1169
<
1078
1170
==============================================================================
1079
- 6 . HIGHLIGHT GROUPS *nvim-tree-highlight*
1171
+ 7 . HIGHLIGHT GROUPS *nvim-tree-highlight*
1080
1172
1081
1173
All the following highlight groups can be configured by hand. Aside from
1082
1174
`NvimTreeWindowPicker` , it is not advised to colorize the background of these
@@ -1150,129 +1242,85 @@ NvimTreeBookmark
1150
1242
1151
1243
1152
1244
==============================================================================
1153
- 7 . EVENTS *nvim-tree-events*
1245
+ 8 . EVENTS *nvim-tree-events*
1154
1246
1155
1247
| nvim_tree_events |
1156
1248
1157
1249
nvim-tree will dispatch events whenever an action is made. These events can be
1158
1250
subscribed to through handler functions. This allows for even further
1159
1251
customization of nvim-tree.
1160
1252
1161
- A handler for an event is just a function which receives one argument -
1162
- the payload of the event. The payload is different for each event type. Refer
1253
+ A handler for an event is just a function which receives one argument, the
1254
+ payload of the event. The payload is different for each event type. Refer
1163
1255
to | nvim_tree_registering_handlers | for more information.
1164
- <
1165
1256
1166
1257
| nvim_tree_registering_handlers |
1167
1258
1168
- Handlers are registered by calling the `on_ * ` functions available in the
1169
- `require (' nvim-tree.events ' )` module. See | nvim-tree.events | .
1259
+ Handlers are registered by calling the `events.subscribe` function available in the
1260
+ `require (" nvim-tree.api " )` module.
1170
1261
1262
+ For example, registering a handler for when a node is renamed is done like this:
1263
+ >
1264
+ local api = require('nvim-tree.api')
1171
1265
1172
- For example, registering a handler for when a node is renamed is done like this: >
1173
-
1174
- local events = require('nvim-tree.events')
1175
-
1176
- events.on_node_renamed(function(data)
1266
+ api.events.subscribe(Event.NodeRenamed, function(data)
1177
1267
print("Node renamed from " .. data.old_name .. " to " .. data.new_name)
1178
1268
end)
1269
+ <
1179
1270
1180
- ==============================================================================
1181
- 7.1 Lua module: nvim-tree.events *nvim-tree.events*
1271
+ | nvim_tree_events_kind |
1272
+
1273
+ You can access the event enum with:
1274
+ >
1275
+ local Event = require('nvim-tree.api').events.Event
1276
+ <
1277
+ Here is the list of available variant of this enum:
1182
1278
1183
- *nvim-tree.events.on_nvim_tree_ready()*
1184
- on_nvim_tree_ready( {handler} )
1185
- Registers a handler for when NvimTree has been initialized .
1279
+ - Event.Ready
1280
+ When NvimTree has been initialized
1281
+ • Note: Handler takes no parameter .
1186
1282
1187
- Parameters: ~
1188
- {handler} `{function }` Handler function, with the
1189
- signature `function ()` .
1283
+ - Event.TreeOpen
1284
+ • Note: Handler takes no parameter.
1190
1285
1191
- *nvim-tree.events.on_node_renamed()*
1192
- on_node_renamed({handler} )
1193
- Registers a handler for when a node is renamed.
1194
- • Note: A node can either be a file or a directory.
1286
+ - Event.TreeClose
1287
+ • Note: Handler takes no parameter.
1195
1288
1196
- Parameters: ~
1197
- {handler} `{function }` Handler function, with the
1198
- signature `function (payload)` .
1199
- payload: ~
1289
+ - Event.Resize - When NvimTree is resized.
1290
+ handler parameters: ~
1291
+ size: `number ` size of the view in columns.
1292
+
1293
+ - Event.NodeRenamed
1294
+ • Note: A node can either be a file or a directory.
1295
+ handler parameters: ~
1200
1296
{old_name} `{string }` Absolute path to the old node location.
1201
1297
{new_name} `{string }` Absolute path to the new node location.
1202
1298
1203
- *nvim-tree.events.on_file_created()*
1204
- on_file_created({handler} )
1205
- Registers a handler for when a file is created.
1206
-
1207
- Parameters: ~
1208
- {handler} `{function }` Handler function, with the
1209
- signature `function (payload)` .
1210
- payload: ~
1299
+ - Event.FileCreated
1300
+ handler parameters: ~
1211
1301
{fname} `{string }` Absolute path to the created file
1212
1302
1213
- *nvim-tree.events.on_file_removed()*
1214
- on_file_removed({handler} )
1215
- Registers a handler for when a file is removed.
1216
-
1217
- Parameters: ~
1218
- {handler} `{function }` Handler function, with the
1219
- signature `function (payload)` .
1220
- payload: ~
1303
+ - Event.FileRemoved
1304
+ handler parameters: ~
1221
1305
{fname} `{string }` Absolute path to the removed file.
1222
1306
1223
- *nvim-tree.events.on_folder_created()*
1224
- on_folder_created({handler} )
1225
- Registers a handler for when a folder is created.
1226
-
1227
- Parameters: ~
1228
- {handler} `{function }` Handler function, with the
1229
- signature `function (payload)` .
1230
- payload: ~
1307
+ - Event.FolderCreated
1308
+ handler parameters: ~
1231
1309
{folder_name} `{string }` Absolute path to the created folder.
1232
1310
1233
- *nvim-tree.events.on_folder_removed()*
1234
- on_folder_removed({handler} )
1235
- Registers a handler for when a folder is removed.
1236
-
1237
- Parameters: ~
1238
- {handler} `{function }` Handler function, with the
1239
- signature `function (payload)` .
1240
- payload: ~
1311
+ - Event.FolderRemoved
1312
+ handler parameters: ~
1241
1313
{folder_name} `{string }` Absolute path to the removed folder.
1242
1314
1243
- *nvim-tree.events.on_tree_open()*
1244
- on_tree_open({handler} )
1245
- Registers a handler for when NvimTree is opened.
1246
-
1247
- Parameters: ~
1248
- {handler} `{function }` Handler function, with the
1249
- signature `function ()` .
1250
-
1251
- *nvim-tree.events.on_tree_close()*
1252
- on_tree_close({handler} )
1253
- Registers a handler for when NvimTree is closed.
1254
-
1255
- Parameters: ~
1256
- {handler} `{function }` Handler function, with the
1257
- signature `function ()` .
1258
-
1259
- *nvim-tree.events.on_tree_resize()*
1260
- on_tree_resize({handler} )
1261
- Registers a handler for when NvimTree is resized.
1262
-
1263
- Parameters: ~
1264
- {handler} `{function }` Handler function, with the
1265
- signature `function (size)` .
1266
-
1267
1315
==============================================================================
1268
- 8 . BOOKMARKS *nvim-tree-bookmarks*
1316
+ 9 . BOOKMARKS *nvim-tree-bookmarks*
1269
1317
1270
1318
You can toggle marks on files/folders with
1271
- `require (" nvim-tree.marks " ).toggle_mark (node)` which is bound to `m ` by
1319
+ `require (" nvim-tree.api " ).marks . toggle (node)` which is bound to `m ` by
1272
1320
default.
1273
1321
1274
1322
To get the list of marked paths, you can call
1275
- `require (" nvim-tree.marks " ).get_marks ()` . This will return `{node}` .
1323
+ `require (" nvim-tree.api " ).marks . list ()` . This will return `{node}` .
1276
1324
1277
1325
*nvim-tree.bookmarks.navigation*
1278
1326
@@ -1282,8 +1330,8 @@ want to focus the tree view each time we wish to switch to another mark.
1282
1330
This requires binding bookmark navigation yourself.
1283
1331
1284
1332
-- in your lua configuration
1285
- vim.keymap.set("n", "<leader> mn", require("nvim-tree.marks.navigation") .next)
1286
- vim.keymap.set("n", "<leader> mp", require("nvim-tree.marks.navigation") .prev)
1287
- vim.keymap.set("n", "<leader> ms", require("nvim-tree.marks.navigation") .select)
1333
+ vim.keymap.set("n", "<leader> mn", require("nvim-tree.api").marks.navigate .next)
1334
+ vim.keymap.set("n", "<leader> mp", require("nvim-tree.api").marks.navigate .prev)
1335
+ vim.keymap.set("n", "<leader> ms", require("nvim-tree.api").marks.navigate .select)
1288
1336
1289
1337
vim:tw=78:ts=4:sw=4:et:ft=help:norl:
0 commit comments