Allow mapping multiple keys to single action.
This commit is contained in:
parent
caf238d908
commit
0d8b22c1e9
@ -47,7 +47,7 @@ let g:lua_tree_show_icons = {
|
|||||||
" You don't have to define all keys.
|
" You don't have to define all keys.
|
||||||
" NOTE: the 'edit' key will wrap/unwrap a folder and open a file
|
" NOTE: the 'edit' key will wrap/unwrap a folder and open a file
|
||||||
let g:lua_tree_bindings = {
|
let g:lua_tree_bindings = {
|
||||||
\ 'edit': '<CR>',
|
\ 'edit': ['<CR>', 'o'],
|
||||||
\ 'edit_vsplit': '<C-v>',
|
\ 'edit_vsplit': '<C-v>',
|
||||||
\ 'edit_split': '<C-x>',
|
\ 'edit_split': '<C-x>',
|
||||||
\ 'edit_tab': '<C-t>',
|
\ 'edit_tab': '<C-t>',
|
||||||
|
|||||||
@ -192,7 +192,7 @@ you can change default keybindings by defining this variable.
|
|||||||
default keybindings will be applied to undefined keys.
|
default keybindings will be applied to undefined keys.
|
||||||
>
|
>
|
||||||
let g:lua_tree_bindings = {
|
let g:lua_tree_bindings = {
|
||||||
\ edit: '<cr>',
|
\ edit: ['<cr>', 'o'], // Multiple keys provided via list
|
||||||
\ edit_vsplit: '<c-v>',
|
\ edit_vsplit: '<c-v>',
|
||||||
\ edit_split: '<c-x>',
|
\ edit_split: '<c-x>',
|
||||||
\ edit_tab: '<c-t>',
|
\ edit_tab: '<c-t>',
|
||||||
|
|||||||
@ -45,7 +45,7 @@ end
|
|||||||
function M.get_bindings()
|
function M.get_bindings()
|
||||||
local keybindings = vim.g.lua_tree_bindings or {}
|
local keybindings = vim.g.lua_tree_bindings or {}
|
||||||
return {
|
return {
|
||||||
edit = keybindings.edit or '<CR>',
|
edit = keybindings.edit or {'<CR>', 'o'},
|
||||||
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
|
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
|
||||||
edit_split = keybindings.edit_split or '<C-x>',
|
edit_split = keybindings.edit_split or '<C-x>',
|
||||||
edit_tab = keybindings.edit_tab or '<C-t>',
|
edit_tab = keybindings.edit_tab or '<C-t>',
|
||||||
|
|||||||
@ -207,6 +207,12 @@ function M.change_dir(foldername)
|
|||||||
M.init(false, M.Tree.bufnr ~= nil)
|
M.init(false, M.Tree.bufnr ~= nil)
|
||||||
end
|
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()
|
local function set_mappings()
|
||||||
if vim.g.lua_tree_disable_keybindings == 1 then
|
if vim.g.lua_tree_disable_keybindings == 1 then
|
||||||
return
|
return
|
||||||
@ -239,9 +245,13 @@ local function set_mappings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k,v in pairs(mappings) do
|
for k,v in pairs(mappings) do
|
||||||
api.nvim_buf_set_keymap(buf, 'n', k, ':lua require"tree".'..v..'<cr>', {
|
if type(k) == 'table' then
|
||||||
nowait = true, noremap = true, silent = true
|
for _, key in pairs(k) do
|
||||||
})
|
set_mapping(buf, key, v)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
set_mapping(buf, k, v)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user