neovim: update nvim-tree mappings config

This commit is contained in:
2023-04-19 09:57:45 +03:00
parent 641020561b
commit 214def19dc

View File

@@ -1,37 +1,38 @@
local Job = require("plenary.job")
local function on_attach(bufnr)
local api = require("nvim-tree.api")
local function git_stage(node)
local cwd = vim.loop.cwd()
local relative_path = string.gsub(node.absolute_path, cwd .. "/", "")
Job:new({
command = "git",
args = { "add", relative_path },
}):start()
local function opts(desc)
return {
desc = "nvim-tree: " .. desc,
buffer = bufnr,
noremap = true,
silent = true,
nowait = true,
}
end
local function git_unstage(node)
local cwd = vim.loop.cwd()
local relative_path = string.gsub(node.absolute_path, cwd .. "/", "")
Job:new({
command = "git",
args = { "reset", relative_path },
}):start()
vim.keymap.set("n", "tn", api.node.open.tab, opts("tabnew"))
vim.keymap.set("n", "l", api.node.open.edit, opts("edit"))
vim.keymap.set("n", "<CR>", api.node.open.edit, opts("edit ENTER"))
vim.keymap.set("n", "@", api.tree.change_root_to_node, opts("change root"))
vim.keymap.set("n", "<C-v>", api.node.open.vertical, opts("vertical split"))
vim.keymap.set("n", "<C-h>", api.node.open.horizontal, opts("horizontal split"))
vim.keymap.set("n", "a", api.fs.create, opts("create file"))
vim.keymap.set("n", "d", api.fs.remove, opts("remove file"))
vim.keymap.set("n", "r", api.fs.rename, opts("rename file"))
vim.keymap.set("n", "R", api.tree.reload, opts("reload"))
vim.keymap.set("n", "x", api.fs.cut, opts("cut"))
vim.keymap.set("n", "y", api.fs.copy.filename, opts("copy filename"))
vim.keymap.set("n", "Y", api.fs.copy.relative_path, opts("copy relative path file"))
vim.keymap.set("n", "W", api.tree.collapse_all, opts("collapse all"))
vim.keymap.set("n", "I", api.tree.toggle_gitignore_filter, opts("toggle git ignored files"))
vim.keymap.set("n", "H", api.tree.toggle_hidden_filter, opts("toggle hidden files"))
vim.keymap.set("n", "<TAB>", api.node.open.preview, opts("preview node"))
vim.keymap.set("n", "F", api.live_filter.clear, opts("clear filter"))
vim.keymap.set("n", "f", api.live_filter.start, opts("filter"))
vim.keymap.set("n", "q", api.tree.close, opts("quit"))
end
local function git_reset(node)
local cwd = vim.loop.cwd()
local relative_path = string.gsub(node.absolute_path, cwd .. "/", "")
Job:new({
command = "git",
args = { "reset", relative_path },
}):start()
end
-- TODO: add here keymap for git diff window
require("nvim-tree").setup({
disable_netrw = true,
hijack_netrw = true,
@@ -49,16 +50,6 @@ require("nvim-tree").setup({
side = "left",
preserve_window_proportions = true,
centralize_selection = true,
mappings = {
list = {
{ key = "tn", action = "tabnew" },
{ key = "gs", action = "git_stage", action_cb = git_stage },
{ key = "gu", action = "git_unstage", action_cb = git_unstage },
{ key = "gr", action = "git_reset", action_cb = git_reset },
{ key = "l", action = "edit" },
{ key = "@", action = "cd" },
},
},
},
renderer = {
add_trailing = true,
@@ -103,4 +94,5 @@ require("nvim-tree").setup({
show_on_dirs = true,
icons = { hint = "", info = "", warning = "", error = "" },
},
on_attach = on_attach,
})