From 9aea1c8fe507abcb0b2b4a1f2d378cb3d8a45cdd Mon Sep 17 00:00:00 2001 From: ecosse3 Date: Sun, 14 Jul 2024 22:11:51 +0200 Subject: [PATCH] refactor(plugins)!: new NvimTree key bindings and configuration --- lua/plugins/tree.lua | 215 +++++++++++++++++++++++-------------------- 1 file changed, 113 insertions(+), 102 deletions(-) diff --git a/lua/plugins/tree.lua b/lua/plugins/tree.lua index fe9f3f01..ec5f9e55 100644 --- a/lua/plugins/tree.lua +++ b/lua/plugins/tree.lua @@ -1,14 +1,13 @@ -local utils = require("utils") local api = require("nvim-tree.api") local git_icons = { - unstaged = "", - staged = "", - unmerged = "", - renamed = "➜", - untracked = "", - deleted = "", - ignored = "◌", + unstaged = "", + staged = "", + unmerged = "", + renamed = "➜", + untracked = "", + deleted = "", + ignored = "◌", } local function on_attach(bufnr) @@ -56,98 +55,110 @@ local function on_attach(bufnr) vim.keymap.set('n', 'S', api.tree.search_node, opts('Search')) end -require("nvim-tree").setup({ - on_attach = on_attach, - -- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually) - sync_root_with_cwd = true, - --false by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree - respect_buf_cwd = true, - -- show lsp diagnostics in the signcolumn - diagnostics = { - enable = false, - icons = { - hint = "", - info = "", - warning = "", - error = "", - }, - }, - renderer = { - group_empty = true, - highlight_git = true, - highlight_opened_files = "none", - root_folder_label = ":~", - indent_markers = { - enable = false, - icons = { - corner = "└ ", - edge = "│ ", - none = " ", - }, - }, - icons = { - show = { - file = true, - folder = true, - folder_arrow = true, - git = true, - modified = true, - }, - glyphs = { - git = git_icons, - }, - }, - }, - -- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file - update_focused_file = { - -- enables the feature - enable = true, - -- update the root directory of the tree to the one of the folder containing the file if the file is not under the current root directory - -- only relevant when `update_focused_file.enable` is true - update_root = true, - -- list of buffer names / filetypes that will not update the cwd if the file isn't found under the current root directory - -- only relevant when `update_focused_file.update_cwd` is true and `update_focused_file.enable` is true - ignore_list = {}, - }, - -- configuration options for the system open command (`s` in the tree by default) - filters = { - dotfiles = false, - custom = {}, - }, - actions = { - use_system_clipboard = true, - change_dir = { - enable = true, - global = false, - restrict_above_cwd = false, - }, - open_file = { - quit_on_open = false, - -- if true the tree will resize itself after opening a file - resize_window = false, - window_picker = { - enable = true, - chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", - exclude = { - filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, - buftype = { "nofile", "terminal", "help" }, - }, - }, - }, - }, - view = { - -- width of the window, can be either a number (columns) or a string in `%` - width = 40, - -- side of the tree, can be one of 'left' | 'right' | 'top' | 'bottom' - side = "left", - number = false, - relativenumber = false, - }, -}) +return { + { + "nvim-tree/nvim-tree.lua", + cmd = { + "NvimTreeOpen", + "NvimTreeClose", + "NvimTreeToggle", + "NvimTreeFindFile", + "NvimTreeFindFileToggle", + }, + keys = { + { "", "lua require('nvim-tree.api').tree.toggle()", desc = "NvimTree" }, + }, + config = function() + require("nvim-tree").setup({ + on_attach = on_attach, + -- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually) + sync_root_with_cwd = true, + --false by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree + respect_buf_cwd = true, + -- show lsp diagnostics in the signcolumn + diagnostics = { + enable = false, + icons = { + hint = "", + info = "", + warning = "", + error = "", + }, + }, + renderer = { + group_empty = true, + highlight_git = true, + highlight_opened_files = "none", + root_folder_label = ":~", + indent_markers = { + enable = false, + icons = { + corner = "└ ", + edge = "│ ", + none = " ", + }, + }, + icons = { + show = { + file = true, + folder = true, + folder_arrow = true, + git = true, + modified = true, + }, + glyphs = { + git = git_icons, + }, + }, + }, + -- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file + update_focused_file = { + -- enables the feature + enable = true, + -- update the root directory of the tree to the one of the folder containing the file if the file is not under the current root directory + -- only relevant when `update_focused_file.enable` is true + update_root = true, + -- list of buffer names / filetypes that will not update the cwd if the file isn't found under the current root directory + -- only relevant when `update_focused_file.update_cwd` is true and `update_focused_file.enable` is true + ignore_list = {}, + }, + -- configuration options for the system open command (`s` in the tree by default) + filters = { + dotfiles = false, + custom = {}, + }, + actions = { + use_system_clipboard = true, + change_dir = { + enable = true, + global = false, + restrict_above_cwd = false, + }, + open_file = { + quit_on_open = false, + -- if true the tree will resize itself after opening a file + resize_window = false, + window_picker = { + enable = true, + chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", + exclude = { + filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, + buftype = { "nofile", "terminal", "help" }, + }, + }, + }, + }, + view = { + -- width of the window, can be either a number (columns) or a string in `%` + width = 40, + -- side of the tree, can be one of 'left' | 'right' | 'top' | 'bottom' + side = "left", + number = false, + relativenumber = false, + }, -vim.api.nvim_set_keymap( - "n", - "", - "lua require('nvim-tree.api').tree.toggle()", - { noremap = true, silent = true } -) + }) + end + }, + +}