BREAKING CHANGE: make keybindings more configurable and add option to disable default
This commit is contained in:
parent
86188a4b9d
commit
10e845e01c
92
README.md
92
README.md
@ -148,54 +148,70 @@ highlight NvimTreeFolderIcon guibg=blue
|
|||||||
|
|
||||||
You can disable default mappings with
|
You can disable default mappings with
|
||||||
```vim
|
```vim
|
||||||
" let nvim_tree_disable_keybindings=1
|
" let g:nvim_tree_disable_keybindings=1
|
||||||
```
|
```
|
||||||
But you won't be able to map any keys from the setup with nvim_tree_bindings. Use with caution.
|
But you won't be able to map any keys from the setup with nvim_tree_bindings. Use with caution.
|
||||||
|
|
||||||
|
You can use only your mappings with
|
||||||
|
```vim
|
||||||
|
let g:nvim_tree_disable_default_keybindings = 1
|
||||||
|
```
|
||||||
|
|
||||||
Default keybindings can be overriden. You can also define your own keymappings for the tree view:
|
You can define your own keymaps with this syntax:
|
||||||
```vim
|
```vim
|
||||||
lua <<EOF
|
lua <<EOF
|
||||||
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
|
|
||||||
vim.g.nvim_tree_bindings = {
|
vim.g.nvim_tree_bindings = {
|
||||||
["<CR>"] = ":YourVimFunction()<cr>",
|
{ key = {"<CR>", "o" }, cb = ":lua some_func()<cr>"}
|
||||||
["u"] = ":lua require'some_module'.some_function()<cr>",
|
{ key = "<Tab>", mode = "v", cb = ":lua some_func()<cr>"}
|
||||||
|
}
|
||||||
-- default mappings
|
EOF
|
||||||
["<CR>"] = tree_cb("edit"),
|
```
|
||||||
["o"] = tree_cb("edit"),
|
Notes:
|
||||||
["<2-LeftMouse>"] = tree_cb("edit"),
|
- `key` can be either a string or a table of strings
|
||||||
["<2-RightMouse>"] = tree_cb("cd"),
|
- `mode` is `n` by default if you don't specify it
|
||||||
["<C-]>"] = tree_cb("cd"),
|
- `cb` is the command that will be called when the keymap is triggered
|
||||||
["<C-v>"] = tree_cb("vsplit"),
|
|
||||||
["<C-x>"] = tree_cb("split"),
|
If you don't use one of the options above, your keymaps will be added to the default keymaps.
|
||||||
["<C-t>"] = tree_cb("tabnew"),
|
|
||||||
["<"] = tree_cb("prev_sibling"),
|
```vim
|
||||||
[">"] = tree_cb("next_sibling"),
|
lua <<EOF
|
||||||
["<BS>"] = tree_cb("close_node"),
|
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
|
||||||
["<S-CR>"] = tree_cb("close_node"),
|
-- default mappings
|
||||||
["<Tab>"] = tree_cb("preview"),
|
vim.g.nvim_tree_bindings = {
|
||||||
["I"] = tree_cb("toggle_ignored"),
|
{ key = {"<CR>", "o", "<2-LeftMouse>"}, cb = tree_cb("edit") },
|
||||||
["H"] = tree_cb("toggle_dotfiles"),
|
{ key = {"<2-RightMouse>", "<C-}>"}, cb = tree_cb("cd") },
|
||||||
["R"] = tree_cb("refresh"),
|
{ key = "<C-v>", cb = tree_cb("vsplit") },
|
||||||
["a"] = tree_cb("create"),
|
{ key = "<C-x>", cb = tree_cb("split") },
|
||||||
["d"] = tree_cb("remove"),
|
{ key = "<C-t>", cb = tree_cb("tabnew") },
|
||||||
["r"] = tree_cb("rename"),
|
{ key = "<", cb = tree_cb("prev_sibling") },
|
||||||
["<C-r>"] = tree_cb("full_rename"),
|
{ key = ">", cb = tree_cb("next_sibling") },
|
||||||
["x"] = tree_cb("cut"),
|
{ key = "P", cb = tree_cb("parent_node") },
|
||||||
["c"] = tree_cb("copy"),
|
{ key = "<BS>", cb = tree_cb("close_node") },
|
||||||
["p"] = tree_cb("paste"),
|
{ key = "<S-CR>", cb = tree_cb("close_node") },
|
||||||
["y"] = tree_cb("copy_name"),
|
{ key = "<Tab>", cb = tree_cb("preview") },
|
||||||
["Y"] = tree_cb("copy_path"),
|
{ key = "K", cb = tree_cb("first_sibling") },
|
||||||
["gy"] = tree_cb("copy_absolute_path"),
|
{ key = "J", cb = tree_cb("last_sibling") },
|
||||||
["[c"] = tree_cb("prev_git_item"),
|
{ key = "I", cb = tree_cb("toggle_ignored") },
|
||||||
["]c"] = tree_cb("next_git_item"),
|
{ key = "H", cb = tree_cb("toggle_dotfiles") },
|
||||||
["-"] = tree_cb("dir_up"),
|
{ key = "R", cb = tree_cb("refresh") },
|
||||||
["q"] = tree_cb("close"),
|
{ key = "a", cb = tree_cb("create") },
|
||||||
|
{ key = "d", cb = tree_cb("remove") },
|
||||||
|
{ key = "r", cb = tree_cb("rename") },
|
||||||
|
{ key = "<C->", cb = tree_cb("full_rename") },
|
||||||
|
{ key = "x", cb = tree_cb("cut") },
|
||||||
|
{ key = "c", cb = tree_cb("copy") },
|
||||||
|
{ key = "p", cb = tree_cb("paste") },
|
||||||
|
{ key = "y", cb = tree_cb("copy_name") },
|
||||||
|
{ key = "Y", cb = tree_cb("copy_path") },
|
||||||
|
{ key = "gy", cb = tree_cb("copy_absolute_path") },
|
||||||
|
{ key = "[c", cb = tree_cb("prev_git_item") },
|
||||||
|
{ key = "}c", cb = tree_cb("next_git_item") },
|
||||||
|
{ key = "-", cb = tree_cb("dir_up") },
|
||||||
|
{ key = "q", cb = tree_cb("close") },
|
||||||
|
{ key = "g?", cb = tree_cb("toggle_help") },
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
All mappings are set in `normal mode`.
|
|
||||||
You can toggle the help UI by pressing `g?`.
|
You can toggle the help UI by pressing `g?`.
|
||||||
|
|
||||||
## Note
|
## Note
|
||||||
|
|||||||
@ -192,6 +192,11 @@ Can be `0` or `1`. When `1`, will disable all keybindings by the plugin.
|
|||||||
|g:nvim_tree_bindings| as well as default bindings will not take effect.
|
|g:nvim_tree_bindings| as well as default bindings will not take effect.
|
||||||
Default is 0
|
Default is 0
|
||||||
|
|
||||||
|
|g:nvim_tree_disable_default_keybindings| *g:nvim_tree_disable_default_keybindings*
|
||||||
|
|
||||||
|
Can be `0` or `1`. When `1`, will disable default keybindings and use only the one you defined.
|
||||||
|
Default is 0
|
||||||
|
|
||||||
|g:nvim_tree_indent_markers| *g:nvim_tree_indent_markers*
|
|g:nvim_tree_indent_markers| *g:nvim_tree_indent_markers*
|
||||||
|
|
||||||
Can be `0` or `1`. When `1`, will display indent markers when folders are open
|
Can be `0` or `1`. When `1`, will display indent markers when folders are open
|
||||||
@ -346,57 +351,58 @@ INFORMATIONS *nvim-tree-info*
|
|||||||
|
|
||||||
|g:nvim_tree_bindings| *g:nvim_tree_bindings*
|
|g:nvim_tree_bindings| *g:nvim_tree_bindings*
|
||||||
|
|
||||||
You can disable default mappings with
|
You can define your own keymaps with this syntax:
|
||||||
>
|
>
|
||||||
let nvim_tree_disable_keybindings=1
|
lua <<EOF
|
||||||
|
vim.g.nvim_tree_bindings = {
|
||||||
|
{ key = {"<CR>", "o" }, cb = ":lua some_func()<cr>"}
|
||||||
|
{ key = "<Tab>", mode = "v", cb = ":lua some_func()<cr>"}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
<
|
<
|
||||||
But you won't be able to map any keys from the setup with nvim_tree_bindings. Use with caution.
|
`key` can be either a string or a table of strings
|
||||||
|
`mode` is `n` by default if you don't specify it
|
||||||
|
`cb` is the command that will be called when the keymap is triggered
|
||||||
|
|
||||||
Default keybindings can be overriden. You can also define your own keymappings for the tree view:
|
Default mappings:
|
||||||
>
|
>
|
||||||
lua <<EOF
|
lua <<EOF
|
||||||
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
|
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
|
||||||
vim.g.nvim_tree_bindings = {
|
vim.g.nvim_tree_bindings = {
|
||||||
["<CR>"] = ":YourVimFunction()<cr>",
|
{ key = {"<CR>", "o", "<2-LeftMouse>"}, cb = tree_cb("edit") },
|
||||||
["u"] = ":lua require'some_module'.some_function()<cr>",
|
{ key = {"<2-RightMouse>", "<C-}>"}, cb = tree_cb("cd") },
|
||||||
|
{ key = "<C-v>", cb = tree_cb("vsplit") },
|
||||||
-- default mappings
|
{ key = "<C-x>", cb = tree_cb("split") },
|
||||||
["<CR>"] = tree_cb("edit"),
|
{ key = "<C-t>", cb = tree_cb("tabnew") },
|
||||||
["o"] = tree_cb("edit"),
|
{ key = "<", cb = tree_cb("prev_sibling") },
|
||||||
["<2-LeftMouse>"] = tree_cb("edit"),
|
{ key = ">", cb = tree_cb("next_sibling") },
|
||||||
["<2-RightMouse>"] = tree_cb("cd"),
|
{ key = "P", cb = tree_cb("parent_node") },
|
||||||
["<C-]>"] = tree_cb("cd"),
|
{ key = "<BS>", cb = tree_cb("close_node") },
|
||||||
["<C-v>"] = tree_cb("vsplit"),
|
{ key = "<S-CR>", cb = tree_cb("close_node") },
|
||||||
["<C-x>"] = tree_cb("split"),
|
{ key = "<Tab>", cb = tree_cb("preview") },
|
||||||
["<C-t>"] = tree_cb("tabnew"),
|
{ key = "K", cb = tree_cb("first_sibling") },
|
||||||
["<"] = tree_cb("prev_sibling"),
|
{ key = "J", cb = tree_cb("last_sibling") },
|
||||||
[">"] = tree_cb("next_sibling"),
|
{ key = "I", cb = tree_cb("toggle_ignored") },
|
||||||
["P"] = tree_cb("parent_node"),
|
{ key = "H", cb = tree_cb("toggle_dotfiles") },
|
||||||
["<BS>"] = tree_cb("close_node"),
|
{ key = "R", cb = tree_cb("refresh") },
|
||||||
["<S-CR>"] = tree_cb("close_node"),
|
{ key = "a", cb = tree_cb("create") },
|
||||||
["<Tab>"] = tree_cb("preview"),
|
{ key = "d", cb = tree_cb("remove") },
|
||||||
["K"] = tree_cb("first_sibling"),
|
{ key = "r", cb = tree_cb("rename") },
|
||||||
["J"] = tree_cb("last_sibling"),
|
{ key = "<C->", cb = tree_cb("full_rename") },
|
||||||
["I"] = tree_cb("toggle_ignored"),
|
{ key = "x", cb = tree_cb("cut") },
|
||||||
["H"] = tree_cb("toggle_dotfiles"),
|
{ key = "c", cb = tree_cb("copy") },
|
||||||
["R"] = tree_cb("refresh"),
|
{ key = "p", cb = tree_cb("paste") },
|
||||||
["a"] = tree_cb("create"),
|
{ key = "y", cb = tree_cb("copy_name") },
|
||||||
["d"] = tree_cb("remove"),
|
{ key = "Y", cb = tree_cb("copy_path") },
|
||||||
["r"] = tree_cb("rename"),
|
{ key = "gy", cb = tree_cb("copy_absolute_path") },
|
||||||
["<C-r>"] = tree_cb("full_rename"),
|
{ key = "[c", cb = tree_cb("prev_git_item") },
|
||||||
["x"] = tree_cb("cut"),
|
{ key = "}c", cb = tree_cb("next_git_item") },
|
||||||
["c"] = tree_cb("copy"),
|
{ key = "-", cb = tree_cb("dir_up") },
|
||||||
["p"] = tree_cb("paste"),
|
{ key = "q", cb = tree_cb("close") },
|
||||||
["[c"] = tree_cb("prev_git_item"),
|
{ key = "g?", cb = tree_cb("toggle_help") },
|
||||||
["]c"] = tree_cb("next_git_item"),
|
}
|
||||||
["-"] = tree_cb("dir_up"),
|
EOF
|
||||||
["q"] = tree_cb("close"),
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
<
|
<
|
||||||
|
|
||||||
All mappings are set in `normal mode`.
|
|
||||||
|
|
||||||
|Features| *nvim-tree-features*
|
|Features| *nvim-tree-features*
|
||||||
|
|
||||||
File icons with vim-devicons.
|
File icons with vim-devicons.
|
||||||
|
|||||||
@ -42,40 +42,37 @@ M.View = {
|
|||||||
bufhidden = 'hide';
|
bufhidden = 'hide';
|
||||||
},
|
},
|
||||||
bindings = {
|
bindings = {
|
||||||
["<CR>"] = M.nvim_tree_callback("edit"),
|
{ key = {"<CR>", "o", "<2-LeftMouse>"}, cb = M.nvim_tree_callback("edit") },
|
||||||
["o"] = M.nvim_tree_callback("edit"),
|
{ key = {"<2-RightMouse>", "<C-}>"}, cb = M.nvim_tree_callback("cd") },
|
||||||
["<2-LeftMouse>"] = M.nvim_tree_callback("edit"),
|
{ key = "<C-v>", cb = M.nvim_tree_callback("vsplit") },
|
||||||
["<2-RightMouse>"] = M.nvim_tree_callback("cd"),
|
{ key = "<C-x>", cb = M.nvim_tree_callback("split") },
|
||||||
["<C-]>"] = M.nvim_tree_callback("cd"),
|
{ key = "<C-t>", cb = M.nvim_tree_callback("tabnew") },
|
||||||
["<C-v>"] = M.nvim_tree_callback("vsplit"),
|
{ key = "<", cb = M.nvim_tree_callback("prev_sibling") },
|
||||||
["<C-x>"] = M.nvim_tree_callback("split"),
|
{ key = ">", cb = M.nvim_tree_callback("next_sibling") },
|
||||||
["<C-t>"] = M.nvim_tree_callback("tabnew"),
|
{ key = "P", cb = M.nvim_tree_callback("parent_node") },
|
||||||
["<"] = M.nvim_tree_callback("prev_sibling"),
|
{ key = "<BS>", cb = M.nvim_tree_callback("close_node") },
|
||||||
[">"] = M.nvim_tree_callback("next_sibling"),
|
{ key = "<S-CR>", cb = M.nvim_tree_callback("close_node") },
|
||||||
["P"] = M.nvim_tree_callback("parent_node"),
|
{ key = "<Tab>", cb = M.nvim_tree_callback("preview") },
|
||||||
["<BS>"] = M.nvim_tree_callback("close_node"),
|
{ key = "K", cb = M.nvim_tree_callback("first_sibling") },
|
||||||
["<S-CR>"] = M.nvim_tree_callback("close_node"),
|
{ key = "J", cb = M.nvim_tree_callback("last_sibling") },
|
||||||
["<Tab>"] = M.nvim_tree_callback("preview"),
|
{ key = "I", cb = M.nvim_tree_callback("toggle_ignored") },
|
||||||
["K"] = M.nvim_tree_callback("first_sibling"),
|
{ key = "H", cb = M.nvim_tree_callback("toggle_dotfiles") },
|
||||||
["J"] = M.nvim_tree_callback("last_sibling"),
|
{ key = "R", cb = M.nvim_tree_callback("refresh") },
|
||||||
["I"] = M.nvim_tree_callback("toggle_ignored"),
|
{ key = "a", cb = M.nvim_tree_callback("create") },
|
||||||
["H"] = M.nvim_tree_callback("toggle_dotfiles"),
|
{ key = "d", cb = M.nvim_tree_callback("remove") },
|
||||||
["R"] = M.nvim_tree_callback("refresh"),
|
{ key = "r", cb = M.nvim_tree_callback("rename") },
|
||||||
["a"] = M.nvim_tree_callback("create"),
|
{ key = "<C->", cb = M.nvim_tree_callback("full_rename") },
|
||||||
["d"] = M.nvim_tree_callback("remove"),
|
{ key = "x", cb = M.nvim_tree_callback("cut") },
|
||||||
["r"] = M.nvim_tree_callback("rename"),
|
{ key = "c", cb = M.nvim_tree_callback("copy") },
|
||||||
["<C-r>"] = M.nvim_tree_callback("full_rename"),
|
{ key = "p", cb = M.nvim_tree_callback("paste") },
|
||||||
["x"] = M.nvim_tree_callback("cut"),
|
{ key = "y", cb = M.nvim_tree_callback("copy_name") },
|
||||||
["c"] = M.nvim_tree_callback("copy"),
|
{ key = "Y", cb = M.nvim_tree_callback("copy_path") },
|
||||||
["p"] = M.nvim_tree_callback("paste"),
|
{ key = "gy", cb = M.nvim_tree_callback("copy_absolute_path") },
|
||||||
["y"] = M.nvim_tree_callback("copy_name"),
|
{ key = "[c", cb = M.nvim_tree_callback("prev_git_item") },
|
||||||
["Y"] = M.nvim_tree_callback("copy_path"),
|
{ key = "}c", cb = M.nvim_tree_callback("next_git_item") },
|
||||||
["gy"] = M.nvim_tree_callback("copy_absolute_path"),
|
{ key = "-", cb = M.nvim_tree_callback("dir_up") },
|
||||||
["[c"] = M.nvim_tree_callback("prev_git_item"),
|
{ key = "q", cb = M.nvim_tree_callback("close") },
|
||||||
["]c"] = M.nvim_tree_callback("next_git_item"),
|
{ key = "g?", cb = M.nvim_tree_callback("toggle_help") }
|
||||||
["-"] = M.nvim_tree_callback("dir_up"),
|
|
||||||
["q"] = M.nvim_tree_callback("close"),
|
|
||||||
["g?"] = M.nvim_tree_callback("toggle_help")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,18 +128,33 @@ function M.setup()
|
|||||||
vim.bo[M.View.bufnr][k] = v
|
vim.bo[M.View.bufnr][k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.g.nvim_tree_disable_keybindings ~= 1 then
|
vim.cmd "au! BufWinEnter * lua require'nvim-tree.view'._prevent_buffer_override()"
|
||||||
M.View.bindings = vim.tbl_extend(
|
if vim.g.nvim_tree_disable_keybindings == 1 then
|
||||||
'force',
|
return
|
||||||
M.View.bindings,
|
|
||||||
vim.g.nvim_tree_bindings or {}
|
|
||||||
)
|
|
||||||
for key, cb in pairs(M.View.bindings) do
|
|
||||||
a.nvim_buf_set_keymap(M.View.bufnr, 'n', key, cb, { noremap = true, silent = true, nowait = true })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.cmd "au! BufWinEnter * lua require'nvim-tree.view'._prevent_buffer_override()"
|
local user_mappings = vim.g.nvim_tree_bindings or {}
|
||||||
|
if vim.g.nvim_tree_disable_default_keybindings == 1 then
|
||||||
|
M.View.bindings = user_mappings
|
||||||
|
else
|
||||||
|
M.View.bindings = vim.tbl_extend('force', M.View.bindings, user_mappings)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, b in pairs(M.View.bindings) do
|
||||||
|
-- TODO: remove this in a few weeks
|
||||||
|
if type(b) == "string" then
|
||||||
|
local warn_str = "Wrong configuration for keymaps, refer to the new documentation. User keymaps setup aborted"
|
||||||
|
require'nvim-tree.utils'.echo_warning(warn_str)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if type(b.key) == "table" then
|
||||||
|
for _, key in pairs(b.key) do
|
||||||
|
a.nvim_buf_set_keymap(M.View.bufnr, b.mode or 'n', key, b.cb, { noremap = true, silent = true, nowait = true })
|
||||||
|
end
|
||||||
|
else
|
||||||
|
a.nvim_buf_set_keymap(M.View.bufnr, b.mode or 'n', b.key, b.cb, { noremap = true, silent = true, nowait = true })
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local goto_tbl = {
|
local goto_tbl = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user