From 0d8b22c1e9b89ec05670794bbf19e8a2acc322e2 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Mon, 3 Aug 2020 18:51:32 +0200 Subject: [PATCH] Allow mapping multiple keys to single action. --- README.md | 2 +- doc/nvim-tree-lua.txt | 2 +- lua/lib/config.lua | 2 +- lua/lib/lib.lua | 16 +++++++++++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d1695f9c..bfe984fa 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ let g:lua_tree_show_icons = { " You don't have to define all keys. " NOTE: the 'edit' key will wrap/unwrap a folder and open a file let g:lua_tree_bindings = { - \ 'edit': '', + \ 'edit': ['', 'o'], \ 'edit_vsplit': '', \ 'edit_split': '', \ 'edit_tab': '', diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 56c0f561..dacb5942 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -192,7 +192,7 @@ you can change default keybindings by defining this variable. default keybindings will be applied to undefined keys. > let g:lua_tree_bindings = { - \ edit: '', + \ edit: ['', 'o'], // Multiple keys provided via list \ edit_vsplit: '', \ edit_split: '', \ edit_tab: '', diff --git a/lua/lib/config.lua b/lua/lib/config.lua index 6fd6a2d2..ebc1d945 100644 --- a/lua/lib/config.lua +++ b/lua/lib/config.lua @@ -45,7 +45,7 @@ end function M.get_bindings() local keybindings = vim.g.lua_tree_bindings or {} return { - edit = keybindings.edit or '', + edit = keybindings.edit or {'', 'o'}, edit_vsplit = keybindings.edit_vsplit or '', edit_split = keybindings.edit_split or '', edit_tab = keybindings.edit_tab or '', diff --git a/lua/lib/lib.lua b/lua/lib/lib.lua index 5aa5b192..eafd0afb 100644 --- a/lua/lib/lib.lua +++ b/lua/lib/lib.lua @@ -207,6 +207,12 @@ function M.change_dir(foldername) M.init(false, M.Tree.bufnr ~= nil) end +local function set_mapping(buf, key, fn) + api.nvim_buf_set_keymap(buf, 'n', key, ':lua require"tree".'..fn..'', { + nowait = true, noremap = true, silent = true + }) +end + local function set_mappings() if vim.g.lua_tree_disable_keybindings == 1 then return @@ -239,9 +245,13 @@ local function set_mappings() } for k,v in pairs(mappings) do - api.nvim_buf_set_keymap(buf, 'n', k, ':lua require"tree".'..v..'', { - nowait = true, noremap = true, silent = true - }) + if type(k) == 'table' then + for _, key in pairs(k) do + set_mapping(buf, key, v) + end + else + set_mapping(buf, k, v) + end end end