From 9326034ef9f6f5194cedded7735e07ad19748530 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Wed, 1 Mar 2023 11:55:03 +0100 Subject: [PATCH] nvim: make nvim-tree on_attach keymaps local to the tree buffer --- config/nvim/after/plugin/nvim-tree.lua | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/config/nvim/after/plugin/nvim-tree.lua b/config/nvim/after/plugin/nvim-tree.lua index db3d22b..b168c51 100644 --- a/config/nvim/after/plugin/nvim-tree.lua +++ b/config/nvim/after/plugin/nvim-tree.lua @@ -1,23 +1,23 @@ -local nt, callback - -local ok, _ = pcall(function() - nt = require 'nvim-tree' - api = require 'nvim-tree.api' -end) - +local ok, nt = pcall(require, 'nvim-tree') if not ok then return end +local on_attach = function(bufnr) + local api = require 'nvim-tree.api' + local opts = function(desc) + return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, silent = true } + end + + vim.keymap.set('n', 'l', api.node.open.edit, opts('open')) + vim.keymap.set('n', '', api.node.open.edit, opts('open')) + vim.keymap.set('n', 'o', api.node.open.edit, opts('open')) + vim.keymap.set('n', 'h', api.node.navigate.parent_close, opts('close directory')) +end + nt.setup { disable_netrw = true, -- replace netrw with nvim-tree hijack_cursor = true, -- keep the cursor on begin of the filename sync_root_with_cwd = true, -- watch for `DirChanged` and refresh the tree - - on_attach = function() - for _, lhs in ipairs({'l', '', 'o'}) do - vim.keymap.set('n', lhs, api.node.open.edit) - end - vim.keymap.set('n', 'h', api.node.navigate.parent_close) - end, + on_attach = on_attach, git = { ignore = false, -- don't hide files from .gitignore