From f9b0ddf8d9dc3bab784eba79030b6359576f0aa0 Mon Sep 17 00:00:00 2001 From: aleidk Date: Sun, 29 Oct 2023 19:33:10 -0300 Subject: [PATCH] Add Oil.nvim as file explorer --- config/nvim/lazy-lock.json | 2 +- config/nvim/lua/aleidk/keymaps.lua | 3 + config/nvim/lua/aleidk/plugins/bufferline.lua | 5 +- .../nvim/lua/aleidk/plugins/file-browser.lua | 140 ++++++++++++++++++ config/nvim/lua/aleidk/plugins/lsp.lua | 2 +- config/nvim/lua/aleidk/plugins/lualine.lua | 13 +- config/nvim/lua/aleidk/plugins/nvim-tree.lua | 89 ----------- 7 files changed, 161 insertions(+), 93 deletions(-) create mode 100644 config/nvim/lua/aleidk/plugins/file-browser.lua delete mode 100644 config/nvim/lua/aleidk/plugins/nvim-tree.lua diff --git a/config/nvim/lazy-lock.json b/config/nvim/lazy-lock.json index dd345f0..250f11a 100644 --- a/config/nvim/lazy-lock.json +++ b/config/nvim/lazy-lock.json @@ -1,7 +1,6 @@ { "LuaSnip": { "branch": "master", "commit": "80a8528f084a97b624ae443a6f50ff8074ba486b" }, "alpha-nvim": { "branch": "main", "commit": "234822140b265ec4ba3203e3e0be0e0bb826dff5" }, - "bufdelete.nvim": { "branch": "master", "commit": "07d1f8ba79dec59d42b975a4df1c732b2e4e37b4" }, "bufferline.nvim": { "branch": "main", "commit": "357cc8f8eeb64702e6fcf2995e3b9becee99a5d3" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, @@ -44,6 +43,7 @@ "nvim-ts-autotag": { "branch": "main", "commit": "6be1192965df35f94b8ea6d323354f7dc7a557e4" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "92e688f013c69f90c9bbd596019ec10235bc51de" }, "nvim-web-devicons": { "branch": "master", "commit": "5de460ca7595806044eced31e3c36c159a493857" }, + "oil.nvim": { "branch": "master", "commit": "05a80e24f6c920e29ed741d12ede0840e456a3e4" }, "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, "pretty-fold.nvim": { "branch": "master", "commit": "a7d8b424abe0eedf50116c460fbe6dfd5783b1d5" }, "smart-splits.nvim": { "branch": "master", "commit": "c8a9173d70cbbd1f6e4a414e49e31df2b32a1362" }, diff --git a/config/nvim/lua/aleidk/keymaps.lua b/config/nvim/lua/aleidk/keymaps.lua index 0164888..688e2f2 100644 --- a/config/nvim/lua/aleidk/keymaps.lua +++ b/config/nvim/lua/aleidk/keymaps.lua @@ -30,6 +30,9 @@ vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = tr vim.keymap.set("n", "J", "mzJ`z", default("Keep cursor in column while joining lines")) +vim.keymap.set("n", "|", ":vs", default("Open vsplit")) +vim.keymap.set("n", "°", ":sp", default("Open split")) + vim.keymap.set("n", "", "zz", default("Keep cursor centered while junping")) vim.keymap.set("n", "", "zz", default("Keep cursor centered while junping")) diff --git a/config/nvim/lua/aleidk/plugins/bufferline.lua b/config/nvim/lua/aleidk/plugins/bufferline.lua index 9892958..83159bc 100644 --- a/config/nvim/lua/aleidk/plugins/bufferline.lua +++ b/config/nvim/lua/aleidk/plugins/bufferline.lua @@ -30,7 +30,10 @@ return { require("mini.bufremove").delete(n, false) end, -- stylua: ignore - right_mouse_command = function(n) require("mini.bufremove").delete(n, false) end, + always_show_bufferline = false, + right_mouse_command = function(n) + require("mini.bufremove").delete(n, false) + end, diagnostics = "nvim_lsp", diagnostics_indicator = function(_, _, diag) local icons = require("aleidk.constants").icons.diagnostics diff --git a/config/nvim/lua/aleidk/plugins/file-browser.lua b/config/nvim/lua/aleidk/plugins/file-browser.lua new file mode 100644 index 0000000..87d3ac8 --- /dev/null +++ b/config/nvim/lua/aleidk/plugins/file-browser.lua @@ -0,0 +1,140 @@ +return { + { + "nvim-tree/nvim-tree.lua", + -- enabled = false, + version = "*", + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + lazy = false, + config = function() + local tree = require("nvim-tree") + local api = require("nvim-tree.api") + + tree.setup({ + hijack_unnamed_buffer_when_opening = true, + disable_netrw = false, + hijack_netrw = false, -- handle by telescope browser + hijack_cursor = true, -- cursor at the start of filename + sync_root_with_cwd = true, + respect_buf_cwd = true, + update_focused_file = { + enable = true, -- focus curren file + update_root = true, + }, + actions = { open_file = { quit_on_open = true } }, + renderer = { + full_name = true, -- show remaining name in floating text + group_empty = true, -- group empty folders + add_trailing = true, -- Trailing slash to folders + highlight_opened_files = "all", + highlight_git = true, + }, + view = { + centralize_selection = true, -- center current file on enter + width = 30, -- N° of columns or % + }, + on_attach = function(bufnr) + local function opts(desc) + return { + desc = "nvim-tree: " .. desc, + buffer = bufnr, + noremap = true, + silent = true, + nowait = true, + } + end + + -- Check defaults here: https://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach + api.config.mappings.default_on_attach(bufnr) + + vim.keymap.set("n", "l", api.node.open.edit, opts("Open")) + vim.keymap.set("n", "o", api.node.open.edit, opts("Open")) + vim.keymap.set("n", "", api.node.open.edit, opts("Open")) + vim.keymap.set("n", "<2-LeftMouse>", api.node.open.edit, opts("Open")) + vim.keymap.set("n", "s", api.node.open.vertical, opts("Open in vsplit")) + vim.keymap.set("n", "v", api.node.open.horizontal, opts("Open in hsplit")) + vim.keymap.set("n", "t", api.node.open.tab, opts("Open in tab")) + vim.keymap.set("n", "h", api.node.navigate.parent_close, opts("Close dir")) + vim.keymap.set("n", "", api.node.navigate.parent_close, opts("Close dir")) + vim.keymap.set("n", "i", api.tree.toggle_hidden_filter, opts("Toggle Dotfiles")) + vim.keymap.set("n", "I", api.tree.toggle_gitignore_filter, opts("Toggle Git Ignore")) + end, + }) + + -- Auto open when a dir is opened + + local function open_nvim_tree(data) + -- buffer is a directory + local directory = vim.fn.isdirectory(data.file) == 1 + + if not directory then + return + end + + -- create a new, empty buffer + vim.cmd.enew() + + -- wipe the directory buffer + vim.cmd.bw(data.buf) + + -- change to the directory + vim.cmd.cd(data.file) + + -- open the tree + require("nvim-tree.api").tree.open() + end + + vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree }) + vim.api.nvim_create_user_command("Tree", "NvimTreeToggle", {}) + + -- bindings + -- disabled to discourage the use of this plugin without disabling it + -- vim.keymap.set("n", "e", ":NvimTreeToggle", { desc = "Toggle file tree", silent = true }) + -- vim.keymap.set("n", "", ":NvimTreeToggle", { desc = "Toggle file tree", silent = true }) + end, + }, + { + "stevearc/oil.nvim", + opts = function() + local oil = require("oil") + return { + win_options = { + number = false, + }, + delete_to_trash = true, + trash_command = "trash", + skip_confirm_for_simple_edits = false, + keymaps = { + ["g?"] = "actions.show_help", + [""] = "actions.select", + ["l"] = "actions.select", + [""] = "actions.open_external", + [""] = function() + oil.select({ vertical = true }) + vim.cmd.wincmd({ args = { "p" } }) + oil.close() + vim.cmd.wincmd({ args = { "p" } }) + end, + [""] = "actions.select_split", + [""] = "actions.select_tab", + [""] = "actions.preview", + [""] = "actions.preview_scroll_down", + [""] = "actions.preview_scroll_up", + [""] = "actions.close", + [""] = "actions.refresh", + ["y"] = "actions.copy_entry_path", + ["h"] = "actions.parent", + ["gs"] = "actions.change_sort", + ["gx"] = "actions.open_external", + ["g."] = "actions.toggle_hidden", + }, + } + end, + -- Optional dependencies + dependencies = { "nvim-tree/nvim-web-devicons" }, + keys = { + { "e", "Oil", desc = "Open file explorer" }, + }, + }, +} diff --git a/config/nvim/lua/aleidk/plugins/lsp.lua b/config/nvim/lua/aleidk/plugins/lsp.lua index c5cb752..10e0e24 100644 --- a/config/nvim/lua/aleidk/plugins/lsp.lua +++ b/config/nvim/lua/aleidk/plugins/lsp.lua @@ -32,7 +32,7 @@ return { -- See `:help K` for why this keymap nmap("K", vim.lsp.buf.hover, "Hover Documentation") - nmap("", vim.lsp.buf.signature_help, "Signature Documentation") + -- nmap("", vim.lsp.buf.signature_help, "Signature Documentation") -- Lesser used LSP functionality nmap("gD", vim.lsp.buf.declaration, "Goto Declaration") diff --git a/config/nvim/lua/aleidk/plugins/lualine.lua b/config/nvim/lua/aleidk/plugins/lualine.lua index bc65270..de82f6b 100644 --- a/config/nvim/lua/aleidk/plugins/lualine.lua +++ b/config/nvim/lua/aleidk/plugins/lualine.lua @@ -81,7 +81,18 @@ return { }, lualine_z = {}, }, - extensions = { "neo-tree", "lazy" }, + extensions = { + "neo-tree", + "lazy", + "fugitive", + "fzf", + "man", + "mason", + "nvim-tree", + "quickfix", + "symbols-outline", + "trouble", + }, } end, } diff --git a/config/nvim/lua/aleidk/plugins/nvim-tree.lua b/config/nvim/lua/aleidk/plugins/nvim-tree.lua deleted file mode 100644 index 42df21b..0000000 --- a/config/nvim/lua/aleidk/plugins/nvim-tree.lua +++ /dev/null @@ -1,89 +0,0 @@ -return { - "nvim-tree/nvim-tree.lua", - -- enabled = false, - version = "*", - dependencies = { - "nvim-tree/nvim-web-devicons", - }, - lazy = false, - config = function() - local tree = require("nvim-tree") - local api = require("nvim-tree.api") - - tree.setup({ - hijack_unnamed_buffer_when_opening = true, - disable_netrw = true, - hijack_netrw = false, -- handle by telescope browser - hijack_cursor = true, -- cursor at the start of filename - sync_root_with_cwd = true, - respect_buf_cwd = true, - update_focused_file = { - enable = true, -- focus curren file - update_root = true, - }, - actions = { open_file = { quit_on_open = true } }, - renderer = { - full_name = true, -- show remaining name in floating text - group_empty = true, -- group empty folders - add_trailing = true, -- Trailing slash to folders - highlight_opened_files = "all", - highlight_git = true, - }, - view = { - centralize_selection = true, -- center current file on enter - width = 30, -- N° of columns or % - }, - on_attach = function(bufnr) - local function opts(desc) - return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } - end - - -- Check defaults here: https://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach - api.config.mappings.default_on_attach(bufnr) - - vim.keymap.set("n", "l", api.node.open.edit, opts("Open")) - vim.keymap.set("n", "o", api.node.open.edit, opts("Open")) - vim.keymap.set("n", "", api.node.open.edit, opts("Open")) - vim.keymap.set("n", "<2-LeftMouse>", api.node.open.edit, opts("Open")) - vim.keymap.set("n", "s", api.node.open.vertical, opts("Open in vsplit")) - vim.keymap.set("n", "v", api.node.open.horizontal, opts("Open in hsplit")) - vim.keymap.set("n", "t", api.node.open.tab, opts("Open in tab")) - vim.keymap.set("n", "h", api.node.navigate.parent_close, opts("Close dir")) - vim.keymap.set("n", "", api.node.navigate.parent_close, opts("Close dir")) - vim.keymap.set("n", "i", api.tree.toggle_hidden_filter, opts("Toggle Dotfiles")) - vim.keymap.set("n", "I", api.tree.toggle_gitignore_filter, opts("Toggle Git Ignore")) - end, - }) - - -- Auto open when a dir is opened - - local function open_nvim_tree(data) - -- buffer is a directory - local directory = vim.fn.isdirectory(data.file) == 1 - - if not directory then - return - end - - -- create a new, empty buffer - vim.cmd.enew() - - -- wipe the directory buffer - vim.cmd.bw(data.buf) - - -- change to the directory - vim.cmd.cd(data.file) - - -- open the tree - require("nvim-tree.api").tree.open() - end - - vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree }) - vim.api.nvim_create_user_command("Tree", "NvimTreeToggle", {}) - - -- bindings - -- disabled to discourage the use of this plugin without disabling it - -- vim.keymap.set("n", "e", ":NvimTreeToggle", { desc = "Toggle file tree", silent = true }) - -- vim.keymap.set("n", "", ":NvimTreeToggle", { desc = "Toggle file tree", silent = true }) - end, -}