vim.g.base46_cache = vim.fn.stdpath "data" .. "/base46/" vim.g.mapleader = " " -- bootstrap lazy and all plugins local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" if not vim.uv.fs_stat(lazypath) then local repo = "https://github.com/folke/lazy.nvim.git" vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath } end vim.opt.rtp:prepend(lazypath) local lazy_config = require "configs.lazy" -- load plugins require("lazy").setup({ { "NvChad/NvChad", lazy = false, branch = "v2.5", import = "nvchad.plugins", }, { import = "plugins" }, }, lazy_config) -- load theme dofile(vim.g.base46_cache .. "defaults") dofile(vim.g.base46_cache .. "statusline") require "options" require "nvchad.autocmds" vim.schedule(function() require "mappings" end) vim.api.nvim_create_autocmd({ "BufEnter", "QuitPre" }, { nested = false, callback = function(e) local tree = require("nvim-tree.api").tree -- Nothing to do if tree is not opened if not tree.is_visible() then return end -- How many focusable windows do we have? (excluding e.g. incline status window) local winCount = 0 for _, winId in ipairs(vim.api.nvim_list_wins()) do if vim.api.nvim_win_get_config(winId).focusable then winCount = winCount + 1 end end -- We want to quit and only one window besides tree is left if e.event == "QuitPre" and winCount == 2 then vim.api.nvim_cmd({ cmd = "qall" }, {}) end -- :bd was probably issued an only tree window is left -- Behave as if tree was closed (see `:h :bd`) if e.event == "BufEnter" and winCount == 1 then -- Required to avoid "Vim:E444: Cannot close last window" vim.defer_fn(function() -- close nvim-tree: will go to the last buffer used before closing tree.toggle { find_file = true, focus = true } -- re-open nivm-tree tree.toggle { find_file = true, focus = false } end, 10) end end, }) require("nvim-tree").setup { actions = { open_file = { quit_on_open = true, }, }, git = { enable = true, ignore = false, timeout = 400, }, filters = { custom = { ".git", "vendor", "node_modules" }, -- exclude = { ".gitignore" }, }, } local autocmd = vim.api.nvim_create_autocmd local function open_nvim_tree(data) -- buffer is a directory local directory = vim.fn.isdirectory(data.file) == 1 -- buffer is a [No Name] local no_name = data.file == "" and vim.bo[data.buf].buftype == "" if not directory and not no_name then return end if directory then -- change to the directory vim.cmd.cd(data.file) end -- open the tree require("nvim-tree.api").tree.open() -- Get a list of all buffers local buffers = vim.api.nvim_list_bufs() -- Iterate over each buffer for _, bufnr in ipairs(buffers) do -- Check if the buffer is empty and doesn't have a name if vim.api.nvim_buf_is_loaded(bufnr) and vim.api.nvim_buf_get_name(bufnr) == "" and vim.api.nvim_buf_get_option(bufnr, "buftype") == "" then -- Get all lines in the buffer local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) -- Initialize a variable to store the total number of characters local total_characters = 0 -- Iterate over each line and calculate the number of characters for _, line in ipairs(lines) do total_characters = total_characters + #line end -- Close the buffer if it's empty: if total_characters == 0 then vim.api.nvim_buf_delete(bufnr, { force = true, }) end end end end autocmd({ "VimEnter" }, { callback = open_nvim_tree }) vim.api.nvim_create_autocmd("TextYankPost", { callback = function() vim.highlight.on_yank { higroup = "IncSearch", timeout = 200 } end, })