diff --git a/Scripts/ReplaceNvChad.bash b/Scripts/ReplaceNvChad.bash new file mode 100755 index 00000000..6199e1a1 --- /dev/null +++ b/Scripts/ReplaceNvChad.bash @@ -0,0 +1,4 @@ +#!/bin/bash + +rm -r ~/.config/nvim/lua/* +cp -r ../nvchad/* ~/.config/nvim/lua diff --git a/Scripts/SyncNvChad.bash b/Scripts/SyncNvChad.bash new file mode 100755 index 00000000..6857cecf --- /dev/null +++ b/Scripts/SyncNvChad.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +rm -r ../nvchad +mkdir ../nvchad +cp -r ~/.config/nvim/lua/* ../nvchad diff --git a/nvchad/core/default_config.lua b/nvchad/core/default_config.lua new file mode 100644 index 00000000..1c7152b4 --- /dev/null +++ b/nvchad/core/default_config.lua @@ -0,0 +1,27 @@ +-- Chadrc overrides this file + +local M = {} + +M.options = { + nvChad = { + update_url = "https://github.com/NvChad/NvChad", + update_branch = "main", + }, +} + +M.ui = { + -- hl = highlights + hl_add = {}, + hl_override = {}, + changed_themes = {}, + theme_toggle = { "onedark", "one_light" }, + theme = "onedark", -- default theme + transparency = false, +} + +M.plugins = {} + +-- check core.mappings for table structure +M.mappings = require "core.mappings" + +return M diff --git a/nvchad/core/init.lua b/nvchad/core/init.lua new file mode 100644 index 00000000..e96ca1a6 --- /dev/null +++ b/nvchad/core/init.lua @@ -0,0 +1,27 @@ +-- add binaries installed by mason.nvim to path +local is_windows = vim.loop.os_uname().sysname == "Windows_NT" +vim.env.PATH = vim.env.PATH .. (is_windows and ";" or ":") .. vim.fn.stdpath "data" .. "/mason/bin" + +-- commands +vim.cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" +vim.cmd "silent! command! NvChadSnapshotCreate lua require('nvchad').snap_create()" +vim.cmd "silent! command! NvChadSnapshotDelete lua require('nvchad').snap_delete()" +vim.cmd "silent! command! NvChadSnapshotCheckout lua require('nvchad').snap_checkout()" + +-- autocmds +local autocmd = vim.api.nvim_create_autocmd + +-- dont list quickfix buffers +autocmd("FileType", { + pattern = "qf", + callback = function() + vim.opt_local.buflisted = false + end, +}) + +-- wrap the PackerSync command to warn people before using it in NvChadSnapshots +autocmd("VimEnter", { + callback = function() + vim.cmd "command! -nargs=* -complete=customlist,v:lua.require'packer'.plugin_complete PackerSync lua require('plugins') require('core.utils').packer_sync()" + end, +}) diff --git a/nvchad/core/lazy_load.lua b/nvchad/core/lazy_load.lua new file mode 100644 index 00000000..29973d45 --- /dev/null +++ b/nvchad/core/lazy_load.lua @@ -0,0 +1,79 @@ +local M = {} +local autocmd = vim.api.nvim_create_autocmd + +-- require("packer").loader(tb.plugins) +-- This must be used for plugins that need to be loaded just after a file +-- ex : treesitter, lspconfig etc +M.lazy_load = function(tb) + autocmd(tb.events, { + group = vim.api.nvim_create_augroup(tb.augroup_name, {}), + callback = function() + if tb.condition() then + vim.api.nvim_del_augroup_by_name(tb.augroup_name) + + -- dont defer for treesitter as it will show slow highlighting + -- This deferring only happens only when we do "nvim filename" + if tb.plugin ~= "nvim-treesitter" then + vim.defer_fn(function() + require("packer").loader(tb.plugin) + if tb.plugin == "nvim-lspconfig" then + vim.cmd "silent! do FileType" + end + end, 0) + else + require("packer").loader(tb.plugin) + end + end + end, + }) +end + +-- load certain plugins only when there's a file opened in the buffer +-- if "nvim filename" is executed -> load the plugin after nvim gui loads +-- This gives an instant preview of nvim with the file opened + +M.on_file_open = function(plugin_name) + M.lazy_load { + events = { "BufRead", "BufWinEnter", "BufNewFile" }, + augroup_name = "BeLazyOnFileOpen" .. plugin_name, + plugin = plugin_name, + condition = function() + local file = vim.fn.expand "%" + return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= "" + end, + } +end + +M.packer_cmds = { + "PackerSnapshot", + "PackerSnapshotRollback", + "PackerSnapshotDelete", + "PackerInstall", + "PackerUpdate", + "PackerSync", + "PackerClean", + "PackerCompile", + "PackerStatus", + "PackerProfile", + "PackerLoad", +} + +M.treesitter_cmds = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSEnable", "TSDisable", "TSModuleInfo" } +M.mason_cmds = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUninstall", "MasonUninstallAll", "MasonLog" } + +M.gitsigns = function() + autocmd({ "BufRead" }, { + group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }), + callback = function() + vim.fn.system("git -C " .. vim.fn.expand "%:p:h" .. " rev-parse") + if vim.v.shell_error == 0 then + vim.api.nvim_del_augroup_by_name "GitSignsLazyLoad" + vim.schedule(function() + require("packer").loader "gitsigns.nvim" + end) + end + end, + }) +end + +return M diff --git a/nvchad/core/mappings.lua b/nvchad/core/mappings.lua new file mode 100644 index 00000000..184a8c17 --- /dev/null +++ b/nvchad/core/mappings.lua @@ -0,0 +1,471 @@ +-- n, v, i, t = mode names + +local function termcodes(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local M = {} + +M.general = { + i = { + -- go to beginning and end + [""] = { "^i", "beginning of line" }, + [""] = { "", "end of line" }, + + -- navigate within insert mode + [""] = { "", "move left" }, + [""] = { "", "move right" }, + [""] = { "", "move down" }, + [""] = { "", "move up" }, + }, + + n = { + [""] = { " noh ", "no highlight" }, + + -- switch between windows + [""] = { "h", "window left" }, + [""] = { "l", "window right" }, + [""] = { "j", "window down" }, + [""] = { "k", "window up" }, + + -- save + [""] = { " w ", "save file" }, + + -- Copy all + [""] = { " %y+ ", "copy whole file" }, + + -- line numbers + ["n"] = { " set nu! ", "toggle line number" }, + ["rn"] = { " set rnu! ", "toggle relative number" }, + + -- update nvchad + ["uu"] = { " :NvChadUpdate ", "update nvchad" }, + + ["tt"] = { + function() + require("base46").toggle_theme() + end, + "toggle theme", + }, + + -- Allow moving the cursor through wrapped lines with j, k, and + -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ + -- empty mode is same as using :map + -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour + ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, + ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, + [""] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, + [""] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, + + -- new buffer + ["b"] = { " enew ", "new buffer" }, + }, + + t = { [""] = { termcodes "", "escape terminal mode" } }, + + v = { + [""] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, + [""] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, + }, + + x = { + ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, + ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, + -- Don't copy the replaced text after pasting in visual mode + -- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste + ["p"] = { 'p:let @+=@0:let @"=@0', opts = { silent = true } }, + }, +} + +M.tabufline = { + plugin = true, + + n = { + -- cycle through buffers + [""] = { + function() + require("nvchad_ui.tabufline").tabuflineNext() + end, + "goto next buffer", + }, + + [""] = { + function() + require("nvchad_ui.tabufline").tabuflinePrev() + end, + "goto prev buffer", + }, + + -- pick buffers via numbers + [""] = { " TbufPick ", "Pick buffer" }, + + -- close buffer + hide terminal buffer + ["x"] = { + function() + require("nvchad_ui.tabufline").close_buffer() + end, + "close buffer", + }, + }, +} + +M.comment = { + plugin = true, + + -- toggle comment in both modes + n = { + ["/"] = { + function() + require("Comment.api").toggle.linewise.current() + end, + "toggle comment", + }, + }, + + v = { + ["/"] = { + "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", + "toggle comment", + }, + }, +} + +M.lspconfig = { + plugin = true, + + -- See ` :help vim.lsp.*` for documentation on any of the below functions + + n = { + ["gD"] = { + function() + vim.lsp.buf.declaration() + end, + "lsp declaration", + }, + + ["gd"] = { + function() + vim.lsp.buf.definition() + end, + "lsp definition", + }, + + ["K"] = { + function() + vim.lsp.buf.hover() + end, + "lsp hover", + }, + + ["gi"] = { + function() + vim.lsp.buf.implementation() + end, + "lsp implementation", + }, + + ["ls"] = { + function() + vim.lsp.buf.signature_help() + end, + "lsp signature_help", + }, + + ["D"] = { + function() + vim.lsp.buf.type_definition() + end, + "lsp definition type", + }, + + ["ra"] = { + function() + require("nvchad_ui.renamer").open() + end, + "lsp rename", + }, + + ["ca"] = { + function() + vim.lsp.buf.code_action() + end, + "lsp code_action", + }, + + ["gr"] = { + function() + vim.lsp.buf.references() + end, + "lsp references", + }, + + ["f"] = { + function() + vim.diagnostic.open_float() + end, + "floating diagnostic", + }, + + ["[d"] = { + function() + vim.diagnostic.goto_prev() + end, + "goto prev", + }, + + ["d]"] = { + function() + vim.diagnostic.goto_next() + end, + "goto_next", + }, + + ["q"] = { + function() + vim.diagnostic.setloclist() + end, + "diagnostic setloclist", + }, + + ["fm"] = { + function() + vim.lsp.buf.format { async = true } + end, + "lsp formatting", + }, + + ["wa"] = { + function() + vim.lsp.buf.add_workspace_folder() + end, + "add workspace folder", + }, + + ["wr"] = { + function() + vim.lsp.buf.remove_workspace_folder() + end, + "remove workspace folder", + }, + + ["wl"] = { + function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, + "list workspace folders", + }, + }, +} + +M.nvimtree = { + plugin = true, + + n = { + -- toggle + [""] = { " NvimTreeToggle ", "toggle nvimtree" }, + + -- focus + ["e"] = { " NvimTreeFocus ", "focus nvimtree" }, + }, +} + +M.telescope = { + plugin = true, + + n = { + -- find + ["ff"] = { " Telescope find_files ", "find files" }, + ["fa"] = { " Telescope find_files follow=true no_ignore=true hidden=true ", "find all" }, + ["fw"] = { " Telescope live_grep ", "live grep" }, + ["fb"] = { " Telescope buffers ", "find buffers" }, + ["fh"] = { " Telescope help_tags ", "help page" }, + ["fo"] = { " Telescope oldfiles ", "find oldfiles" }, + ["tk"] = { " Telescope keymaps ", "show keys" }, + + -- git + ["cm"] = { " Telescope git_commits ", "git commits" }, + ["gt"] = { " Telescope git_status ", "git status" }, + + -- pick a hidden term + ["pt"] = { " Telescope terms ", "pick hidden term" }, + + -- theme switcher + ["th"] = { " Telescope themes ", "nvchad themes" }, + }, +} + +M.nvterm = { + plugin = true, + + t = { + -- toggle in terminal mode + [""] = { + function() + require("nvterm.terminal").toggle "float" + end, + "toggle floating term", + }, + + [""] = { + function() + require("nvterm.terminal").toggle "horizontal" + end, + "toggle horizontal term", + }, + + [""] = { + function() + require("nvterm.terminal").toggle "vertical" + end, + "toggle vertical term", + }, + }, + + n = { + -- toggle in normal mode + [""] = { + function() + require("nvterm.terminal").toggle "float" + end, + "toggle floating term", + }, + + [""] = { + function() + require("nvterm.terminal").toggle "horizontal" + end, + "toggle horizontal term", + }, + + [""] = { + function() + require("nvterm.terminal").toggle "vertical" + end, + "toggle vertical term", + }, + + -- new + + ["h"] = { + function() + require("nvterm.terminal").new "horizontal" + end, + "new horizontal term", + }, + + ["v"] = { + function() + require("nvterm.terminal").new "vertical" + end, + "new vertical term", + }, + }, +} + +M.whichkey = { + plugin = true, + + n = { + ["wK"] = { + function() + vim.cmd "WhichKey" + end, + "which-key all keymaps", + }, + ["wk"] = { + function() + local input = vim.fn.input "WhichKey: " + vim.cmd("WhichKey " .. input) + end, + "which-key query lookup", + }, + }, +} + +M.blankline = { + plugin = true, + + n = { + ["cc"] = { + function() + local ok, start = require("indent_blankline.utils").get_current_context( + vim.g.indent_blankline_context_patterns, + vim.g.indent_blankline_use_treesitter_scope + ) + + if ok then + vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start, 0 }) + vim.cmd [[normal! _]] + end + end, + + "Jump to current_context", + }, + }, +} + +M.gitsigns = { + plugin = true, + + n = { + -- Navigation through hunks + ["]c"] = { + function() + if vim.wo.diff then + return "]c" + end + vim.schedule(function() + require("gitsigns").next_hunk() + end) + return "" + end, + "Jump to next hunk", + opts = { expr = true }, + }, + + ["[c"] = { + function() + if vim.wo.diff then + return "[c" + end + vim.schedule(function() + require("gitsigns").prev_hunk() + end) + return "" + end, + "Jump to prev hunk", + opts = { expr = true }, + }, + + -- Actions + ["rh"] = { + function() + require("gitsigns").reset_hunk() + end, + "Reset hunk", + }, + + ["ph"] = { + function() + require("gitsigns").preview_hunk() + end, + "Preview hunk", + }, + + ["gb"] = { + function() + package.loaded.gitsigns.blame_line() + end, + "Blame line", + }, + + ["td"] = { + function() + require("gitsigns").toggle_deleted() + end, + "Toggle deleted", + }, + }, +} + +return M diff --git a/nvchad/core/options.lua b/nvchad/core/options.lua new file mode 100644 index 00000000..49f11916 --- /dev/null +++ b/nvchad/core/options.lua @@ -0,0 +1,95 @@ +local opt = vim.opt +local g = vim.g +local config = require("core.utils").load_config() + +g.nvchad_theme = config.ui.theme +g.toggle_theme_icon = "  " +g.transparency = config.ui.transparency +g.theme_switcher_loaded = false + +opt.laststatus = 3 -- global statusline +opt.showmode = false + +opt.clipboard = "unnamedplus" +opt.cursorline = true + +-- Indenting +opt.expandtab = true +opt.shiftwidth = 2 +opt.smartindent = true +opt.tabstop = 2 +opt.softtabstop = 2 + +opt.fillchars = { eob = " " } +opt.ignorecase = true +opt.smartcase = true +opt.mouse = "a" + +-- Numbers +opt.number = true +opt.numberwidth = 2 +opt.ruler = false + +-- disable nvim intro +opt.shortmess:append "sI" + +opt.signcolumn = "yes" +opt.splitbelow = true +opt.splitright = true +opt.termguicolors = true +opt.timeoutlen = 400 +opt.undofile = true + +-- interval for writing swap file to disk, also used by gitsigns +opt.updatetime = 250 + +-- go to previous/next line with h,l,left arrow and right arrow +-- when cursor reaches end/beginning of line +opt.whichwrap:append "<>[]hl" + +g.mapleader = " " + +-- disable some builtin vim plugins +local default_plugins = { + "2html_plugin", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + "tutor", + "rplugin", + "syntax", + "synmenu", + "optwin", + "compiler", + "bugreport", + "ftplugin", +} + +for _, plugin in pairs(default_plugins) do + g["loaded_" .. plugin] = 1 +end + +local default_providers = { + "node", + "perl", + "python3", + "ruby", +} + +for _, provider in ipairs(default_providers) do + vim.g["loaded_" .. provider .. "_provider"] = 0 +end diff --git a/nvchad/core/utils.lua b/nvchad/core/utils.lua new file mode 100644 index 00000000..b74278bf --- /dev/null +++ b/nvchad/core/utils.lua @@ -0,0 +1,192 @@ +local M = {} +local merge_tb = vim.tbl_deep_extend + +M.load_config = function() + local config = require "core.default_config" + local chadrc_exists, chadrc = pcall(require, "custom.chadrc") + + if chadrc_exists then + -- merge user config if it exists and is a table; otherwise display an error + if type(chadrc) == "table" then + config.mappings = M.remove_disabled_keys(chadrc.mappings, config.mappings) + config = merge_tb("force", config, chadrc) or {} + else + error "chadrc must return a table!" + end + end + + config.mappings.disabled = nil + return config +end + +M.remove_disabled_keys = function(chadrc_mappings, default_mappings) + if not chadrc_mappings then + return default_mappings + end + + -- store keys in a array with true value to compare + local keys_to_disable = {} + for _, mappings in pairs(chadrc_mappings) do + for mode, section_keys in pairs(mappings) do + if not keys_to_disable[mode] then + keys_to_disable[mode] = {} + end + section_keys = (type(section_keys) == "table" and section_keys) or {} + for k, _ in pairs(section_keys) do + keys_to_disable[mode][k] = true + end + end + end + + -- make a copy as we need to modify default_mappings + for section_name, section_mappings in pairs(default_mappings) do + for mode, mode_mappings in pairs(section_mappings) do + mode_mappings = (type(mode_mappings) == "table" and mode_mappings) or {} + for k, _ in pairs(mode_mappings) do + -- if key if found then remove from default_mappings + if keys_to_disable[mode] and keys_to_disable[mode][k] then + default_mappings[section_name][mode][k] = nil + end + end + end + end + + return default_mappings +end + +M.load_mappings = function(section, mapping_opt) + local function set_section_map(section_values) + if section_values.plugin then + return + end + section_values.plugin = nil + + for mode, mode_values in pairs(section_values) do + local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {}) + for keybind, mapping_info in pairs(mode_values) do + -- merge default + user opts + local opts = merge_tb("force", default_opts, mapping_info.opts or {}) + + mapping_info.opts, opts.mode = nil, nil + opts.desc = mapping_info[2] + + vim.keymap.set(mode, keybind, mapping_info[1], opts) + end + end + end + + local mappings = require("core.utils").load_config().mappings + + if type(section) == "string" then + mappings[section]["plugin"] = nil + mappings = { mappings[section] } + end + + for _, sect in pairs(mappings) do + set_section_map(sect) + end +end + +-- merge default/user plugin tables +M.merge_plugins = function(plugins) + local plugin_configs = M.load_config().plugins + local user_plugins = plugin_configs + + -- old plugin syntax for adding plugins + if plugin_configs.user and type(plugin_configs.user) == "table" then + user_plugins = plugin_configs.user + end + + -- support old plugin removal syntax + local remove_plugins = plugin_configs.remove + if type(remove_plugins) == "table" then + for _, v in ipairs(remove_plugins) do + plugins[v] = nil + end + end + + plugins = merge_tb("force", plugins, user_plugins) + + local final_table = {} + + for key, val in pairs(plugins) do + if val and type(val) == "table" then + plugins[key] = val.rm_default_opts and user_plugins[key] or plugins[key] + plugins[key][1] = key + final_table[#final_table + 1] = plugins[key] + end + end + + return final_table +end + +-- override plugin options table with custom ones +M.load_override = function(options_table, name) + local plugin_configs, plugin_options = M.load_config().plugins, nil + + -- support old plugin syntax for override + local user_override = plugin_configs.override and plugin_configs.override[name] + if user_override and type(user_override) == "table" then + plugin_options = user_override + end + + -- if no old style plugin override is found, then use the new syntax + if not plugin_options and plugin_configs[name] then + local override_options = plugin_configs[name].override_options or {} + if type(override_options) == "table" then + plugin_options = override_options + elseif type(override_options) == "function" then + plugin_options = override_options() + end + end + + -- make sure the plugin options are a table + plugin_options = type(plugin_options) == "table" and plugin_options or {} + + return merge_tb("force", options_table, plugin_options) +end + +M.packer_sync = function(...) + local git_exists, git = pcall(require, "nvchad.utils.git") + local defaults_exists, defaults = pcall(require, "nvchad.utils.config") + local packer_exists, packer = pcall(require, "packer") + + if git_exists and defaults_exists then + local current_branch_name = git.get_current_branch_name() + + -- warn the user if we are on a snapshot branch + if current_branch_name:match(defaults.snaps.base_snap_branch_name .. "(.+)" .. "$") then + vim.api.nvim_echo({ + { "WARNING: You are trying to use ", "WarningMsg" }, + { "PackerSync" }, + { + " on a NvChadSnapshot. This will cause issues if NvChad dependencies contain " + .. "any breaking changes! Plugin updates will not be included in this " + .. "snapshot, so they will be lost after switching between snapshots! Would " + .. "you still like to continue? [y/N]\n", + "WarningMsg", + }, + }, false, {}) + + local ans = vim.trim(string.lower(vim.fn.input "-> ")) + + if ans ~= "y" then + return + end + end + end + + if packer_exists then + packer.sync(...) + + local plugins = M.load_config().plugins + local old_style_options = plugins.user or plugins.override or plugins.remove + if old_style_options then + vim.notify_once("NvChad: This plugin syntax is deprecated, use new style config.", "Error") + end + else + error "Packer could not be loaded!" + end +end + +return M diff --git a/nvchad/chadrc.lua b/nvchad/custom/chadrc.lua similarity index 99% rename from nvchad/chadrc.lua rename to nvchad/custom/chadrc.lua index bd5faed9..8f1e7d41 100644 --- a/nvchad/chadrc.lua +++ b/nvchad/custom/chadrc.lua @@ -22,7 +22,7 @@ M.plugins = { autotag = { enable = true, } - } + }, }, options = { lspconfig = { @@ -48,4 +48,5 @@ vim.cmd('autocmd BufRead,BufEnter *.astro set filetype=astro') vim.cmd('set rnu') vim.cmd('autocmd InsertLeave *.tex update') + return M diff --git a/nvchad/mappings.lua b/nvchad/custom/mappings.lua similarity index 69% rename from nvchad/mappings.lua rename to nvchad/custom/mappings.lua index 676bf1cd..1545375e 100644 --- a/nvchad/mappings.lua +++ b/nvchad/custom/mappings.lua @@ -27,6 +27,12 @@ M.custom = { n = { ["nt"] = {" tabnew ", "New tab"}, ["ct"] = {" tabclose ", "Close tab"}, + ["rf"] = {":lua require('refactoring').select_refactor()", "options"}, + ["q"] = {":lua require('harpoon.mark').add_file()"}, + ["fm"] = {":lua require('harpoon.ui').toggle_quick_menu()"}, + }, + v = { + ["rf"] = {":lua require('refactoring').select_refactor()", "options"}, } } diff --git a/nvchad/override.lua b/nvchad/custom/override.lua similarity index 100% rename from nvchad/override.lua rename to nvchad/custom/override.lua diff --git a/nvchad/custom/plugins/init.lua b/nvchad/custom/plugins/init.lua new file mode 100644 index 00000000..2dd5cb99 --- /dev/null +++ b/nvchad/custom/plugins/init.lua @@ -0,0 +1,26 @@ +return { + ["wakatime/vim-wakatime"] = {}, + ["sbdchd/neoformat"] = {}, + ["williamboman/mason-lspconfig.nvim"] = {}, + ["neovim/nvim-lspconfig"] = { + config = function () + require "plugins.configs.lspconfig" + require "custom.plugins.lspconfig" + end + }, + ["windwp/nvim-ts-autotag"] = { + ft = { "html", "javascriptreact", "typescriptreact", "astro"}, + after = "nvim-treesitter", + config = function() + local present, autotag = pcall(require, "nvim-ts-autotag") + + if present then + autotag.setup() + end + end + }, + ["lervag/vimtex"] = {}, + ["sindrets/diffview.nvim"] = {}, + ["ThePrimeagen/refactoring.nvim"] = {}, + ["ThePrimeagen/harpoon"] = {}, +} diff --git a/nvchad/custom/plugins/lspconfig.lua b/nvchad/custom/plugins/lspconfig.lua new file mode 100644 index 00000000..f57b385f --- /dev/null +++ b/nvchad/custom/plugins/lspconfig.lua @@ -0,0 +1,24 @@ +local on_attach = require("plugins.configs.lspconfig").on_attach +local capabilities = require("plugins.configs.lspconfig").capabilities + +local lspconfig = require("lspconfig") +local servers = {"tailwindcss", "eslint", "cssls", "prismals", "gopls", "dockerls", "yamlls", "hls"} + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup({ + on_attach = on_attach, + capabilities = capabilities, + }) +end + +lspconfig.denols.setup { + on_attach = on_attach, + root_dir = lspconfig.util.root_pattern("deno.json", "deno.jsonc"), +} + +lspconfig.tsserver.setup { + on_attach = on_attach, + root_dir = lspconfig.util.root_pattern("package.json"), + single_file_support = false, + enable = false, +} diff --git a/nvchad/plugins/configs/alpha.lua b/nvchad/plugins/configs/alpha.lua new file mode 100644 index 00000000..6ddb0c21 --- /dev/null +++ b/nvchad/plugins/configs/alpha.lua @@ -0,0 +1,94 @@ +local present, alpha = pcall(require, "alpha") + +if not present then + return +end + +require("base46").load_highlight "alpha" + +local function button(sc, txt, keybind) + local sc_ = sc:gsub("%s", ""):gsub("SPC", "") + + local opts = { + position = "center", + text = txt, + shortcut = sc, + cursor = 5, + width = 36, + align_shortcut = "right", + hl = "AlphaButtons", + } + + if keybind then + opts.keymap = { "n", sc_, keybind, { noremap = true, silent = true } } + end + + return { + type = "button", + val = txt, + on_press = function() + local key = vim.api.nvim_replace_termcodes(sc_, true, false, true) or "" + vim.api.nvim_feedkeys(key, "normal", false) + end, + opts = opts, + } +end + +-- dynamic header padding +local fn = vim.fn +local marginTopPercent = 0.3 +local headerPadding = fn.max { 2, fn.floor(fn.winheight(0) * marginTopPercent) } + +local options = { + + header = { + type = "text", + val = { + " ⣴⣶⣤⡤⠦⣤⣀⣤⠆ ⣈⣭⣿⣶⣿⣦⣼⣆ ", + " ⠉⠻⢿⣿⠿⣿⣿⣶⣦⠤⠄⡠⢾⣿⣿⡿⠋⠉⠉⠻⣿⣿⡛⣦ ", + " ⠈⢿⣿⣟⠦ ⣾⣿⣿⣷ ⠻⠿⢿⣿⣧⣄ ", + " ⣸⣿⣿⢧ ⢻⠻⣿⣿⣷⣄⣀⠄⠢⣀⡀⠈⠙⠿⠄ ", + " ⢠⣿⣿⣿⠈ ⣻⣿⣿⣿⣿⣿⣿⣿⣛⣳⣤⣀⣀ ", + " ⢠⣧⣶⣥⡤⢄ ⣸⣿⣿⠘ ⢀⣴⣿⣿⡿⠛⣿⣿⣧⠈⢿⠿⠟⠛⠻⠿⠄ ", + " ⣰⣿⣿⠛⠻⣿⣿⡦⢹⣿⣷ ⢊⣿⣿⡏ ⢸⣿⣿⡇ ⢀⣠⣄⣾⠄ ", + " ⣠⣿⠿⠛ ⢀⣿⣿⣷⠘⢿⣿⣦⡀ ⢸⢿⣿⣿⣄ ⣸⣿⣿⡇⣪⣿⡿⠿⣿⣷⡄ ", + " ⠙⠃ ⣼⣿⡟ ⠈⠻⣿⣿⣦⣌⡇⠻⣿⣿⣷⣿⣿⣿ ⣿⣿⡇ ⠛⠻⢷⣄ ", + " ⢻⣿⣿⣄ ⠈⠻⣿⣿⣿⣷⣿⣿⣿⣿⣿⡟ ⠫⢿⣿⡆ ", + " ⠻⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣀⣤⣾⡿⠃ ", + }, + opts = { + position = "center", + hl = "AlphaHeader", + }, + }, + + buttons = { + type = "group", + val = { + button("SPC f f", " Find File ", ":Telescope find_files"), + button("SPC f o", " Recent File ", ":Telescope oldfiles"), + button("SPC f w", " Find Word ", ":Telescope live_grep"), + button("SPC b m", " Bookmarks ", ":Telescope marks"), + button("SPC t h", " Themes ", ":Telescope themes"), + button("SPC e s", " Settings", ":e $MYVIMRC | :cd %:p:h "), + }, + opts = { + spacing = 1, + }, + }, + + headerPaddingTop = { type = "padding", val = headerPadding }, + headerPaddingBottom = { type = "padding", val = 2 }, +} + +options = require("core.utils").load_override(options, "goolord/alpha-nvim") + +alpha.setup { + layout = { + options.headerPaddingTop, + options.header, + options.headerPaddingBottom, + options.buttons, + }, + opts = {}, +} diff --git a/nvchad/plugins/configs/cmp.lua b/nvchad/plugins/configs/cmp.lua new file mode 100644 index 00000000..07795791 --- /dev/null +++ b/nvchad/plugins/configs/cmp.lua @@ -0,0 +1,103 @@ +local present, cmp = pcall(require, "cmp") + +if not present then + return +end + +require("base46").load_highlight "cmp" + +vim.o.completeopt = "menu,menuone,noselect" + +local function border(hl_name) + return { + { "╭", hl_name }, + { "─", hl_name }, + { "╮", hl_name }, + { "│", hl_name }, + { "╯", hl_name }, + { "─", hl_name }, + { "╰", hl_name }, + { "│", hl_name }, + } +end + +local cmp_window = require "cmp.utils.window" + +cmp_window.info_ = cmp_window.info +cmp_window.info = function(self) + local info = self:info_() + info.scrollable = false + return info +end + +local options = { + window = { + completion = { + border = border "CmpBorder", + winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", + }, + documentation = { + border = border "CmpDocBorder", + }, + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + formatting = { + format = function(_, vim_item) + local icons = require("nvchad_ui.icons").lspkind + vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) + return vim_item + end, + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-expand-or-jump", true, true, true), "") + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-jump-prev", true, true, true), "") + else + fallback() + end + end, { + "i", + "s", + }), + }, + sources = { + { name = "luasnip" }, + { name = "nvim_lsp" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "path" }, + }, +} + +-- check for any override +options = require("core.utils").load_override(options, "hrsh7th/nvim-cmp") + +cmp.setup(options) diff --git a/nvchad/plugins/configs/lspconfig.lua b/nvchad/plugins/configs/lspconfig.lua new file mode 100644 index 00000000..c6006966 --- /dev/null +++ b/nvchad/plugins/configs/lspconfig.lua @@ -0,0 +1,46 @@ +local present, lspconfig = pcall(require, "lspconfig") + +if not present then + return +end + +require("base46").load_highlight "lsp" +require "nvchad_ui.lsp" + +local M = {} +local utils = require "core.utils" + +-- export on_attach & capabilities for custom lspconfigs + +M.on_attach = function(client, bufnr) + client.server_capabilities.documentFormattingProvider = false + client.server_capabilities.documentRangeFormattingProvider = false + + utils.load_mappings("lspconfig", { buffer = bufnr }) + + if client.server_capabilities.signatureHelpProvider then + require("nvchad_ui.signature").setup(client) + end +end + +M.capabilities = vim.lsp.protocol.make_client_capabilities() + +M.capabilities.textDocument.completion.completionItem = { + documentationFormat = { "markdown", "plaintext" }, + snippetSupport = true, + preselectSupport = true, + insertReplaceSupport = true, + labelDetailsSupport = true, + deprecatedSupport = true, + commitCharactersSupport = true, + tagSupport = { valueSet = { 1 } }, + resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, + }, +} + +return M diff --git a/nvchad/plugins/configs/mason.lua b/nvchad/plugins/configs/mason.lua new file mode 100644 index 00000000..c713847d --- /dev/null +++ b/nvchad/plugins/configs/mason.lua @@ -0,0 +1,49 @@ +local present, mason = pcall(require, "mason") + +if not present then + return +end + +vim.api.nvim_create_augroup("_mason", { clear = true }) +vim.api.nvim_create_autocmd("Filetype", { + pattern = "mason", + callback = function() + require("base46").load_highlight "mason" + end, + group = "_mason", +}) + +local options = { + ensure_installed = { "lua-language-server" }, -- not an option from mason.nvim + + PATH = "skip", + + ui = { + icons = { + package_pending = " ", + package_installed = " ", + package_uninstalled = " ﮊ", + }, + + keymaps = { + toggle_server_expand = "", + install_server = "i", + update_server = "u", + check_server_version = "c", + update_all_servers = "U", + check_outdated_servers = "C", + uninstall_server = "X", + cancel_installation = "", + }, + }, + + max_concurrent_installers = 10, +} + +options = require("core.utils").load_override(options, "williamboman/mason.nvim") + +vim.api.nvim_create_user_command("MasonInstallAll", function() + vim.cmd("MasonInstall " .. table.concat(options.ensure_installed, " ")) +end, {}) + +mason.setup(options) diff --git a/nvchad/plugins/configs/nvimtree.lua b/nvchad/plugins/configs/nvimtree.lua new file mode 100644 index 00000000..4279d235 --- /dev/null +++ b/nvchad/plugins/configs/nvimtree.lua @@ -0,0 +1,88 @@ +local present, nvimtree = pcall(require, "nvim-tree") + +if not present then + return +end + +require("base46").load_highlight "nvimtree" + +local options = { + filters = { + dotfiles = false, + exclude = { vim.fn.stdpath "config" .. "/lua/custom" }, + }, + disable_netrw = true, + hijack_netrw = true, + hijack_cursor = true, + hijack_unnamed_buffer_when_opening = false, + update_cwd = true, + update_focused_file = { + enable = true, + update_cwd = false, + }, + view = { + adaptive_size = true, + side = "left", + width = 25, + hide_root_folder = true, + }, + git = { + enable = false, + ignore = true, + }, + filesystem_watchers = { + enable = true, + }, + actions = { + open_file = { + resize_window = true, + }, + }, + renderer = { + highlight_git = false, + highlight_opened_files = "none", + + indent_markers = { + enable = false, + }, + + icons = { + show = { + file = true, + folder = true, + folder_arrow = true, + git = false, + }, + + glyphs = { + default = "", + symlink = "", + folder = { + default = "", + empty = "", + empty_open = "", + open = "", + symlink = "", + symlink_open = "", + arrow_open = "", + arrow_closed = "", + }, + git = { + unstaged = "✗", + staged = "✓", + unmerged = "", + renamed = "➜", + untracked = "★", + deleted = "", + ignored = "◌", + }, + }, + }, + }, +} + +-- check for any override +options = require("core.utils").load_override(options, "nvim-tree/nvim-tree.lua") +vim.g.nvimtree_side = options.view.side + +nvimtree.setup(options) diff --git a/nvchad/plugins/configs/nvterm.lua b/nvchad/plugins/configs/nvterm.lua new file mode 100644 index 00000000..2c82e14c --- /dev/null +++ b/nvchad/plugins/configs/nvterm.lua @@ -0,0 +1,34 @@ +local present, nvterm = pcall(require, "nvterm") + +if not present then + return +end + +require "base46.term" + +local options = { + terminals = { + list = {}, + type_opts = { + float = { + relative = "editor", + row = 0.3, + col = 0.25, + width = 0.5, + height = 0.4, + border = "single", + }, + horizontal = { location = "rightbelow", split_ratio = 0.3 }, + vertical = { location = "rightbelow", split_ratio = 0.5 }, + }, + }, + behavior = { + close_on_exit = true, + auto_insert = true, + }, + enable_new_mappings = true, +} + +options = require("core.utils").load_override(options, "NvChad/nvterm") + +nvterm.setup(options) diff --git a/nvchad/plugins/configs/others.lua b/nvchad/plugins/configs/others.lua new file mode 100644 index 00000000..59a10dd2 --- /dev/null +++ b/nvchad/plugins/configs/others.lua @@ -0,0 +1,189 @@ +local M = {} + +local load_override = require("core.utils").load_override +local utils = require "core.utils" + +M.autopairs = function() + local present1, autopairs = pcall(require, "nvim-autopairs") + local present2, cmp = pcall(require, "cmp") + + if not (present1 and present2) then + return + end + + local options = { + fast_wrap = {}, + disable_filetype = { "TelescopePrompt", "vim" }, + } + + options = load_override(options, "windwp/nvim-autopairs") + autopairs.setup(options) + + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) +end + +M.blankline = function() + local present, blankline = pcall(require, "indent_blankline") + + if not present then + return + end + + require("base46").load_highlight "blankline" + + local options = { + indentLine_enabled = 1, + filetype_exclude = { + "help", + "terminal", + "alpha", + "packer", + "lspinfo", + "TelescopePrompt", + "TelescopeResults", + "mason", + "", + }, + buftype_exclude = { "terminal" }, + show_trailing_blankline_indent = false, + show_first_indent_level = false, + show_current_context = true, + show_current_context_start = true, + } + + options = load_override(options, "lukas-reineke/indent-blankline.nvim") + blankline.setup(options) +end + +M.colorizer = function() + local present, colorizer = pcall(require, "colorizer") + + if not present then + return + end + + local options = { + filetypes = { + "*", + }, + user_default_options = { + RGB = true, -- #RGB hex codes + RRGGBB = true, -- #RRGGBB hex codes + names = false, -- "Name" codes like Blue + RRGGBBAA = false, -- #RRGGBBAA hex codes + rgb_fn = false, -- CSS rgb() and rgba() functions + hsl_fn = false, -- CSS hsl() and hsla() functions + css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB + css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn + mode = "background", -- Set the display mode. + }, + } + + options = load_override(options, "NvChad/nvim-colorizer.lua") + colorizer.setup(options) + -- execute colorizer as soon as possible + vim.defer_fn(function() + require("colorizer").attach_to_buffer(0) + end, 0) +end + +M.comment = function() + local present, nvim_comment = pcall(require, "Comment") + + if not present then + return + end + + local options = {} + options = load_override(options, "numToStr/Comment.nvim") + nvim_comment.setup(options) +end + +M.luasnip = function() + local present, luasnip = pcall(require, "luasnip") + + if not present then + return + end + + local options = { + history = true, + updateevents = "TextChanged,TextChangedI", + } + + options = load_override(options, "L3MON4D3/LuaSnip") + luasnip.config.set_config(options) + require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.luasnippets_path or "" } + require("luasnip.loaders.from_vscode").lazy_load() + + vim.api.nvim_create_autocmd("InsertLeave", { + callback = function() + if + require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, + }) +end + +M.gitsigns = function() + local present, gitsigns = pcall(require, "gitsigns") + + if not present then + return + end + + require("base46").load_highlight "git" + + local options = { + signs = { + add = { hl = "DiffAdd", text = "│", numhl = "GitSignsAddNr" }, + change = { hl = "DiffChange", text = "│", numhl = "GitSignsChangeNr" }, + delete = { hl = "DiffDelete", text = "", numhl = "GitSignsDeleteNr" }, + topdelete = { hl = "DiffDelete", text = "‾", numhl = "GitSignsDeleteNr" }, + changedelete = { hl = "DiffChangeDelete", text = "~", numhl = "GitSignsChangeNr" }, + }, + on_attach = function (bufnr) + utils.load_mappings("gitsigns", { buffer = bufnr }) + end + } + + options = load_override(options, "lewis6991/gitsigns.nvim") + gitsigns.setup(options) +end + +M.devicons = function() + local present, devicons = pcall(require, "nvim-web-devicons") + + if present then + require("base46").load_highlight "devicons" + + local options = { override = require("nvchad_ui.icons").devicons } + options = require("core.utils").load_override(options, "nvim-tree/nvim-web-devicons") + + devicons.setup(options) + end +end + +M.packer_init = function() + return { + auto_clean = true, + compile_on_sync = true, + git = { clone_timeout = 6000 }, + display = { + working_sym = "ﲊ", + error_sym = "✗ ", + done_sym = " ", + removed_sym = " ", + moved_sym = "", + open_fn = function() + return require("packer.util").float { border = "single" } + end, + }, + } +end + +return M diff --git a/nvchad/plugins/configs/telescope.lua b/nvchad/plugins/configs/telescope.lua new file mode 100644 index 00000000..5b4b1024 --- /dev/null +++ b/nvchad/plugins/configs/telescope.lua @@ -0,0 +1,74 @@ +local present, telescope = pcall(require, "telescope") + +if not present then + return +end + +vim.g.theme_switcher_loaded = true + +require("base46").load_highlight "telescope" + +local options = { + defaults = { + vimgrep_arguments = { + "rg", + "-L", + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + }, + prompt_prefix = "  ", + selection_caret = " ", + entry_prefix = " ", + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = "ascending", + layout_strategy = "horizontal", + layout_config = { + horizontal = { + prompt_position = "top", + preview_width = 0.55, + results_width = 0.8, + }, + vertical = { + mirror = false, + }, + width = 0.87, + height = 0.80, + preview_cutoff = 120, + }, + file_sorter = require("telescope.sorters").get_fuzzy_file, + file_ignore_patterns = { "node_modules" }, + generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, + path_display = { "truncate" }, + winblend = 0, + border = {}, + borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + color_devicons = true, + set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + -- Developer configurations: Not meant for general override + buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker, + mappings = { + n = { ["q"] = require("telescope.actions").close }, + }, + }, + + extensions_list = { "themes", "terms", "harpoon" }, +} + +-- check for any override +options = require("core.utils").load_override(options, "nvim-telescope/telescope.nvim") +telescope.setup(options) + +-- load extensions +pcall(function() + for _, ext in ipairs(options.extensions_list) do + telescope.load_extension(ext) + end +end) diff --git a/nvchad/plugins/configs/treesitter.lua b/nvchad/plugins/configs/treesitter.lua new file mode 100644 index 00000000..bb1b163a --- /dev/null +++ b/nvchad/plugins/configs/treesitter.lua @@ -0,0 +1,27 @@ +local present, treesitter = pcall(require, "nvim-treesitter.configs") + +if not present then + return +end + +require("base46").load_highlight "treesitter" + +local options = { + ensure_installed = { + "lua", + }, + + highlight = { + enable = true, + use_languagetree = true, + }, + + indent = { + enable = true, + }, +} + +-- check for any override +options = require("core.utils").load_override(options, "nvim-treesitter/nvim-treesitter") + +treesitter.setup(options) diff --git a/nvchad/plugins/configs/whichkey.lua b/nvchad/plugins/configs/whichkey.lua new file mode 100644 index 00000000..89e7c3e2 --- /dev/null +++ b/nvchad/plugins/configs/whichkey.lua @@ -0,0 +1,41 @@ +local present, wk = pcall(require, "which-key") + +if not present then + return +end + +require("base46").load_highlight "whichkey" + +local options = { + + icons = { + breadcrumb = "»", -- symbol used in the command line area that shows your active key combo + separator = "  ", -- symbol used between a key and it's label + group = "+", -- symbol prepended to a group + }, + + popup_mappings = { + scroll_down = "", -- binding to scroll down inside the popup + scroll_up = "", -- binding to scroll up inside the popup + }, + + window = { + border = "none", -- none/single/double/shadow + }, + + layout = { + spacing = 6, -- spacing between columns + }, + + hidden = { "", "", "", "", "call", "lua", "^:", "^ " }, + + triggers_blacklist = { + -- list of mode / prefixes that should never be hooked by WhichKey + i = { "j", "k" }, + v = { "j", "k" }, + }, +} + +options = require("core.utils").load_override(options, "folke/which-key.nvim") + +wk.setup(options) diff --git a/nvchad/plugins/init.lua b/nvchad/plugins/init.lua index a71996bc..079b7bcc 100644 --- a/nvchad/plugins/init.lua +++ b/nvchad/plugins/init.lua @@ -1,24 +1,223 @@ -return { - ["wakatime/vim-wakatime"] = {}, - ["sbdchd/neoformat"] = {}, - ["williamboman/mason-lspconfig.nvim"] = {}, - ["neovim/nvim-lspconfig"] = { - config = function () - require "plugins.configs.lspconfig" - require "custom.plugins.lspconfig" - end - }, - ["windwp/nvim-ts-autotag"] = { - ft = { "html", "javascriptreact", "typescriptreact", "astro"}, - after = "nvim-treesitter", +local plugins = { + + ["nvim-lua/plenary.nvim"] = { module = "plenary" }, + + ["lewis6991/impatient.nvim"] = {}, + + ["wbthomason/packer.nvim"] = { + cmd = require("core.lazy_load").packer_cmds, config = function() - local present, autotag = pcall(require, "nvim-ts-autotag") + require "plugins" + end, + }, + + ["NvChad/extensions"] = { module = { "telescope", "nvchad" } }, + + ["NvChad/base46"] = { + config = function() + local ok, base46 = pcall(require, "base46") + + if ok then + base46.load_theme() + end + end, + }, + + ["NvChad/ui"] = { + after = "base46", + config = function() + local present, nvchad_ui = pcall(require, "nvchad_ui") if present then - autotag.setup() + nvchad_ui.setup() end - end + end, + }, + + ["NvChad/nvterm"] = { + module = "nvterm", + config = function() + require "plugins.configs.nvterm" + end, + setup = function() + require("core.utils").load_mappings "nvterm" + end, + }, + + ["nvim-tree/nvim-web-devicons"] = { + after = "ui", + module = "nvim-web-devicons", + config = function() + require("plugins.configs.others").devicons() + end, + }, + + ["lukas-reineke/indent-blankline.nvim"] = { + opt = true, + setup = function() + require("core.lazy_load").on_file_open "indent-blankline.nvim" + require("core.utils").load_mappings "blankline" + end, + config = function() + require("plugins.configs.others").blankline() + end, + }, + + ["NvChad/nvim-colorizer.lua"] = { + opt = true, + setup = function() + require("core.lazy_load").on_file_open "nvim-colorizer.lua" + end, + config = function() + require("plugins.configs.others").colorizer() + end, + }, + + ["nvim-treesitter/nvim-treesitter"] = { + module = "nvim-treesitter", + setup = function() + require("core.lazy_load").on_file_open "nvim-treesitter" + end, + cmd = require("core.lazy_load").treesitter_cmds, + run = ":TSUpdate", + config = function() + require "plugins.configs.treesitter" + end, + }, + + -- git stuff + ["lewis6991/gitsigns.nvim"] = { + ft = "gitcommit", + setup = function() + require("core.lazy_load").gitsigns() + end, + config = function() + require("plugins.configs.others").gitsigns() + end, + }, + + -- lsp stuff + ["williamboman/mason.nvim"] = { + cmd = require("core.lazy_load").mason_cmds, + config = function() + require "plugins.configs.mason" + end, + }, + + ["neovim/nvim-lspconfig"] = { + opt = true, + setup = function() + require("core.lazy_load").on_file_open "nvim-lspconfig" + end, + config = function() + require "plugins.configs.lspconfig" + end, + }, + + -- load luasnips + cmp related in insert mode only + + ["rafamadriz/friendly-snippets"] = { + module = { "cmp", "cmp_nvim_lsp" }, + event = "InsertEnter", + }, + + ["hrsh7th/nvim-cmp"] = { + after = "friendly-snippets", + config = function() + require "plugins.configs.cmp" + end, + }, + + ["L3MON4D3/LuaSnip"] = { + wants = "friendly-snippets", + after = "nvim-cmp", + config = function() + require("plugins.configs.others").luasnip() + end, + }, + + ["saadparwaiz1/cmp_luasnip"] = { after = "LuaSnip" }, + ["hrsh7th/cmp-nvim-lua"] = { after = "cmp_luasnip" }, + ["hrsh7th/cmp-nvim-lsp"] = { after = "cmp-nvim-lua" }, + ["hrsh7th/cmp-buffer"] = { after = "cmp-nvim-lsp" }, + ["hrsh7th/cmp-path"] = { after = "cmp-buffer" }, + + -- misc plugins + ["windwp/nvim-autopairs"] = { + after = "nvim-cmp", + config = function() + require("plugins.configs.others").autopairs() + end, + }, + + ["goolord/alpha-nvim"] = { + after = "base46", + disable = true, + config = function() + require "plugins.configs.alpha" + end, + }, + + ["numToStr/Comment.nvim"] = { + module = "Comment", + keys = { "gc", "gb" }, + config = function() + require("plugins.configs.others").comment() + end, + setup = function() + require("core.utils").load_mappings "comment" + end, + }, + + -- file managing , picker etc + ["nvim-tree/nvim-tree.lua"] = { + ft = "alpha", + cmd = { "NvimTreeToggle", "NvimTreeFocus" }, + config = function() + require "plugins.configs.nvimtree" + end, + setup = function() + require("core.utils").load_mappings "nvimtree" + end, + }, + + ["nvim-telescope/telescope.nvim"] = { + cmd = "Telescope", + config = function() + require "plugins.configs.telescope" + end, + setup = function() + require("core.utils").load_mappings "telescope" + end, + }, + + -- Only load whichkey after all the gui + ["folke/which-key.nvim"] = { + disable = true, + module = "which-key", + keys = { "", '"', "'", "`" }, + config = function() + require "plugins.configs.whichkey" + end, + setup = function() + require("core.utils").load_mappings "whichkey" + end, }, - ["lervag/vimtex"] = {}, - ["sindrets/diffview.nvim"] = {}, } + +-- Load all plugins +local present, packer = pcall(require, "packer") + +if present then + vim.cmd "packadd packer.nvim" + + -- Override with default plugins with user ones + plugins = require("core.utils").merge_plugins(plugins) + + -- load packer init options + local init_options = require("plugins.configs.others").packer_init() + init_options = require("core.utils").load_override(init_options, "wbthomason/packer.nvim") + + packer.init(init_options) + packer.startup { plugins } +end diff --git a/nvchad/plugins/lspconfig.lua b/nvchad/plugins/lspconfig.lua deleted file mode 100644 index 25aafed1..00000000 --- a/nvchad/plugins/lspconfig.lua +++ /dev/null @@ -1,12 +0,0 @@ -local on_attach = require("plugins.configs.lspconfig").on_attach -local capabilities = require("plugins.configs.lspconfig").capabilities - -local lspconfig = require("lspconfig") -local servers = {"tsserver", "tailwindcss", "eslint", "cssls", "prismals", "gopls", "dockerls", "yamlls", "hls" } - -for _, lsp in ipairs(servers) do - lspconfig[lsp].setup({ - on_attach = on_attach, - capabilities = capabilities, - }) -end