@@ -10,11 +10,12 @@ CONTENTS *nvim-tree*
1010 3. Commands | nvim-tree-commands |
1111 4. Setup/Configuration | nvim-tree-setup |
1212 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 |
1819
1920==============================================================================
2021 1. INTRODUCTION *nvim-tree-introduction*
@@ -951,7 +952,97 @@ You'll also need to set |nvim-tree.hijack_netrw| to `true` during setup.
951952A good functionnality to enable is | nvim-tree.hijack_directories | .
952953
953954==============================================================================
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 (its an 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*
9551046
9561047The `list ` option in `view .mappings.list ` is a table of
9571048
@@ -1078,7 +1169,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings
10781169 } -- END_DEFAULT_MAPPINGS
10791170<
10801171==============================================================================
1081- 6 . HIGHLIGHT GROUPS *nvim-tree-highlight*
1172+ 7 . HIGHLIGHT GROUPS *nvim-tree-highlight*
10821173
10831174All the following highlight groups can be configured by hand. Aside from
10841175`NvimTreeWindowPicker` , it is not advised to colorize the background of these
@@ -1152,35 +1243,52 @@ NvimTreeBookmark
11521243
11531244
11541245==============================================================================
1155- 7 . EVENTS *nvim-tree-events*
1246+ 8 . EVENTS *nvim-tree-events*
11561247
11571248| nvim_tree_events |
11581249
11591250nvim-tree will dispatch events whenever an action is made. These events can be
11601251subscribed to through handler functions. This allows for even further
11611252customization of nvim-tree.
11621253
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
11651256to | nvim_tree_registering_handlers | for more information.
1166- <
11671257
11681258| nvim_tree_registering_handlers |
11691259
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.
11731262
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 ')
11771266
1178- events.on_node_renamed( function(data)
1267+ api. events.subscribe(Event.NodeRenamed, function(data)
11791268 print("Node renamed from " .. data.old_name .. " to " .. data.new_name)
11801269 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
11811289
11821290==============================================================================
1183- 7 .1 Lua module: nvim-tree.events *nvim-tree.events*
1291+ 8 .1 Lua module: nvim-tree.events *nvim-tree.events*
11841292
11851293 *nvim-tree.events.on_nvim_tree_ready()*
11861294on_nvim_tree_ready({handler} )
@@ -1267,14 +1375,14 @@ on_tree_resize({handler})
12671375 signature `function (size)` .
12681376
12691377==============================================================================
1270- 8 . BOOKMARKS *nvim-tree-bookmarks*
1378+ 9 . BOOKMARKS *nvim-tree-bookmarks*
12711379
12721380You 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
12741382default.
12751383
12761384To 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}` .
12781386
12791387*nvim-tree.bookmarks.navigation*
12801388
@@ -1284,8 +1392,8 @@ want to focus the tree view each time we wish to switch to another mark.
12841392This requires binding bookmark navigation yourself.
12851393
12861394-- 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)
12901398
12911399 vim:tw=78:ts=4:sw=4:et:ft=help:norl:
0 commit comments