chore: update documentation for tree mappings
This commit is contained in:
parent
1984c12510
commit
58e44d29d7
30
README.md
30
README.md
@ -118,14 +118,40 @@ But you won't be able to map any keys from the setup with nvim_tree_bindings. Us
|
||||
Default keybindings can be overriden. You can also define your own keymappings for the tree view:
|
||||
```vim
|
||||
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"),
|
||||
["<BS>"] = tree_cb("close_node"),
|
||||
["<S-CR>"] = tree_cb("close_node"),
|
||||
["<Tab>"] = tree_cb("preview"),
|
||||
["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
|
||||
```
|
||||
You can check the default binding table in `nvim-tree/config.lua`, under the `get_bindings` function.
|
||||
This basically maps the default keys to the `on_keypress` function with different string parameters.
|
||||
All mappings are set in `normal mode`.
|
||||
|
||||
## Note
|
||||
|
||||
@ -236,18 +236,51 @@ INFORMATIONS *nvim-tree-info*
|
||||
|
||||
|g:nvim_tree_bindings| *g:nvim_tree_bindings*
|
||||
|
||||
You can disable default mappings with
|
||||
>
|
||||
let 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.
|
||||
|
||||
Default keybindings can be overriden. You can also define your own keymappings for the tree view:
|
||||
>
|
||||
lua <<EOF
|
||||
vim.g.nvim_tree_bindings = {
|
||||
["<CR>"] = ":YourVimFunction()<cr>",
|
||||
["u"] = ":lua require'some_module'.some_function()<cr>",
|
||||
}
|
||||
EOF
|
||||
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>",
|
||||
|
||||
You can check the default binding table in `nvim-tree/config.lua`, under the `get_bindings` function.
|
||||
This basically maps the default keys to the `on_keypress` function with different string parameters.
|
||||
All mappings are set in `normal` `mode`.
|
||||
-- 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"),
|
||||
["<BS>"] = tree_cb("close_node"),
|
||||
["<S-CR>"] = tree_cb("close_node"),
|
||||
["<Tab>"] = tree_cb("preview"),
|
||||
["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
|
||||
<
|
||||
|
||||
All mappings are set in `normal mode`.
|
||||
|
||||
|Features| *nvim-tree-features*
|
||||
|
||||
|
||||
@ -51,38 +51,38 @@ function M.get_icon_state()
|
||||
}
|
||||
end
|
||||
|
||||
local function get_lua_cb(cb_name)
|
||||
return string.format(":lua require'nvim-tree'.on_keypress('%s')<CR>", cb_name)
|
||||
function M.nvim_tree_callback(callback_name)
|
||||
return string.format(":lua require'nvim-tree'.on_keypress('%s')<CR>", callback_name)
|
||||
end
|
||||
|
||||
function M.get_bindings()
|
||||
local keybindings = vim.g.nvim_tree_bindings or {}
|
||||
return vim.tbl_extend('force', {
|
||||
["<CR>"] = get_lua_cb("edit"),
|
||||
["o"] = get_lua_cb("edit"),
|
||||
["<2-LeftMouse>"] = get_lua_cb("edit"),
|
||||
["<2-RightMouse>"] = get_lua_cb("cd"),
|
||||
["<C-]>"] = get_lua_cb("cd"),
|
||||
["<C-v>"] = get_lua_cb("vsplit"),
|
||||
["<C-x>"] = get_lua_cb("split"),
|
||||
["<C-t>"] = get_lua_cb("tabnew"),
|
||||
["<BS>"] = get_lua_cb("close_node"),
|
||||
["<S-CR>"] = get_lua_cb("close_node"),
|
||||
["<Tab>"] = get_lua_cb("preview"),
|
||||
["I"] = get_lua_cb("toggle_ignored"),
|
||||
["H"] = get_lua_cb("toggle_dotfiles"),
|
||||
["R"] = get_lua_cb("refresh"),
|
||||
["a"] = get_lua_cb("create"),
|
||||
["d"] = get_lua_cb("remove"),
|
||||
["r"] = get_lua_cb("rename"),
|
||||
["<C-r>"] = get_lua_cb("full_rename"),
|
||||
["x"] = get_lua_cb("cut"),
|
||||
["c"] = get_lua_cb("copy"),
|
||||
["p"] = get_lua_cb("paste"),
|
||||
["[c"] = get_lua_cb("prev_git_item"),
|
||||
["]c"] = get_lua_cb("next_git_item"),
|
||||
["-"] = get_lua_cb("dir_up"),
|
||||
["q"] = get_lua_cb("close"),
|
||||
["<CR>"] = M.nvim_tree_callback("edit"),
|
||||
["o"] = M.nvim_tree_callback("edit"),
|
||||
["<2-LeftMouse>"] = M.nvim_tree_callback("edit"),
|
||||
["<2-RightMouse>"] = M.nvim_tree_callback("cd"),
|
||||
["<C-]>"] = M.nvim_tree_callback("cd"),
|
||||
["<C-v>"] = M.nvim_tree_callback("vsplit"),
|
||||
["<C-x>"] = M.nvim_tree_callback("split"),
|
||||
["<C-t>"] = M.nvim_tree_callback("tabnew"),
|
||||
["<BS>"] = M.nvim_tree_callback("close_node"),
|
||||
["<S-CR>"] = M.nvim_tree_callback("close_node"),
|
||||
["<Tab>"] = M.nvim_tree_callback("preview"),
|
||||
["I"] = M.nvim_tree_callback("toggle_ignored"),
|
||||
["H"] = M.nvim_tree_callback("toggle_dotfiles"),
|
||||
["R"] = M.nvim_tree_callback("refresh"),
|
||||
["a"] = M.nvim_tree_callback("create"),
|
||||
["d"] = M.nvim_tree_callback("remove"),
|
||||
["r"] = M.nvim_tree_callback("rename"),
|
||||
["<C-r>"] = M.nvim_tree_callback("full_rename"),
|
||||
["x"] = M.nvim_tree_callback("cut"),
|
||||
["c"] = M.nvim_tree_callback("copy"),
|
||||
["p"] = M.nvim_tree_callback("paste"),
|
||||
["[c"] = M.nvim_tree_callback("prev_git_item"),
|
||||
["]c"] = M.nvim_tree_callback("next_git_item"),
|
||||
["-"] = M.nvim_tree_callback("dir_up"),
|
||||
["q"] = M.nvim_tree_callback("close"),
|
||||
}, keybindings)
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user