From 1fae90350f4240f79be967c67c02e28a4e5088dc Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 5 Aug 2025 17:05:46 +0200 Subject: [PATCH] Changed tree viewer to oil.nvim --- lazy-lock.json | 2 +- lua/custom/plugins/oil.lua | 29 ++++++++++++ lua/custom/plugins/tree.lua | 89 ------------------------------------- 3 files changed, 30 insertions(+), 90 deletions(-) create mode 100644 lua/custom/plugins/oil.lua delete mode 100644 lua/custom/plugins/tree.lua diff --git a/lazy-lock.json b/lazy-lock.json index 94516133..a3d4515a 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -25,10 +25,10 @@ "nvim-lspconfig": { "branch": "master", "commit": "1ddc1a2e692b120cda6d33c890461e49cb85d6bf" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, "nvim-notify": { "branch": "master", "commit": "a22f5d7ac511c2df2fd3290a9f04c48d5a822e2e" }, - "nvim-tree.lua": { "branch": "master", "commit": "6b5b36659688767fb9f133bb83024ab1466fe5cd" }, "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-ts-autotag": { "branch": "main", "commit": "a1d526af391f6aebb25a8795cbc05351ed3620b5" }, "nvim-web-devicons": { "branch": "master", "commit": "19d6211c78169e78bab372b585b6fb17ad974e82" }, + "oil.nvim": { "branch": "master", "commit": "bbad9a76b2617ce1221d49619e4e4b659b3c61fc" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, diff --git a/lua/custom/plugins/oil.lua b/lua/custom/plugins/oil.lua new file mode 100644 index 00000000..babe51ff --- /dev/null +++ b/lua/custom/plugins/oil.lua @@ -0,0 +1,29 @@ +return { + 'stevearc/oil.nvim', + lazy = false, + ---@module 'oil' + ---@type oil.SetupOpts + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + local oil = require 'oil' + + oil.setup { + columns = { 'icon' }, + keymaps = { + ['g?'] = { 'actions.show_help', mode = 'n' }, + ['gs'] = { 'actions.change_sort', mode = 'n' }, + [''] = { 'actions.select' }, + [''] = { 'actions.select' }, + [''] = { 'actions.parent' }, + [''] = { 'actions.select_split' }, + [''] = { 'actions.close', mode = 'n' }, + [''] = { 'actions.close', mode = 'n' }, + }, + view_options = { + show_hidden = true, + }, + } + + vim.keymap.set('n', '-', oil.toggle_float, { desc = 'Open parent directory' }) + end, +} diff --git a/lua/custom/plugins/tree.lua b/lua/custom/plugins/tree.lua deleted file mode 100644 index bfbf3a8a..00000000 --- a/lua/custom/plugins/tree.lua +++ /dev/null @@ -1,89 +0,0 @@ -return { - 'nvim-tree/nvim-tree.lua', - version = '*', - lazy = false, - dependencies = { - 'nvim-tree/nvim-web-devicons', - }, - config = function() - local function custom_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 - local function edit_or_open() - local node = api.tree.get_node_under_cursor() - - if node.nodes ~= nil then - -- expand or collapse folder - api.node.open.edit() - else - -- open file - api.node.open.edit() - -- Close the tree if file was opened - api.tree.close() - end - end - - -- open as vsplit on current node - local function vsplit_preview() - local node = api.tree.get_node_under_cursor() - - if node.nodes ~= nil then - -- expand or collapse folder - api.node.open.edit() - else - -- open file as vsplit - api.node.open.vertical() - end - - -- Finally refocus on tree if it was lost - api.tree.focus() - end - - -- default mappings - api.config.mappings.default_on_attach(bufnr) - - -- custom mappings - vim.keymap.set('n', '', api.tree.change_root_to_parent, opts 'Up') - vim.keymap.set('n', '?', api.tree.toggle_help, opts 'Help') - -- - -- global - vim.api.nvim_set_keymap('n', '', ':NvimTreeToggle', { silent = true, noremap = true }) - - -- on_attach - vim.keymap.set('n', 'l', edit_or_open, opts 'Edit Or Open') - vim.keymap.set('n', 'L', vsplit_preview, opts 'Vsplit Preview') - vim.keymap.set('n', 'h', api.tree.close, opts 'Close') - vim.keymap.set('n', 'H', api.tree.collapse_all, opts 'Collapse All') - end - - require('nvim-tree').setup { - on_attach = custom_attach, - sort = { - sorter = 'case_sensitive', - }, - view = { - width = 30, - }, - renderer = { - group_empty = true, - }, - filters = { - dotfiles = true, - }, - } - end, -} --- return { --- 'nvim-tree/nvim-tree.lua', --- version = '*', --- lazy = false, --- dependencies = { --- 'nvim-tree/nvim-web-devicons', --- }, --- config = function() --- require('nvim-tree').setup {} --- end, --- }