Allow mapping multiple keys to single action.

This commit is contained in:
Kristijan Husak 2020-08-03 18:51:32 +02:00 committed by Kiyan Yazdani
parent caf238d908
commit 0d8b22c1e9
4 changed files with 16 additions and 6 deletions

View File

@ -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': '<CR>',
\ 'edit': ['<CR>', 'o'],
\ 'edit_vsplit': '<C-v>',
\ 'edit_split': '<C-x>',
\ 'edit_tab': '<C-t>',

View File

@ -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: '<cr>',
\ edit: ['<cr>', 'o'], // Multiple keys provided via list
\ edit_vsplit: '<c-v>',
\ edit_split: '<c-x>',
\ edit_tab: '<c-t>',

View File

@ -45,7 +45,7 @@ end
function M.get_bindings()
local keybindings = vim.g.lua_tree_bindings or {}
return {
edit = keybindings.edit or '<CR>',
edit = keybindings.edit or {'<CR>', 'o'},
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
edit_split = keybindings.edit_split or '<C-x>',
edit_tab = keybindings.edit_tab or '<C-t>',

View File

@ -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..'<cr>', {
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..'<cr>', {
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