File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -1494,6 +1494,23 @@ api.config.mappings.default() *nvim-tree.api.config.mappings.default()*
1494
1494
Return: ~
1495
1495
(table) as per | nvim-tree.view.mappings.list |
1496
1496
1497
+ *nvim-tree.api.config.mappings.get_keymap()*
1498
+ api.config.mappings.get_keymap()
1499
+ Retrieves all buffer local mappings for nvim-tree.
1500
+ These are the mappings that are applied by | nvim-tree.on_attach | , which
1501
+ may include default mappings.
1502
+
1503
+ Return: ~
1504
+ (table) as per | nvim_buf_get_keymap() |
1505
+
1506
+ *nvim-tree.api.config.mappings.get_keymap()*
1507
+ api.config.mappings.get_keymap_default()
1508
+ Retrieves the buffer local mappings for nvim-tree that are applied by
1509
+ | nvim-tree.api.config.mappings.default_on_attach() |
1510
+
1511
+ Return: ~
1512
+ (table) as per | nvim_buf_get_keymap() |
1513
+
1497
1514
==============================================================================
1498
1515
6. MAPPINGS *nvim-tree-mappings*
1499
1516
Original file line number Diff line number Diff line change @@ -182,4 +182,11 @@ Api.config.mappings.default = function()
182
182
return require (" nvim-tree.keymap-legacy" ).default_mappings_clone ()
183
183
end
184
184
185
+ Api .config .mappings .get_keymap = function ()
186
+ return require (" nvim-tree.keymap" ).get_keymap ()
187
+ end
188
+ Api .config .mappings .get_keymap_default = function ()
189
+ return require (" nvim-tree.keymap" ).get_keymap_default ()
190
+ end
191
+
185
192
return Api
Original file line number Diff line number Diff line change 1
1
local M = {}
2
2
3
+ --- Apply mappings to a scratch buffer and return buffer local mappings
4
+ --- @param fn function (bufnr ) on_attach or default_on_attach
5
+ --- @return table as per vim.api.nvim_buf_get_keymap
6
+ local function generate_keymap (fn )
7
+ -- create an unlisted scratch buffer
8
+ local scratch_bufnr = vim .api .nvim_create_buf (false , true )
9
+
10
+ -- apply mappings
11
+ fn (scratch_bufnr )
12
+
13
+ -- retrieve all
14
+ local keymap = vim .api .nvim_buf_get_keymap (scratch_bufnr , " " )
15
+
16
+ -- delete the scratch buffer
17
+ vim .api .nvim_buf_delete (scratch_bufnr , { force = true })
18
+
19
+ return keymap
20
+ end
21
+
3
22
-- stylua: ignore start
4
23
function M .default_on_attach (bufnr )
5
24
local api = require (' nvim-tree.api' )
@@ -65,6 +84,14 @@ function M.default_on_attach(bufnr)
65
84
end
66
85
-- stylua: ignore end
67
86
87
+ function M .get_keymap ()
88
+ return generate_keymap (M .on_attach )
89
+ end
90
+
91
+ function M .get_keymap_default ()
92
+ return generate_keymap (M .default_on_attach )
93
+ end
94
+
68
95
function M .setup (opts )
69
96
if type (opts .on_attach ) ~= " function" then
70
97
M .on_attach = M .default_on_attach
You can’t perform that action at this time.
0 commit comments