BREAKING CHANGE: make keybindings more configurable and add option to disable default

This commit is contained in:
kiyan
2021-06-30 21:54:17 +02:00
parent 86188a4b9d
commit 10e845e01c
3 changed files with 162 additions and 128 deletions

View File

@@ -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.
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*
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*
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
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
vim.g.nvim_tree_bindings = {
["<CR>"] = ":YourVimFunction()<cr>",
["u"] = ":lua require'some_module'.some_function()<cr>",
-- default mappings
["<CR>"] = tree_cb("edit"),
["o"] = tree_cb("edit"),
["<2-LeftMouse>"] = tree_cb("edit"),
["<2-RightMouse>"] = tree_cb("cd"),
["<C-]>"] = tree_cb("cd"),
["<C-v>"] = tree_cb("vsplit"),
["<C-x>"] = tree_cb("split"),
["<C-t>"] = tree_cb("tabnew"),
["<"] = tree_cb("prev_sibling"),
[">"] = tree_cb("next_sibling"),
["P"] = tree_cb("parent_node"),
["<BS>"] = tree_cb("close_node"),
["<S-CR>"] = tree_cb("close_node"),
["<Tab>"] = tree_cb("preview"),
["K"] = tree_cb("first_sibling"),
["J"] = tree_cb("last_sibling"),
["I"] = tree_cb("toggle_ignored"),
["H"] = tree_cb("toggle_dotfiles"),
["R"] = tree_cb("refresh"),
["a"] = tree_cb("create"),
["d"] = tree_cb("remove"),
["r"] = tree_cb("rename"),
["<C-r>"] = tree_cb("full_rename"),
["x"] = tree_cb("cut"),
["c"] = tree_cb("copy"),
["p"] = tree_cb("paste"),
["[c"] = tree_cb("prev_git_item"),
["]c"] = tree_cb("next_git_item"),
["-"] = tree_cb("dir_up"),
["q"] = tree_cb("close"),
}
EOF
lua <<EOF
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
vim.g.nvim_tree_bindings = {
{ key = {"<CR>", "o", "<2-LeftMouse>"}, cb = tree_cb("edit") },
{ key = {"<2-RightMouse>", "<C-}>"}, cb = tree_cb("cd") },
{ key = "<C-v>", cb = tree_cb("vsplit") },
{ key = "<C-x>", cb = tree_cb("split") },
{ key = "<C-t>", cb = tree_cb("tabnew") },
{ key = "<", cb = tree_cb("prev_sibling") },
{ key = ">", cb = tree_cb("next_sibling") },
{ key = "P", cb = tree_cb("parent_node") },
{ key = "<BS>", cb = tree_cb("close_node") },
{ key = "<S-CR>", cb = tree_cb("close_node") },
{ key = "<Tab>", cb = tree_cb("preview") },
{ key = "K", cb = tree_cb("first_sibling") },
{ key = "J", cb = tree_cb("last_sibling") },
{ key = "I", cb = tree_cb("toggle_ignored") },
{ key = "H", cb = tree_cb("toggle_dotfiles") },
{ key = "R", cb = tree_cb("refresh") },
{ 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
<
All mappings are set in `normal mode`.
|Features| *nvim-tree-features*
File icons with vim-devicons.