diff --git a/lua/core/init.lua b/lua/core/init.lua index 4efce92..c77801c 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -6,7 +6,7 @@ require("user.keymaps") -- require("user.snip") -- require("core.neovide") require("custom.autocmd") --- require("custom.keymaps") +require("custom.keymaps") -- require("user.nvim-tree") -- require("user.options") -- require("user.keymaps") diff --git a/lua/custom/autocmd.lua b/lua/custom/autocmd.lua index cb51ab3..874c696 100644 --- a/lua/custom/autocmd.lua +++ b/lua/custom/autocmd.lua @@ -47,3 +47,27 @@ vim.g.VM_Extend_hl = "DiffAdd" -- vim.g.VM_Cursor_hl = "Visual" vim.g.VM_Cursor_hl = "DiffText" vim.g.VM_Insert_hl = "DiffChange" + +-- NvimTree automatically resize the floating window when neovim's window size changes +-- local tree_api = require("nvim-tree") +-- local tree_view = require("nvim-tree.view") +-- +-- vim.api.nvim_create_augroup("NvimTreeResize", { +-- clear = true, +-- }) +-- +-- vim.api.nvim_create_autocmd({ "VimResized" }, { +-- group = "NvimTreeResize", +-- callback = function() +-- if tree_view.is_visible() then +-- tree_view.close() +-- tree_api.open() +-- end +-- end, +-- }) + +-- auto open file if creation +local api = require("nvim-tree.api") +api.events.subscribe(api.events.Event.FileCreated, function(file) + vim.cmd("edit " .. file.fname) +end) diff --git a/lua/custom/keymaps.lua b/lua/custom/keymaps.lua index 6efddc8..8cd41d9 100644 --- a/lua/custom/keymaps.lua +++ b/lua/custom/keymaps.lua @@ -2,3 +2,4 @@ local opts = { noremap = true, silent = true } local keymap = vim.api.nvim_set_keymap keymap("n", "]h", 'lua print("Testing")', opts) +keymap("n", "F", "NvimTreeToggle", opts) diff --git a/lua/custom/plugins/lualine_onedark.lua b/lua/custom/plugins/lualine_onedark.lua index e330c37..62cdaa4 100644 --- a/lua/custom/plugins/lualine_onedark.lua +++ b/lua/custom/plugins/lualine_onedark.lua @@ -150,8 +150,8 @@ return { if data_ok then lsp_progress = lspprogress.progress end - -- stylua: ignore - local is_transparat=true + -- stylua: ignore + local is_transparat=true local colors = require("onedarkpro.helpers").get_colors("onedark") local onedark = { diff --git a/lua/custom/plugins/nvim_tree.lua b/lua/custom/plugins/nvim_tree.lua new file mode 100644 index 0000000..1123684 --- /dev/null +++ b/lua/custom/plugins/nvim_tree.lua @@ -0,0 +1,274 @@ +return { + { + "kyazdani42/nvim-tree.lua", + lazy = true, + -- event = "BufRead", + cmd = { "NvimTree", "NvimTreeOpen", "NvimTreeToggle", "NvimTreeFocus", "NvimTreeClose" }, + -- dependencies = "kyazdani42/nvim-web-devicons", + config = function() + local data_exists, treeconfig = pcall(require, "core.config") + if data_exists then + if treeconfig.loadnvimtree_lazy then + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + + -- set termguicolors to enable highlight groups + vim.opt.termguicolors = true + local status_ok, nvim_tree = pcall(require, "nvim-tree") + if not status_ok then + return + end + + local HEIGHT_RATIO = 0.8 -- You can change this + local WIDTH_RATIO = 0.5 -- You can change this too + + local icons = require("user.icons") + nvim_tree.setup({ + auto_reload_on_write = false, + disable_netrw = false, + hijack_cursor = false, + hijack_netrw = true, + hijack_unnamed_buffer_when_opening = false, + sort_by = "name", + root_dirs = {}, + prefer_startup_root = false, + sync_root_with_cwd = true, + reload_on_bufenter = false, + respect_buf_cwd = false, + on_attach = "default", + select_prompts = false, + view = { + adaptive_size = false, + centralize_selection = true, + -- width = 30, + side = "left", + preserve_window_proportions = false, + number = false, + relativenumber = false, + signcolumn = "yes", + -- float = { + -- enable = true, + -- quit_on_focus_loss = true, + -- open_win_config = { + -- relative = "editor", + -- border = "rounded", + -- width = 30, + -- height = 30, + -- row = 1, + -- col = 1, + -- }, + -- }, + float = { + enable = true, + open_win_config = function() + local screen_w = vim.opt.columns:get() + local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() + local window_w = screen_w * WIDTH_RATIO + local window_h = screen_h * HEIGHT_RATIO + local window_w_int = math.floor(window_w) + local window_h_int = math.floor(window_h) + local center_x = (screen_w - window_w) / 2 + local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get() + return { + border = "rounded", + relative = "editor", + row = center_y, + col = center_x, + width = window_w_int, + height = window_h_int, + } + end, + }, + width = function() + return math.floor(vim.opt.columns:get() * WIDTH_RATIO) + end, + }, + renderer = { + add_trailing = false, + group_empty = false, + highlight_git = true, + full_name = false, + highlight_opened_files = "none", + root_folder_label = ":t", + -- root_folder_label = false, + indent_width = 2, + indent_markers = { + enable = true, + inline_arrows = true, + icons = { + corner = "└", + edge = "│", + item = "│", + none = " ", + }, + }, + icons = { + webdev_colors = true, + git_placement = "before", + padding = " ", + symlink_arrow = " ➛ ", + show = { + file = true, + folder = true, + folder_arrow = true, + git = true, + }, + glyphs = { + default = icons.ui.Text, + symlink = icons.ui.FileSymlink, + bookmark = icons.ui.BookMark, + folder = { + -- arrow_closed = icons.ui.TriangleShortArrowRight, + arrow_closed = icons.ui.ChevronShortRight, + -- arrow_open = icons.ui.TriangleShortArrowDown, + arrow_open = icons.ui.ChevronShortDown, + default = icons.ui.Folder, + open = icons.ui.FolderOpen, + empty = icons.ui.EmptyFolder, + empty_open = icons.ui.EmptyFolderOpen, + symlink = icons.ui.FolderSymlink, + symlink_open = icons.ui.FolderOpen, + }, + git = { + unstaged = icons.git.FileUnstaged, + staged = icons.git.FileStaged, + unmerged = icons.git.FileUnmerged, + renamed = icons.git.FileRenamed, + untracked = icons.git.FileUntracked, + deleted = icons.git.FileDeleted, + ignored = icons.git.FileIgnored, + }, + }, + }, + special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" }, + symlink_destination = true, + }, + hijack_directories = { + enable = false, + auto_open = true, + }, + update_focused_file = { + enable = true, + debounce_delay = 15, + update_root = true, + ignore_list = {}, + }, + diagnostics = { + enable = true, + show_on_dirs = false, + show_on_open_dirs = true, + debounce_delay = 50, + severity = { + min = vim.diagnostic.severity.HINT, + max = vim.diagnostic.severity.ERROR, + }, + icons = { + hint = icons.diagnostics.BoldHint, + info = icons.diagnostics.BoldInformation, + warning = icons.diagnostics.BoldWarning, + error = icons.diagnostics.BoldError, + }, + }, + filters = { + dotfiles = false, + git_clean = false, + no_buffer = false, + custom = { "node_modules", "\\.cache", "\\.git" }, + exclude = { + ".gitignore", + ".prettierignore", + }, + }, + filesystem_watchers = { + enable = true, + debounce_delay = 50, + ignore_dirs = {}, + }, + git = { + enable = true, + ignore = false, + show_on_dirs = true, + show_on_open_dirs = true, + disable_for_dirs = {}, + timeout = 400, + }, + actions = { + use_system_clipboard = true, + change_dir = { + enable = true, + global = false, + restrict_above_cwd = false, + }, + expand_all = { + max_folder_discovery = 300, + exclude = {}, + }, + file_popup = { + open_win_config = { + col = 1, + row = 1, + relative = "cursor", + border = "shadow", + style = "minimal", + }, + }, + open_file = { + quit_on_open = false, + resize_window = false, + window_picker = { + enable = true, + picker = "default", + chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", + exclude = { + filetype = { "notify", "lazy", "qf", "diff", "fugitive", "fugitiveblame" }, + buftype = { "nofile", "terminal", "help" }, + }, + }, + }, + remove_file = { + close_window = true, + }, + }, + trash = { + cmd = "trash", + require_confirm = true, + }, + live_filter = { + prefix = "[FILTER]: ", + always_show_folders = true, + }, + tab = { + sync = { + open = false, + close = false, + ignore = {}, + }, + }, + notify = { + threshold = vim.log.levels.INFO, + -- threshold = vim.log.levels.ERROR, + }, + log = { + enable = false, + truncate = false, + types = { + all = false, + config = false, + copy_paste = false, + dev = false, + diagnostics = false, + git = false, + profile = false, + watcher = false, + }, + }, + system_open = { + cmd = nil, + args = {}, + }, + }) + end + end + end, + }, +} diff --git a/lua/custom/plugins/onedarkpro.lua b/lua/custom/plugins/onedarkpro.lua index 7168ca2..9e16cfb 100644 --- a/lua/custom/plugins/onedarkpro.lua +++ b/lua/custom/plugins/onedarkpro.lua @@ -61,7 +61,7 @@ return { -- overide nvimtree text fill color folder opened NvimTreeOpenedFolderName = { fg = "${blue}" }, -- overide nvimtree text fill color root folder - NvimTreeRootFolder = { fg = "${yellow}" }, + NvimTreeRootFolder = { fg = "${blue}" }, NvimTreeSpecialFile = { fg = "${orange}" }, NvimTreeWinSeparator = { fg = "#202329" }, NvimTreeIndentMarker = { fg = "#3E4450" }, diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index 1eec144..93a2713 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -35,7 +35,7 @@ return { "kyazdani42/nvim-tree.lua", lazy = true, -- event = "BufRead", - cmd = { "NvimTree", "NvimTreeToggle", "NvimTreeFocus", "NvimTreeClose" }, + cmd = { "NvimTree", "NvimTreeOpen", "NvimTreeToggle", "NvimTreeFocus", "NvimTreeClose" }, -- dependencies = "kyazdani42/nvim-web-devicons", config = function() local data_exists, treeconfig = pcall(require, "core.config")