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 function opts(desc)
local cwd = vim.loop.cwd() return {
local relative_path = string.gsub(node.absolute_path, cwd .. "/", "") desc = "nvim-tree: " .. desc,
buffer = bufnr,
Job:new({ noremap = true,
command = "git", silent = true,
args = { "add", relative_path }, nowait = true,
}):start() }
end end
local function git_unstage(node) vim.keymap.set("n", "tn", api.node.open.tab, opts("tabnew"))
local cwd = vim.loop.cwd() vim.keymap.set("n", "l", api.node.open.edit, opts("edit"))
local relative_path = string.gsub(node.absolute_path, cwd .. "/", "") 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"))
Job:new({ vim.keymap.set("n", "<C-v>", api.node.open.vertical, opts("vertical split"))
command = "git", vim.keymap.set("n", "<C-h>", api.node.open.horizontal, opts("horizontal split"))
args = { "reset", relative_path }, vim.keymap.set("n", "a", api.fs.create, opts("create file"))
}):start() 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 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({ require("nvim-tree").setup({
disable_netrw = true, disable_netrw = true,
hijack_netrw = true, hijack_netrw = true,
@@ -49,16 +50,6 @@ require("nvim-tree").setup({
side = "left", side = "left",
preserve_window_proportions = true, preserve_window_proportions = true,
centralize_selection = 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 = { renderer = {
add_trailing = true, add_trailing = true,
@@ -103,4 +94,5 @@ require("nvim-tree").setup({
show_on_dirs = true, show_on_dirs = true,
icons = { hint = "", info = "", warning = "", error = "" }, icons = { hint = "", info = "", warning = "", error = "" },
}, },
on_attach = on_attach,
}) })