From d7f4fef5996c6a4f93416b28b4334fae85889053 Mon Sep 17 00:00:00 2001 From: Thomas Dorsch Date: Wed, 13 Aug 2025 07:19:01 +0000 Subject: [PATCH] Adding nvim-tree --- lua/custom/plugins/init.lua | 4 +++ lua/custom/plugins/nvim-tree.lua | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 lua/custom/plugins/nvim-tree.lua diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index cfdcf3c2..fe02583e 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -3,6 +3,10 @@ -- -- See the kickstart.nvim README for more information +-- Disabled netrw plugin, because we will use nvim-tree +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + -- Set the blinking cursor settings vim.o.guicursor = 'n-v:block,i:ver25,r-cr-o:hor20,a:blinkwait700-blinkoff400-blinkon250' diff --git a/lua/custom/plugins/nvim-tree.lua b/lua/custom/plugins/nvim-tree.lua new file mode 100644 index 00000000..13cefc27 --- /dev/null +++ b/lua/custom/plugins/nvim-tree.lua @@ -0,0 +1,50 @@ +return { + 'nvim-tree/nvim-tree.lua', + version = '*', + lazy = false, + dependencies = { + 'nvim-tree/nvim-web-devicons', + }, + config = function() + require('nvim-tree').setup { + filters = { + dotfiles = true, + }, + } + -- Helper function to setup a custom keybindings when nvim-tree buffer is active + local function my_on_attach(bufnr) + local api = require 'nvim-tree.api' + + local function opts(desc) + return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + -- default mappings + api.config.mappings.default_on_attach(bufnr) + + -- add/overwrite custom mappings + vim.keymap.set('n', '?', api.tree.toggle_help, opts 'Help') + end + + -- pass to setup along with your other options + require('nvim-tree').setup { + --- + on_attach = my_on_attach, + --- + } + + -- fix the width of nvim tree if once adjusted. + require('nvim-tree').setup { + actions = { + open_file = { + quit_on_open = false, -- important: don't quit tree immediately + resize_window = false, -- prevent auto-resizing + }, + }, + } + + -- Keybinding in "normal" vi mode + local anotherApi = require 'nvim-tree.api' + vim.keymap.set('n', 't', anotherApi.tree.toggle, { desc = 'Toogle nvim-tree' }) + end, +}