From adecbe719f14e852346dbf672d50776e4789355b Mon Sep 17 00:00:00 2001 From: siduck Date: Wed, 27 Apr 2022 21:12:28 +0530 Subject: [PATCH] BREAKING CHANGE | re-implementation of custom config --- examples/init.lua | 6 +- init.lua | 8 +- lua/colors/highlights.lua | 25 +-- lua/core/autocmds.lua | 11 - lua/core/default_config.lua | 250 +-------------------- lua/core/mappings.lua | 335 ++++++++++++++--------------- lua/core/options.lua | 80 ++++--- lua/core/utils.lua | 289 +++++-------------------- lua/plugins/configs/alpha.lua | 37 ++-- lua/plugins/configs/bufferline.lua | 94 ++++---- lua/plugins/configs/cmp.lua | 23 +- lua/plugins/configs/icons.lua | 74 +++---- lua/plugins/configs/lspconfig.lua | 1 + lua/plugins/configs/nvimtree.lua | 34 ++- lua/plugins/configs/nvterm.lua | 43 ++++ lua/plugins/configs/others.lua | 234 ++++++++++---------- lua/plugins/configs/statusline.lua | 321 ++++++++++++--------------- lua/plugins/configs/telescope.lua | 30 ++- lua/plugins/configs/treesitter.lua | 15 +- lua/plugins/init.lua | 234 ++++++++++---------- 20 files changed, 835 insertions(+), 1309 deletions(-) create mode 100644 lua/plugins/configs/nvterm.lua diff --git a/examples/init.lua b/examples/init.lua index a6b3d5c..721f625 100644 --- a/examples/init.lua +++ b/examples/init.lua @@ -1,6 +1,4 @@ --- Please check NvChad docs if you're totally new to nvchad + dont know lua!! --- This is an example init file in /lua/custom/ --- this init.lua can load stuffs etc too so treat it like your ~/.config/nvim/ +-- example file i.e lua/custom/init.lua -- MAPPINGS local map = require("core.utils").map @@ -8,4 +6,4 @@ local map = require("core.utils").map map("n", "cc", ":Telescope ") map("n", "q", ":q ") --- NOTE: the 4th argument in the map function is be a table i.e options but its most likely un-needed so dont worry about it +-- require("my autocmds file") or just declare them here diff --git a/init.lua b/init.lua index 425185d..96afe05 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,3 @@ --- REMOVE THIS LATER -print("EMERGENCY: GUYS CHECK THE PINNED ISSUE ASAP!") - local present, impatient = pcall(require, "impatient") if present then @@ -20,15 +17,14 @@ for _, module in ipairs(core_modules) do end end --- non plugin mappings -require("core.mappings").misc() - -- check if custom init.lua file exists if vim.fn.filereadable(vim.fn.stdpath "config" .. "/lua/custom/init.lua") == 1 then -- try to call custom init, if not successful, show error local ok, err = pcall(require, "custom") + if not ok then vim.notify("Error loading custom/init.lua\n\n" .. err) end + return end diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index d9f2616..c97c64f 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -30,11 +30,7 @@ local fg_bg = require("core.utils").fg_bg local bg = require("core.utils").bg -- Comments -if ui.italic_comments then - fg("Comment", grey_fg .. " gui=italic") -else - fg("Comment", grey_fg) -end +fg("Comment", grey_fg) -- Disable cursor line cmd "hi clear CursorLine" @@ -128,25 +124,6 @@ fg_bg("TelescopeResultsTitle", darker_black, darker_black) bg("TelescopeSelection", black2) --- keybinds cheatsheet - -fg_bg("CheatsheetBorder", black, black) -bg("CheatsheetSectionContent", black) -fg("CheatsheetHeading", white) - -local section_title_colors = { - white, - blue, - red, - green, - yellow, - purple, - orange, -} -for i, color in ipairs(section_title_colors) do - vim.cmd("highlight CheatsheetTitle" .. i .. " guibg = " .. color .. " guifg=" .. black) -end - -- Disable some highlight in nvim tree if transparency enabled if ui.transparency then bg("NormalFloat", "NONE") diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index 7d83b74..b74f61b 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -1,4 +1,3 @@ -local settings=require("core.utils").load_config().options.nvChad -- uncomment this if you want to open nvim with a dir -- vim.cmd [[ autocmd BufEnter * if &buftype != "terminal" | lcd %:p:h | endif ]] @@ -6,16 +5,6 @@ local settings=require("core.utils").load_config().options.nvChad -- vim.cmd[[ au InsertEnter * set norelativenumber ]] -- vim.cmd[[ au InsertLeave * set relativenumber ]] --- Don't show any numbers inside terminals -if not settings.terminal_numbers then - vim.cmd [[ au TermOpen term://* setlocal nonumber norelativenumber | setfiletype terminal ]] -end - --- Don't show status line on certain windows -if not require("core.utils").load_config().plugins.options.statusline.hide_disable then - vim.cmd [[ autocmd BufEnter,BufRead,BufWinEnter,FileType,WinEnter * lua require("core.utils").hide_statusline() ]] -end - -- Open a file from its last left off position -- vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]] -- File extension specific tabbing diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index 4123f4b..6515d83 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -1,279 +1,51 @@ -- IMPORTANT NOTE : This is default config, so dont change anything here. --- use custom/chadrc.lua instead +-- chadrc overrides this file local M = {} M.options = { - -- custom = {} - -- general nvim/vim options , check :h optionname to know more about an option - clipboard = "unnamedplus", - cmdheight = 1, - ruler = false, - hidden = true, - ignorecase = true, - smartcase = true, - mapleader = " ", - mouse = "a", - number = true, - numberwidth = 2, - relativenumber = false, - expandtab = true, - shiftwidth = 2, - smartindent = true, - tabstop = 8, - timeoutlen = 400, - updatetime = 250, - undofile = true, - fillchars = { eob = " " }, - shadafile = vim.opt.shadafile, + path = "", -- path to file that overrides core.options -- NvChad options nvChad = { - copy_cut = true, -- copy cut text ( x key ), visual and normal mode - copy_del = true, -- copy deleted text ( dd key ), visual and normal mode - insert_nav = true, -- navigation in insertmode - window_nav = true, - terminal_numbers = false, - -- updater update_url = "https://github.com/NvChad/NvChad", update_branch = "main", }, - terminal = { - behavior = { - close_on_exit = true, - }, - window = { - vsplit_ratio = 0.5, - split_ratio = 0.4, - }, - location = { - horizontal = "rightbelow", - vertical = "rightbelow", - float = { - relative = 'editor', - row = 0.3, - col = 0.25, - width = 0.5, - height = 0.4, - border = "single", - } - }, - }, } ---- UI ----- M.ui = { - hl_override = "", -- path of your file that contains highlights + hl_override = "", colors = "", -- path of your file that contains colors - italic_comments = false, theme = "onedark", -- default theme - - -- Change terminal bg to nvim theme's bg color so it'll match well - -- For Ex : if you have onedark set in nvchad, set onedark's bg color on your terminal transparency = false, } ----- PLUGIN OPTIONS ---- - M.plugins = { + override = {}, - -- builtin nvim plugins are disabled - builtins = { - "2html_plugin", - "getscript", - "getscriptPlugin", - "gzip", - "logipat", - "netrw", - "netrwPlugin", - "netrwSettings", - "netrwFileHandlers", - "matchit", - "tar", - "tarPlugin", - "rrhelper", - "spellfile_plugin", - "vimball", - "vimballPlugin", - "zip", - "zipPlugin", - }, - - -- enable/disable plugins (false for disable) - status = { - blankline = true, -- indentline stuff - bufferline = true, -- manage and preview opened buffers - colorizer = false, -- color RGB, HEX, CSS, NAME color codes - comment = true, -- easily (un)comment code, language aware - alpha = false, -- dashboard - better_escape = true, -- map to with no lag - feline = true, -- statusline - gitsigns = true, - lspsignature = true, -- lsp enhancements - vim_matchup = true, -- improved matchit - cmp = true, - nvimtree = true, - autopairs = true, - }, options = { packer = { init_file = "plugins.packerInit", }, - autopairs = { loadAfter = "nvim-cmp" }, - cmp = { - lazy_load = true, - }, lspconfig = { - setup_lspconf = "", -- path of file containing setups of different lsps - }, - nvimtree = { - -- packerCompile required after changing lazy_load - lazy_load = true, - }, - luasnip = { - snippet_path = {}, + setup_lspconf = "", -- path of lspconfig file }, statusline = { - hide_disable = false, - -- hide, show on specific filetypes - hidden = { - "help", - "NvimTree", - "terminal", - "alpha", - }, - shown = {}, - - -- truncate statusline on small screens - shortline = true, - style = "default", -- default, round , slant , block , arrow + style = "default", -- default/round/slant/block/arrow }, - esc_insertmode_timeout = 300, }, - default_plugin_config_replace = {}, - default_plugin_remove = {}, - install = nil, + + -- add, modify, remove plugins + user = {}, } --- Don't use a single keymap twice - ---- MAPPINGS ---- - --- non plugin +-- non plugin only M.mappings = { - -- custom = {}, -- custom user mappings - - misc = { - cheatsheet = "ch", - close_buffer = "x", - cp_whole_file = "", -- copy all contents of current buffer - lineNR_toggle = "n", -- toggle line number - lineNR_rel_toggle = "rn", - update_nvchad = "uu", - new_buffer = "", - new_tab = "b", - save_file = "", -- save file using :w - }, - - -- navigation in insert mode, only if enabled in options - - insert_nav = { - backward = "", - end_of_line = "", - forward = "", - next_line = "", - prev_line = "", - beginning_of_line = "", - }, - - -- better window movement - window_nav = { - moveLeft = "", - moveRight = "", - moveUp = "", - moveDown = "", - }, - - -- terminal related mappings - terminal = { - -- multiple mappings can be given for esc_termmode, esc_hide_termmode - - -- get out of terminal mode - esc_termmode = { "jk" }, - - -- get out of terminal mode and hide it - esc_hide_termmode = { "JK" }, - -- show & recover hidden terminal buffers in a telescope picker - pick_term = "W", - - -- spawn a single terminal and toggle it - -- this just works like toggleterm kinda - new_horizontal = "h", - new_vertical = "v", - new_float = "", - - -- spawn new terminals - spawn_horizontal = "", - spawn_vertical = "", - spawn_window = "w", - }, -} - --- plugins related mappings --- To disable a mapping, equate the variable to "" or false or nil in chadrc -M.mappings.plugins = { - bufferline = { - next_buffer = "", - prev_buffer = "", - }, - comment = { - toggle = "/", - }, - - -- map to with no lag - better_escape = { -- will still work - esc_insertmode = { "jk" }, -- multiple mappings allowed - }, - - lspconfig = { - declaration = "gD", - definition = "gd", - hover = "K", - implementation = "gi", - signature_help = "gk", - add_workspace_folder = "wa", - remove_workspace_folder = "wr", - list_workspace_folders = "wl", - type_definition = "D", - rename = "ra", - code_action = "ca", - references = "gr", - float_diagnostics = "ge", - goto_prev = "[d", - goto_next = "]d", - set_loclist = "q", - formatting = "fm", - }, - - nvimtree = { - toggle = "", - focus = "e", - }, - - telescope = { - buffers = "fb", - find_files = "ff", - find_hiddenfiles = "fa", - git_commits = "cm", - git_status = "gt", - help_tags = "fh", - live_grep = "fw", - oldfiles = "fo", - themes = "th", -- NvChad theme picker - }, + misc = nil, } return M diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index d310f2e..f32d1c3 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -1,207 +1,200 @@ local utils = require "core.utils" local config = utils.load_config() -local map_wrapper = utils.map +local map = utils.map + +local user_cmd = vim.api.nvim_create_user_command -local maps = config.mappings -local plugin_maps = maps.plugins local nvChad_options = config.options.nvChad -local terminal_options = config.options.terminal + +local mappings = config.mappings local cmd = vim.cmd -- This is a wrapper function made to disable a plugin mapping from chadrc -- If keys are nil, false or empty string, then the mapping will be not applied -- Useful when one wants to use that keymap for any other purpose -local map = function(...) - local keys = select(2, ...) - if not keys or keys == "" then - return + +-- Don't copy the replaced text after pasting in visual mode +map("v", "p", "p:let @+=@0") + +-- 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 + +map({ "n", "x", "o" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) +map({ "n", "x", "o" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) +map("", "", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) +map("", "", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) + +-- use ESC to turn off search highlighting +map("n", "", " :noh ") + +-- move cursor within insert mode +map("i", "", "") +map("i", "", "") +map("i", "", "") +map("i", "", "") +map("i", "", "") +map("i", "", "^i") + +-- navigation between windows +map("n", "", "h") +map("n", "", "l") +map("n", "", "k") +map("n", "", "j") + +map("n", "x", function() + require("core.utils").close_buffer() +end) + +map("n", "", " :%y+ ") -- copy whole file content +map("n", "", " :enew ") -- new buffer +map("n", "b", " :tabnew ") -- new tabs +map("n", "n", " :set nu! ") +map("n", "rn", " :set rnu! ") -- relative line numbers +map("n", "", " :w ") -- ctrl + s to save file + +-- terminal mappings + +-- get out of terminal mode +map("t", { "jk" }, "") + +-- hide a term from within terminal mode +map("t", { "JK" }, function() + require("nvchad.terminal").hide() +end) + +-- Add Packer commands because we are not loading it at startup + +local packer_cmd = function(callback) + return function() + require "plugins" + require("packer")[callback]() end - map_wrapper(...) +end + +user_cmd("PackerClean", packer_cmd "clean", {}) +user_cmd("PackerCompile", packer_cmd "compile", {}) +user_cmd("PackerInstall", packer_cmd "install", {}) +user_cmd("PackerStatus", packer_cmd "status", {}) +user_cmd("PackerSync", packer_cmd "sync", {}) +user_cmd("PackerUpdate", packer_cmd "update", {}) + +-- add NvChadUpdate command and mapping +cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" +map("n", "uu", " :NvChadUpdate ") + +-- load overriden misc mappings + +if mappings.misc ~= nil and type(mappings.misc) == "function" then + mappings.misc() end local M = {} --- these mappings will only be called during initialization -M.misc = function() - local function non_config_mappings() - -- Don't copy the replaced text after pasting in visual mode - map_wrapper("v", "p", "p:let @+=@0") - - -- 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 - map_wrapper({ "n", "x", "o" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) - map_wrapper({ "n", "x", "o" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) - map_wrapper("", "", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) - map_wrapper("", "", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) - - -- use ESC to turn off search highlighting - map_wrapper("n", "", ":noh ") - - -- center cursor when moving (goto_definition) - end - - local function optional_mappings() - -- don't yank text on cut ( x ) - if not nvChad_options.copy_cut then - map_wrapper({ "n", "v" }, "x", '"_x') - end - - -- don't yank text on delete ( dd ) - if not nvChad_options.copy_del then - map_wrapper({ "n", "v" }, "d", '"_d') - end - - -- navigation within insert mode - if nvChad_options.insert_nav then - local inav = maps.insert_nav - - map("i", inav.backward, "") - map("i", inav.end_of_line, "") - map("i", inav.forward, "") - map("i", inav.next_line, "") - map("i", inav.prev_line, "") - map("i", inav.beginning_of_line, "^i") - end - - -- easier navigation between windows - if nvChad_options.window_nav then - local wnav = maps.window_nav - - map("n", wnav.moveLeft, "h") - map("n", wnav.moveRight, "l") - map("n", wnav.moveUp, "k") - map("n", wnav.moveDown, "j") - end - end - - local function required_mappings() - map("n", maps.misc.cheatsheet, ":lua require('nvchad.cheatsheet').show() ") -- show keybinds - map("n", maps.misc.close_buffer, ":lua require('core.utils').close_buffer() ") -- close buffer - map("n", maps.misc.cp_whole_file, ":%y+ ") -- copy whole file content - map("n", maps.misc.new_buffer, ":enew ") -- new buffer - map("n", maps.misc.new_tab, ":tabnew ") -- new tabs - map("n", maps.misc.lineNR_toggle, ":set nu! ") - map("n", maps.misc.lineNR_rel_toggle, ":set rnu! ") -- relative line numbers - map("n", maps.misc.save_file, ":w ") -- ctrl + s to save file - - -- terminal mappings -- - local term_maps = maps.terminal - -- get out of terminal mode - map("t", term_maps.esc_termmode, "") - -- hide a term from within terminal mode - map("t", term_maps.esc_hide_termmode, "lua require('nvchad.terminal').hide() ") - -- pick a hidden term - map("n", term_maps.pick_term, ":Telescope terms ") - -- Open terminals - -- TODO this opens on top of an existing vert/hori term, fixme - map( - { "n", "t" }, - term_maps.new_horizontal, - "lua require('nvchad.terminal').new_or_toggle('horizontal', " - .. tostring(terminal_options.window.split_height) - .. ")" - ) - map( - { "n", "t" }, - term_maps.new_vertical, - "lua require('nvchad.terminal').new_or_toggle('vertical', " - .. tostring(terminal_options.window.vsplit_width) - .. ")" - ) - map( - { "n", "t" }, - term_maps.new_float, - "lua require('nvchad.terminal').new_or_toggle('float')" - ) - - -- spawns terminals - map( - "n", - term_maps.spawn_horizontal, - ":execute 15 .. 'new +terminal' | let b:term_type = 'hori' | startinsert " - ) - map("n", term_maps.spawn_vertical, ":execute 'vnew +terminal' | let b:term_type = 'vert' | startinsert ") - map("n", term_maps.spawn_window, ":execute 'terminal' | let b:term_type = 'wind' | startinsert ") - - -- terminal mappings end -- - - -- Add Packer commands because we are not loading it at startup - cmd "silent! command PackerClean lua require 'plugins' require('packer').clean()" - cmd "silent! command PackerCompile lua require 'plugins' require('packer').compile()" - cmd "silent! command PackerInstall lua require 'plugins' require('packer').install()" - cmd "silent! command PackerStatus lua require 'plugins' require('packer').status()" - cmd "silent! command PackerSync lua require 'plugins' require('packer').sync()" - cmd "silent! command PackerUpdate lua require 'plugins' require('packer').update()" - - -- add NvChadUpdate command and mapping - cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" - map("n", maps.misc.update_nvchad, ":NvChadUpdate ") - end - - non_config_mappings() - optional_mappings() - required_mappings() -end - -- below are all plugin related mappings M.bufferline = function() - local m = plugin_maps.bufferline - - map("n", m.next_buffer, ":BufferLineCycleNext ") - map("n", m.prev_buffer, ":BufferLineCyclePrev ") + map("n", "", " :BufferLineCycleNext ") + map("n", "", " :BufferLineCyclePrev ") end M.comment = function() - local m = plugin_maps.comment.toggle - map("n", m, ":lua require('Comment.api').toggle_current_linewise()") - map("v", m, ":lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())") + map("n", "/", " :lua require('Comment.api').toggle_current_linewise()") + map("v", "/", " :lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())") end M.lspconfig = function() - local m = plugin_maps.lspconfig + -- See ` :help vim.lsp.*` for documentation on any of the below functions + map("n", "gD", function() + vim.lsp.buf.declaration() + end) - -- See `:help vim.lsp.*` for documentation on any of the below functions - map("n", m.declaration, "lua vim.lsp.buf.declaration()") - map("n", m.definition, "lua vim.lsp.buf.definition()") - map("n", m.hover, "lua vim.lsp.buf.hover()") - map("n", m.implementation, "lua vim.lsp.buf.implementation()") - map("n", m.signature_help, "lua vim.lsp.buf.signature_help()") - map("n", m.add_workspace_folder, "lua vim.lsp.buf.add_workspace_folder()") - map("n", m.remove_workspace_folder, "lua vim.lsp.buf.remove_workspace_folder()") - map("n", m.list_workspace_folders, "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))") - map("n", m.type_definition, "lua vim.lsp.buf.type_definition()") - map("n", m.rename, "lua vim.lsp.buf.rename()") - map("n", m.code_action, "lua vim.lsp.buf.code_action()") - map("n", m.references, "lua vim.lsp.buf.references()") - map("n", m.float_diagnostics, "lua vim.diagnostic.open_float()") - map("n", m.goto_prev, "lua vim.diagnostic.goto_prev()") - map("n", m.goto_next, "lua vim.diagnostic.goto_next()") - map("n", m.set_loclist, "lua vim.diagnostic.setloclist()") - map("n", m.formatting, "lua vim.lsp.buf.formatting()") + map("n", "gd", function() + vim.lsp.buf.definition() + end) + + map("n", "K", function() + vim.lsp.buf.hover() + end) + + map("n", "gi", function() + vim.lsp.buf.implementation() + end) + + map("n", "", function() + vim.lsp.buf.signature_help() + end) + + map("n", "D", function() + vim.lsp.buf.type_definition() + end) + + map("n", "ra", function() + vim.lsp.buf.rename() + end) + + map("n", "ca", function() + vim.lsp.buf.code_action() + end) + + map("n", "gr", function() + vim.lsp.buf.references() + end) + + map("n", "f", function() + vim.diagnostic.open_float() + end) + + map("n", "[d", function() + vim.diagnostic.goto_prev() + end) + + map("n", "d]", function() + vim.diagnostic.goto_next() + end) + + map("n", "q", function() + vim.diagnostic.setloclist() + end) + + map("n", "fm", function() + vim.lsp.buf.formatting() + end) + + map("n", "wa", function() + vim.lsp.buf.add_workspace_folder() + end) + + map("n", "wr", function() + vim.lsp.buf.remove_workspace_folder() + end) + + map("n", "wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end) end M.nvimtree = function() - map("n", plugin_maps.nvimtree.toggle, ":NvimTreeToggle ") - map("n", plugin_maps.nvimtree.focus, ":NvimTreeFocus ") + map("n", "", " :NvimTreeToggle ") + map("n", "e", " :NvimTreeFocus ") end M.telescope = function() - local m = plugin_maps.telescope + map("n", "fb", " :Telescope buffers ") + map("n", "ff", " :Telescope find_files ") + map("n", "fa", " :Telescope find_files follow=true no_ignore=true hidden=true ") + map("n", "cm", " :Telescope git_commits ") + map("n", "gt", " :Telescope git_status ") + map("n", "fh", " :Telescope help_tags ") + map("n", "fw", " :Telescope live_grep ") + map("n", "fo", " :Telescope oldfiles ") + map("n", "th", " :Telescope themes ") - map("n", m.buffers, ":Telescope buffers ") - map("n", m.find_files, ":Telescope find_files ") - map("n", m.find_hiddenfiles, ":Telescope find_files follow=true no_ignore=true hidden=true ") - map("n", m.git_commits, ":Telescope git_commits ") - map("n", m.git_status, ":Telescope git_status ") - map("n", m.help_tags, ":Telescope help_tags ") - map("n", m.live_grep, ":Telescope live_grep ") - map("n", m.oldfiles, ":Telescope oldfiles ") - map("n", m.themes, ":Telescope themes ") + -- pick a hidden term + map("n", "W", " :Telescope terms ") end return M diff --git a/lua/core/options.lua b/lua/core/options.lua index 06f669c..6b731b4 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -1,31 +1,34 @@ local opt = vim.opt local g = vim.g -local options = require("core.utils").load_config().options +-- use filetype.lua instead of filetype.vim +g.did_load_filetypes = 0 +g.do_filetype_lua = 1 +opt.laststatus = 3 -- global statusline opt.title = true -opt.clipboard = options.clipboard -opt.cmdheight = options.cmdheight +opt.clipboard = "unnamedplus" +opt.cmdheight = 1 opt.cul = true -- cursor line -- Indentline -opt.expandtab = options.expandtab -opt.shiftwidth = options.shiftwidth -opt.smartindent = options.smartindent +opt.expandtab = true +opt.shiftwidth = 2 +opt.smartindent = true -- disable tilde on end of buffer: https://github.com/neovim/neovim/pull/8546#issuecomment-643643758 -opt.fillchars = options.fillchars +opt.fillchars = { eob = " " } -opt.hidden = options.hidden -opt.ignorecase = options.ignorecase -opt.smartcase = options.smartcase -opt.mouse = options.mouse +opt.hidden = true +opt.ignorecase = true +opt.smartcase = true +opt.mouse = "a" -- Numbers -opt.number = options.number -opt.numberwidth = options.numberwidth -opt.relativenumber = options.relativenumber -opt.ruler = options.ruler +opt.number = true +opt.numberwidth = 2 +opt.relativenumber = false +opt.ruler = false -- disable nvim intro opt.shortmess:append "sI" @@ -33,31 +36,54 @@ opt.shortmess:append "sI" opt.signcolumn = "yes" opt.splitbelow = true opt.splitright = true -opt.tabstop = options.tabstop +opt.tabstop = 8 opt.termguicolors = true -opt.timeoutlen = options.timeoutlen -opt.undofile = options.undofile +opt.timeoutlen = 400 +opt.undofile = true -- interval for writing swap file to disk, also used by gitsigns -opt.updatetime = options.updatetime +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 = options.mapleader +g.mapleader = " " -- disable some builtin vim plugins -local disabled_built_ins = require("core.utils").load_config().plugins.builtins -for _, plugin in pairs(disabled_built_ins) do +local default_plugins = { + "2html_plugin", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", +} + +for _, plugin in pairs(default_plugins) do g["loaded_" .. plugin] = 1 end ---Defer loading shada until after startup_ -vim.opt.shadafile = "NONE" - vim.schedule(function() - vim.opt.shadafile = require("core.utils").load_config().options.shadafile + vim.opt.shadafile = "NONE" vim.cmd [[ silent! rsh ]] end) + +-- load user options if the file exists + +local load_ifExists = require("core.utils").load_ifExists +local user_options = require("core.utils").load_config().options.path + +load_ifExists(user_options) diff --git a/lua/core/utils.lua b/lua/core/utils.lua index bfda660..7ebb577 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -1,141 +1,13 @@ local M = {} local cmd = vim.cmd + M.close_buffer = function(force) - -- This is a modification of a NeoVim plugin from - -- Author: ojroques - Olivier Roques - -- Src: https://github.com/ojroques/nvim-bufdel - -- (Author has okayed copy-paste) - - -- Options - local opts = { - next = "cycle", -- how to retrieve the next buffer - quit = false, -- exit when last buffer is deleted - --TODO make this a chadrc flag/option - } - - -- ---------------- - -- Helper functions - -- ---------------- - - -- Switch to buffer 'buf' on each window from list 'windows' - local function switch_buffer(windows, buf) - local cur_win = vim.fn.winnr() - for _, winid in ipairs(windows) do - winid = tonumber(winid) or 0 - vim.cmd(string.format("%d wincmd w", vim.fn.win_id2win(winid))) - vim.cmd(string.format("buffer %d", buf)) - end - vim.cmd(string.format("%d wincmd w", cur_win)) -- return to original window - end - - -- Select the first buffer with a number greater than given buffer - local function get_next_buf(buf) - local next = vim.fn.bufnr "#" - if opts.next == "alternate" and vim.fn.buflisted(next) == 1 then - return next - end - for i = 0, vim.fn.bufnr "$" - 1 do - next = (buf + i) % vim.fn.bufnr "$" + 1 -- will loop back to 1 - if vim.fn.buflisted(next) == 1 then - return next - end - end - end - - -- ---------------- - -- End helper functions - -- ---------------- - - local buf = vim.fn.bufnr() - if vim.fn.buflisted(buf) == 0 then -- exit if buffer number is invalid - vim.cmd "close" - return - end - - if #vim.fn.getbufinfo { buflisted = 1 } < 2 then - if opts.quit then - -- exit when there is only one buffer left - if force then - vim.cmd "qall!" - else - vim.cmd "confirm qall" - end - return - end - - local chad_term, _ = pcall(function() - return vim.api.nvim_buf_get_var(buf, "term_type") - end) - - if chad_term then - -- Must be a window type - vim.cmd(string.format("setlocal nobl", buf)) - vim.cmd "enew" - return - end - -- don't exit and create a new empty buffer - vim.cmd "enew" - vim.cmd "bp" - end - - local next_buf = get_next_buf(buf) - local windows = vim.fn.getbufinfo(buf)[1].windows - - -- force deletion of terminal buffers to avoid the prompt - if force or vim.fn.getbufvar(buf, "&buftype") == "terminal" then - local chad_term, type = pcall(function() - return vim.api.nvim_buf_get_var(buf, "term_type") - end) - - -- TODO this scope is error prone, make resilient - if chad_term then - if type == "wind" then - -- hide from bufferline - vim.cmd(string.format("%d bufdo setlocal nobl", buf)) - -- switch to another buff - -- TODO switch to next buffer, this works too - vim.cmd "BufferLineCycleNext" - else - local cur_win = vim.fn.winnr() - -- we can close this window - vim.cmd(string.format("%d wincmd c", cur_win)) - return - end - else - switch_buffer(windows, next_buf) - vim.cmd(string.format("bd! %d", buf)) - end + if force or not vim.bo.buflisted then + cmd ":bd!" else - switch_buffer(windows, next_buf) - vim.cmd(string.format("silent! confirm bd %d", buf)) + cmd "bd" end - -- revert buffer switches if user has canceled deletion - if vim.fn.buflisted(buf) == 1 then - switch_buffer(windows, buf) - end -end - --- hide statusline --- tables fetched from load_config function -M.hide_statusline = function() - local hidden = require("core.utils").load_config().plugins.options.statusline.hidden - local shown = require("core.utils").load_config().plugins.options.statusline.shown - local api = vim.api - local buftype = api.nvim_buf_get_option(0, "ft") - - -- shown table from config has the highest priority - if vim.tbl_contains(shown, buftype) then - api.nvim_set_option("laststatus", 2) - return - end - - if vim.tbl_contains(hidden, buftype) then - api.nvim_set_option("laststatus", 0) - return - end - - api.nvim_set_option("laststatus", 2) end M.load_config = function() @@ -146,10 +18,10 @@ M.load_config = function() if chadrc_exists then -- merge user config if it exists and is a table; otherwise display an error local user_config = require "custom.chadrc" - if type(user_config) == 'table' then + if type(user_config) == "table" then conf = vim.tbl_deep_extend("force", conf, user_config) else - error("User config (chadrc.lua) *must* return a table!") + error "User config (chadrc.lua) *must* return a table!" end end @@ -158,52 +30,19 @@ end M.map = function(mode, keys, command, opt) local options = { noremap = true, silent = true } + if opt then options = vim.tbl_extend("force", options, opt) end - -- all valid modes allowed for mappings - -- :h map-modes - local valid_modes = { - [""] = true, - ["n"] = true, - ["v"] = true, - ["s"] = true, - ["x"] = true, - ["o"] = true, - ["!"] = true, - ["i"] = true, - ["l"] = true, - ["c"] = true, - ["t"] = true, - } - - -- helper function for M.map - -- can gives multiple modes and keys - local function map_wrapper(sub_mode, lhs, rhs, sub_options) - if type(lhs) == "table" then - for _, key in ipairs(lhs) do - map_wrapper(sub_mode, key, rhs, sub_options) - end - else - if type(sub_mode) == "table" then - for _, m in ipairs(sub_mode) do - map_wrapper(m, lhs, rhs, sub_options) - end - else - if valid_modes[sub_mode] and lhs and rhs then - vim.api.nvim_set_keymap(sub_mode, lhs, rhs, sub_options) - else - sub_mode, lhs, rhs = sub_mode or "", lhs or "", rhs or "" - print( - "Cannot set mapping [ mode = '" .. sub_mode .. "' | key = '" .. lhs .. "' | cmd = '" .. rhs .. "' ]" - ) - end - end + if type(keys) == "table" then + for _, keymap in ipairs(keys) do + M.map(mode, keymap, command, opt) end + return end - map_wrapper(mode, keys, command, options) + vim.keymap.set(mode, keys, command, opt) end -- load plugin after entering vim ui @@ -241,81 +80,49 @@ M.fg_bg = function(group, fgcol, bgcol) cmd("hi " .. group .. " guifg=" .. fgcol .. " guibg=" .. bgcol) end --- Override default config of a plugin based on the path provided in the chadrc --- Arguments: --- 1st - name of plugin --- 2nd - default config path --- 3rd - optional function name which will called from default_config path --- e.g: if given args - "telescope", "plugins.configs.telescope", "setup" --- then return "require('plugins.configs.telescope').setup()" --- if 3rd arg not given, then return "require('plugins.configs.telescope')" --- if override is a table, mark set the override flag for the default config to true --- override flag being true tells the plugin to call tbl_override_req as part of configuration +M.load_ifExists = function(module) + if #module ~= 0 then + if type(module) == "string" then + require(module) -M.override_req = function(name, default_config, config_function) - local override, apply_table_override = - require("core.utils").load_config().plugins.default_plugin_config_replace[name], "false" - local result = default_config - if type(override) == "string" and override ~= "" then - return "require('" .. override .. "')" - elseif type(override) == "table" then - apply_table_override = "true" - elseif type(override) == "function" then - return override - end - - result = "('" .. result .. "')" - if type(config_function) == "string" and config_function ~= "" then - -- add the . to call the functions and concatenate true or false as argument - result = result .. "." .. config_function .. "(" .. apply_table_override .. ")" - end - - return "require" .. result -end - --- Override parts of default config of a plugin based on the table provided in the chadrc - --- FUNCTION: tbl_override_req, use `chadrc` plugin config override to modify default config if present --- name = name inside `default_config` / `chadrc` --- default_table = the default configuration table of the plugin --- returns the modified configuration table -M.tbl_override_req = function(name, default_table) - local override = require("core.utils").load_config().plugins.default_plugin_config_replace[name] or {} - return vim.tbl_deep_extend("force", default_table, override) -end - ---provide labels to plugins instead of integers -M.label_plugins = function(plugins) - local plugins_labeled = {} - for _, plugin in ipairs(plugins) do - plugins_labeled[plugin[1]] = plugin - end - return plugins_labeled -end - --- remove plugins specified by user from the plugins table -M.remove_default_plugins = function(plugins) - local removals = require("core.utils").load_config().plugins.default_plugin_remove or {} - if not vim.tbl_isempty(removals) then - for _, plugin in pairs(removals) do - plugins[plugin] = nil + -- file[1] = module & file[2] = function + elseif type(module) == "table" then + require(module[1])[module[2]]() end end - return plugins end --- append user plugins to default plugins -M.add_user_plugins = function(plugins) - local user_Plugins = require("core.utils").load_config().plugins.install or {} - if type(user_Plugins) == "string" - then user_Plugins=require(user_Plugins) +-- merge default/user plugin tables + +M.plugin_list = function(default_plugins) + local user_plugins = require("core.utils").load_config().plugins.user + local plug_override = require("core.default_config").plugins.override + + -- merge default + user plugin table + default_plugins = vim.tbl_deep_extend("force", default_plugins, user_plugins) + + local final_table = {} + + for key, _ in pairs(default_plugins) do + default_plugins[key][1] = key + + final_table[#final_table + 1] = default_plugins[key] + plug_override[#plug_override + 1] = default_plugins[key] end - if not vim.tbl_isempty(user_Plugins) then - for _, v in pairs(user_Plugins) do - plugins[v[1]] = v - end + + return final_table +end + +M.load_override = function(default_table, plugin_name) + local user_table = require("core.utils").load_config().plugins.override[plugin_name] + + if type(user_table) == "table" then + default_table = vim.tbl_deep_extend("force", default_table, user_table) + else + default_table = default_table end - return plugins + + return default_table end return M diff --git a/lua/plugins/configs/alpha.lua b/lua/plugins/configs/alpha.lua index 573bbca..8a29061 100644 --- a/lua/plugins/configs/alpha.lua +++ b/lua/plugins/configs/alpha.lua @@ -32,9 +32,9 @@ local function button(sc, txt, keybind) } end -local default = {} +local options = {} -default.ascii = { +local ascii = { " ⣴⣶⣤⡤⠦⣤⣀⣤⠆ ⣈⣭⣿⣶⣿⣦⣼⣆ ", " ⠉⠻⢿⣿⠿⣿⣿⣶⣦⠤⠄⡠⢾⣿⣿⡿⠋⠉⠉⠻⣿⣿⡛⣦ ", " ⠈⢿⣿⣟⠦ ⣾⣿⣿⣷ ⠻⠿⢿⣿⣧⣄ ", @@ -48,16 +48,16 @@ default.ascii = { " ⠻⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣀⣤⣾⡿⠃ ", } -default.header = { +options.header = { type = "text", - val = default.ascii, + val = ascii, opts = { position = "center", hl = "AlphaHeader", }, } -default.buttons = { +options.buttons = { type = "group", val = { button("SPC f f", " Find File ", ":Telescope find_files"), @@ -72,21 +72,14 @@ default.buttons = { }, } -local M = {} +options = require("core.utils").load_override(options, "goolord/alpha-nvim") -M.setup = function(override_flag) - if override_flag then - default = require("core.utils").tbl_override_req("alpha", default) - end - alpha.setup { - layout = { - { type = "padding", val = 9 }, - default.header, - { type = "padding", val = 2 }, - default.buttons, - }, - opts = {}, - } -end - -return M +alpha.setup { + layout = { + { type = "padding", val = 9 }, + options.header, + { type = "padding", val = 2 }, + options.buttons, + }, + opts = {}, +} diff --git a/lua/plugins/configs/bufferline.lua b/lua/plugins/configs/bufferline.lua index 98557fd..3c127bc 100644 --- a/lua/plugins/configs/bufferline.lua +++ b/lua/plugins/configs/bufferline.lua @@ -3,10 +3,9 @@ if not present then return end -local default = { - colors = require("colors").get(), -} -default = { +local colors = require("colors").get() + +local options = { options = { offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, buffer_close_icon = "", @@ -46,103 +45,98 @@ default = { highlights = { background = { - guifg = default.colors.grey_fg, - guibg = default.colors.black2, + guifg = colors.grey_fg, + guibg = colors.black2, }, -- buffers buffer_selected = { - guifg = default.colors.white, - guibg = default.colors.black, + guifg = colors.white, + guibg = colors.black, gui = "bold", }, buffer_visible = { - guifg = default.colors.light_grey, - guibg = default.colors.black2, + guifg = colors.light_grey, + guibg = colors.black2, }, -- for diagnostics = "nvim_lsp" error = { - guifg = default.colors.light_grey, - guibg = default.colors.black2, + guifg = colors.light_grey, + guibg = colors.black2, }, error_diagnostic = { - guifg = default.colors.light_grey, - guibg = default.colors.black2, + guifg = colors.light_grey, + guibg = colors.black2, }, -- close buttons close_button = { - guifg = default.colors.light_grey, - guibg = default.colors.black2, + guifg = colors.light_grey, + guibg = colors.black2, }, close_button_visible = { - guifg = default.colors.light_grey, - guibg = default.colors.black2, + guifg = colors.light_grey, + guibg = colors.black2, }, close_button_selected = { - guifg = default.colors.red, - guibg = default.colors.black, + guifg = colors.red, + guibg = colors.black, }, fill = { - guifg = default.colors.grey_fg, - guibg = default.colors.black2, + guifg = colors.grey_fg, + guibg = colors.black2, }, indicator_selected = { - guifg = default.colors.black, - guibg = default.colors.black, + guifg = colors.black, + guibg = colors.black, }, -- modified modified = { - guifg = default.colors.red, - guibg = default.colors.black2, + guifg = colors.red, + guibg = colors.black2, }, modified_visible = { - guifg = default.colors.red, - guibg = default.colors.black2, + guifg = colors.red, + guibg = colors.black2, }, modified_selected = { - guifg = default.colors.green, - guibg = default.colors.black, + guifg = colors.green, + guibg = colors.black, }, -- separators separator = { - guifg = default.colors.black2, - guibg = default.colors.black2, + guifg = colors.black2, + guibg = colors.black2, }, separator_visible = { - guifg = default.colors.black2, - guibg = default.colors.black2, + guifg = colors.black2, + guibg = colors.black2, }, separator_selected = { - guifg = default.colors.black2, - guibg = default.colors.black2, + guifg = colors.black2, + guibg = colors.black2, }, -- tabs tab = { - guifg = default.colors.light_grey, - guibg = default.colors.one_bg3, + guifg = colors.light_grey, + guibg = colors.one_bg3, }, tab_selected = { - guifg = default.colors.black2, - guibg = default.colors.nord_blue, + guifg = colors.black2, + guibg = colors.nord_blue, }, tab_close = { - guifg = default.colors.red, - guibg = default.colors.black, + guifg = colors.red, + guibg = colors.black, }, }, } -local M = {} -M.setup = function(override_flag) - if override_flag then - default = require("core.utils").tbl_override_req("bufferline", default) - end - bufferline.setup(default) -end +-- check for any override +options = require("core.utils").load_override(options, "akinsho/bufferline.nvim") -return M +bufferline.setup(options) diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index 02b77e9..7d02520 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -6,7 +6,7 @@ end vim.opt.completeopt = "menuone,noselect" -local default = { +local options = { snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) @@ -45,7 +45,10 @@ local default = { else fallback() end - end, { "i", "s" }), + end, { + "i", + "s", + }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() @@ -54,7 +57,10 @@ local default = { else fallback() end - end, { "i", "s" }), + end, { + "i", + "s", + }), }, sources = { { name = "nvim_lsp" }, @@ -65,12 +71,7 @@ local default = { }, } -local M = {} -M.setup = function(override_flag) - if override_flag then - default = require("core.utils").tbl_override_req("nvim_cmp", default) - end - cmp.setup(default) -end +-- check for any override +-- options = require("core.utils").load_override(options, "cmp") -return M +cmp.setup(options) diff --git a/lua/plugins/configs/icons.lua b/lua/plugins/configs/icons.lua index 4f23dd9..d765ec9 100644 --- a/lua/plugins/configs/icons.lua +++ b/lua/plugins/configs/icons.lua @@ -1,158 +1,152 @@ -local present, icons = pcall(require, "nvim-web-devicons") +local present, devicons = pcall(require, "nvim-web-devicons") + if not present then return end -local default = { - colors = require("colors").get(), -} +local colors = require("colors").get() -default = { +local options = { override = { c = { icon = "", - color = default.colors.blue, + color = colors.blue, name = "c", }, css = { icon = "", - color = default.colors.blue, + color = colors.blue, name = "css", }, deb = { icon = "", - color = default.colors.cyan, + color = colors.cyan, name = "deb", }, Dockerfile = { icon = "", - color = default.colors.cyan, + color = colors.cyan, name = "Dockerfile", }, html = { icon = "", - color = default.colors.baby_pink, + color = colors.baby_pink, name = "html", }, jpeg = { icon = "", - color = default.colors.dark_purple, + color = colors.dark_purple, name = "jpeg", }, jpg = { icon = "", - color = default.colors.dark_purple, + color = colors.dark_purple, name = "jpg", }, js = { icon = "", - color = default.colors.sun, + color = colors.sun, name = "js", }, kt = { icon = "󱈙", - color = default.colors.orange, + color = colors.orange, name = "kt", }, lock = { icon = "", - color = default.colors.red, + color = colors.red, name = "lock", }, lua = { icon = "", - color = default.colors.blue, + color = colors.blue, name = "lua", }, mp3 = { icon = "", - color = default.colors.white, + color = colors.white, name = "mp3", }, mp4 = { icon = "", - color = default.colors.white, + color = colors.white, name = "mp4", }, out = { icon = "", - color = default.colors.white, + color = colors.white, name = "out", }, png = { icon = "", - color = default.colors.dark_purple, + color = colors.dark_purple, name = "png", }, py = { icon = "", - color = default.colors.cyan, + color = colors.cyan, name = "py", }, ["robots.txt"] = { icon = "ﮧ", - color = default.colors.red, + color = colors.red, name = "robots", }, toml = { icon = "", - color = default.colors.blue, + color = colors.blue, name = "toml", }, ts = { icon = "ﯤ", - color = default.colors.teal, + color = colors.teal, name = "ts", }, ttf = { icon = "", - color = default.colors.white, + color = colors.white, name = "TrueTypeFont", }, rb = { icon = "", - color = default.colors.pink, + color = colors.pink, name = "rb", }, rpm = { icon = "", - color = default.colors.orange, + color = colors.orange, name = "rpm", }, vue = { icon = "﵂", - color = default.colors.vibrant_green, + color = colors.vibrant_green, name = "vue", }, woff = { icon = "", - color = default.colors.white, + color = colors.white, name = "WebOpenFontFormat", }, woff2 = { icon = "", - color = default.colors.white, + color = colors.white, name = "WebOpenFontFormat2", }, xz = { icon = "", - color = default.colors.sun, + color = colors.sun, name = "xz", }, zip = { icon = "", - color = default.colors.sun, + color = colors.sun, name = "zip", }, }, } -local M = {} -M.setup = function(override_flag) - if override_flag then - default = require("core.utils").tbl_override_req("nvim_web_devicons", default) - end - icons.setup(default) -end +-- check for any override +-- options = require("core.utils").load_override(options, "nvim_web_devicons") -return M +devicons.setup(options) diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index 962cfeb..5d6452a 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -1,4 +1,5 @@ local M = {} + require("plugins.configs.others").lsp_handlers() function M.on_attach(client, bufnr) diff --git a/lua/plugins/configs/nvimtree.lua b/lua/plugins/configs/nvimtree.lua index a93a102..2276248 100644 --- a/lua/plugins/configs/nvimtree.lua +++ b/lua/plugins/configs/nvimtree.lua @@ -1,8 +1,14 @@ +local present, nvimtree = pcall(require, "nvim-tree") + +if not present then + return +end + -- globals must be set prior to requiring nvim-tree to function local g = vim.g g.nvim_tree_add_trailing = 0 -- append a trailing slash to folder names -g.nvim_tree_git_hl = 0 +g.nvim_tree_git_hl = 1 g.nvim_tree_highlight_opened_files = 0 g.nvim_tree_root_folder_modifier = table.concat { ":t:gs?$?/..", string.rep(" ", 1000), "?:gs?^??" } @@ -34,20 +40,13 @@ g.nvim_tree_icons = { }, } -local present, nvimtree = pcall(require, "nvim-tree") - -if not present then - return -end - -local default = { +local options = { filters = { dotfiles = false, }, disable_netrw = true, hijack_netrw = true, ignore_ft_on_setup = { "dashboard" }, - auto_close = false, open_on_tab = false, hijack_cursor = true, hijack_unnamed_buffer_when_opening = false, @@ -57,7 +56,6 @@ local default = { update_cwd = false, }, view = { - allow_resize = true, side = "left", width = 25, hide_root_folder = true, @@ -74,17 +72,11 @@ local default = { renderer = { indent_markers = { enable = true, - } - } + }, + }, } -local M = {} +-- check for any override +options = require("core.utils").load_override(options, "kyazdani42/nvim-tree.lua") -M.setup = function(override_flag) - if override_flag then - default = require("core.utils").tbl_override_req("nvim_tree", default) - end - nvimtree.setup(default) -end - -return M +nvimtree.setup(options) diff --git a/lua/plugins/configs/nvterm.lua b/lua/plugins/configs/nvterm.lua new file mode 100644 index 0000000..720b6d2 --- /dev/null +++ b/lua/plugins/configs/nvterm.lua @@ -0,0 +1,43 @@ +local present, nvterm = pcall(require, "nvterm") + +if not present then + return +end + +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, + }, + mappings = { + toggle = { + float = "", + horizontal = "", + vertical = "", + }, + new = { + horizontal = "h", + vertical = "v", + }, + }, + enable_new_mappings = true, +} + +options = require("core.utils").load_override(options, "NvChad/nvterm") + +nvterm.setup(options) diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index 3a86715..bad0b63 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -1,36 +1,49 @@ local M = {} -local chadrc_config = require("core.utils").load_config() - -M.autopairs = function(override_flag) +M.autopairs = function() local present1, autopairs = pcall(require, "nvim-autopairs") - local present2, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp") + local present2, cmp = pcall(require, "cmp") - if present1 and present2 then - local default = { fast_wrap = {} } - if override_flag then - default = require("core.utils").tbl_override_req("nvim_autopairs", default) - end - autopairs.setup(default) - - local cmp = require "cmp" - cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) + if not present1 and present2 then + return end -end -M.better_escape = function(override_flag) - local default = { - mapping = chadrc_config.mappings.plugins.better_escape.esc_insertmode, - timeout = chadrc_config.plugins.options.esc_insertmode_timeout, + autopairs.setup { + fast_wrap = {}, + disable_filetype = { "TelescopePrompt", "vim" }, } - if override_flag then - default = require("core.utils").tbl_override_req("better_escape", default) - end - require("better_escape").setup(default) + + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) end -M.blankline = function(override_flag) - local default = { +M.better_escape = function() + local present, escape = pcall(require, "better_escape") + + if not present then + return + end + + local options = { + mapping = { "jk" }, -- a table with mappings to use + timeout = vim.o.timeoutlen, + clear_empty_lines = false, -- clear line after escaping if there is only whitespace + keys = "", + } + + options = require("core.utils").load_override(options, "max397574/better-escape.nvim") + escape.setup(options) +end + +M.blankline = function() + local present, blankline = pcall(require, "indent_blankline") + + if not present then + return + end + + local options = { indentLine_enabled = 1, char = "▏", filetype_exclude = { @@ -49,93 +62,97 @@ M.blankline = function(override_flag) show_trailing_blankline_indent = false, show_first_indent_level = false, } - if override_flag then - default = require("core.utils").tbl_override_req("indent_blankline", default) - end - require("indent_blankline").setup(default) + + options = require("core.utils").load_override(options, "lukas-reineke/indent-blankline.nvim") + blankline.setup(options) end -M.colorizer = function(override_flag) +M.colorizer = function() local present, colorizer = pcall(require, "colorizer") - if present then - local default = { - 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 - -- Available modes: foreground, background - mode = "background", -- Set the display mode. - }, - } - if override_flag then - default = require("core.utils").tbl_override_req("nvim_colorizer", default) - end - colorizer.setup(default["filetypes"], default["user_default_options"]) - vim.cmd "ColorizerReloadAllBuffers" + 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 + + -- Available modes: foreground, background + mode = "background", -- Set the display mode. + }, + } + + options = require("core.utils").load_override(options, "NvChad/nvim-colorizer.lua") + + colorizer.setup(options["filetypes"], options["user_default_options"]) + vim.cmd "ColorizerReloadAllBuffers" end -M.comment = function(override_flag) +M.comment = function() local present, nvim_comment = pcall(require, "Comment") - if present then - local default = {} - if override_flag then - default = require("core.utils").tbl_override_req("nvim_comment", default) - end - nvim_comment.setup(default) + + if not present then + return end + + nvim_comment.setup() end -M.luasnip = function(override_flag) +M.luasnip = function() local present, luasnip = pcall(require, "luasnip") + if present then - local default = { - history = true, - updateevents = "TextChanged,TextChangedI", - } - if override_flag then - default = require("core.utils").tbl_override_req("luasnip", default) - end - luasnip.config.set_config(default) - require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path } - require("luasnip/loaders/from_vscode").load() + return end + + luasnip.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + } + + -- add snippet path here! + require("luasnip/loaders/from_vscode").load { paths = {} } + require("luasnip/loaders/from_vscode").load() end -M.signature = function(override_flag) - local present, lspsignature = pcall(require, "lsp_signature") - if present then - local default = { - bind = true, - doc_lines = 0, - floating_window = true, - fix_pos = true, - hint_enable = true, - hint_prefix = " ", - hint_scheme = "String", - hi_parameter = "Search", - max_height = 22, - max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width - handler_opts = { - border = "single", -- double, single, shadow, none - }, - zindex = 200, -- by default it will be on top of all floating windows, set to 50 send it to bottom - padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc - } - if override_flag then - default = require("core.utils").tbl_override_req("signature", default) - end - lspsignature.setup(default) +M.signature = function() + local present, lsp_signature = pcall(require, "lsp_signature") + + if not present then + return end + + local options = { + bind = true, + doc_lines = 0, + floating_window = true, + fix_pos = true, + hint_enable = true, + hint_prefix = " ", + hint_scheme = "String", + hi_parameter = "Search", + max_height = 22, + max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width + handler_opts = { + border = "single", -- double, single, shadow, none + }, + zindex = 200, -- by default it will be on top of all floating windows, set to 50 send it to bottom + padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc + } + + options = require("core.utils").load_override(options, "ray-x/lsp_signature.nvim") + lsp_signature.setup(options) end M.lsp_handlers = function() @@ -178,23 +195,22 @@ M.lsp_handlers = function() end end -M.gitsigns = function(override_flag) +M.gitsigns = function() local present, gitsigns = pcall(require, "gitsigns") - if present then - local default = { - 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" }, - }, - } - if override_flag then - default = require("core.utils").tbl_override_req("gitsigns", default) - end - gitsigns.setup(default) + + if not present then + return end + + gitsigns.setup { + 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" }, + }, + } end return M diff --git a/lua/plugins/configs/statusline.lua b/lua/plugins/configs/statusline.lua index ddad9d5..b667680 100644 --- a/lua/plugins/configs/statusline.lua +++ b/lua/plugins/configs/statusline.lua @@ -1,16 +1,14 @@ local present, feline = pcall(require, "feline") + if not present then return end -local default = { - colors = require("colors").get(), - lsp = require "feline.providers.lsp", - lsp_severity = vim.diagnostic.severity, - config = require("core.utils").load_config().plugins.options.statusline, -} +local colors = require("colors").get() +local lsp = require "feline.providers.lsp" +local lsp_severity = vim.diagnostic.severity -default.icon_styles = { +local icon_styles = { default = { left = "", right = " ", @@ -51,35 +49,31 @@ default.icon_styles = { }, } --- statusline style -default.statusline_style = default.icon_styles[default.config.style] - --- show short statusline on small screens -default.shortline = default.config.shortline == false and true +local separator_style = icon_styles.default -- Initialize the components table -default.components = { +local components = { active = {}, } -default.main_icon = { - provider = default.statusline_style.main_icon, +local main_icon = { + provider = separator_style.main_icon, hl = { - fg = default.colors.statusline_bg, - bg = default.colors.nord_blue, + fg = colors.statusline_bg, + bg = colors.nord_blue, }, right_sep = { - str = default.statusline_style.right, + str = separator_style.right, hl = { - fg = default.colors.nord_blue, - bg = default.colors.lightbg, + fg = colors.nord_blue, + bg = colors.lightbg, }, }, } -default.file_name = { +local file_name = { provider = function() local filename = vim.fn.expand "%:t" local extension = vim.fn.expand "%:e" @@ -90,49 +84,42 @@ default.file_name = { end return " " .. icon .. " " .. filename .. " " end, - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 - end, hl = { - fg = default.colors.white, - bg = default.colors.lightbg, + fg = colors.white, + bg = colors.lightbg, }, right_sep = { - str = default.statusline_style.right, - hl = { fg = default.colors.lightbg, bg = default.colors.lightbg2 }, + str = separator_style.right, + hl = { fg = colors.lightbg, bg = colors.lightbg2 }, }, } -default.dir_name = { +local dir_name = { provider = function() local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t") return "  " .. dir_name .. " " end, - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80 - end, - hl = { - fg = default.colors.grey_fg2, - bg = default.colors.lightbg2, + fg = colors.grey_fg2, + bg = colors.lightbg2, }, right_sep = { - str = default.statusline_style.right, + str = separator_style.right, hi = { - fg = default.colors.lightbg2, - bg = default.colors.statusline_bg, + fg = colors.lightbg2, + bg = colors.statusline_bg, }, }, } -default.diff = { +local diff = { add = { provider = "git_diff_added", hl = { - fg = default.colors.grey_fg2, - bg = default.colors.statusline_bg, + fg = colors.grey_fg2, + bg = colors.statusline_bg, }, icon = " ", }, @@ -140,8 +127,8 @@ default.diff = { change = { provider = "git_diff_changed", hl = { - fg = default.colors.grey_fg2, - bg = default.colors.statusline_bg, + fg = colors.grey_fg2, + bg = colors.statusline_bg, }, icon = "  ", }, @@ -149,65 +136,62 @@ default.diff = { remove = { provider = "git_diff_removed", hl = { - fg = default.colors.grey_fg2, - bg = default.colors.statusline_bg, + fg = colors.grey_fg2, + bg = colors.statusline_bg, }, icon = "  ", }, } -default.git_branch = { +local git_branch = { provider = "git_branch", - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 - end, hl = { - fg = default.colors.grey_fg2, - bg = default.colors.statusline_bg, + fg = colors.grey_fg2, + bg = colors.statusline_bg, }, icon = "  ", } -default.diagnostic = { +local diagnostic = { error = { provider = "diagnostic_errors", enabled = function() - return default.lsp.diagnostics_exist(default.lsp_severity.ERROR) + return lsp.diagnostics_exist(lsp_severity.ERROR) end, - hl = { fg = default.colors.red }, + hl = { fg = colors.red }, icon = "  ", }, warning = { provider = "diagnostic_warnings", enabled = function() - return default.lsp.diagnostics_exist(default.lsp_severity.WARN) + return lsp.diagnostics_exist(lsp_severity.WARN) end, - hl = { fg = default.colors.yellow }, + hl = { fg = colors.yellow }, icon = "  ", }, hint = { provider = "diagnostic_hints", enabled = function() - return default.lsp.diagnostics_exist(default.lsp_severity.HINT) + return lsp.diagnostics_exist(lsp_severity.HINT) end, - hl = { fg = default.colors.grey_fg2 }, + hl = { fg = colors.grey_fg2 }, icon = "  ", }, info = { provider = "diagnostic_info", enabled = function() - return default.lsp.diagnostics_exist(default.lsp_severity.INFO) + return lsp.diagnostics_exist(lsp_severity.INFO) end, - hl = { fg = default.colors.green }, + hl = { fg = colors.green }, icon = "  ", }, } -default.lsp_progress = { +local lsp_progress = { provider = function() local Lsp = vim.lsp.util.get_progress_messages()[1] @@ -239,13 +223,10 @@ default.lsp_progress = { return "" end, - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80 - end, - hl = { fg = default.colors.green }, + hl = { fg = colors.green }, } -default.lsp_icon = { +local lsp_icon = { provider = function() if next(vim.lsp.buf_get_clients()) ~= nil then return " LSP" @@ -253,112 +234,100 @@ default.lsp_icon = { return "" end end, - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 - end, - hl = { fg = default.colors.grey_fg2, bg = default.colors.statusline_bg }, + hl = { fg = colors.grey_fg2, bg = colors.statusline_bg }, } -default.mode_colors = { - ["n"] = { "NORMAL", default.colors.red }, - ["no"] = { "N-PENDING", default.colors.red }, - ["i"] = { "INSERT", default.colors.dark_purple }, - ["ic"] = { "INSERT", default.colors.dark_purple }, - ["t"] = { "TERMINAL", default.colors.green }, - ["v"] = { "VISUAL", default.colors.cyan }, - ["V"] = { "V-LINE", default.colors.cyan }, - [""] = { "V-BLOCK", default.colors.cyan }, - ["R"] = { "REPLACE", default.colors.orange }, - ["Rv"] = { "V-REPLACE", default.colors.orange }, - ["s"] = { "SELECT", default.colors.nord_blue }, - ["S"] = { "S-LINE", default.colors.nord_blue }, - [""] = { "S-BLOCK", default.colors.nord_blue }, - ["c"] = { "COMMAND", default.colors.pink }, - ["cv"] = { "COMMAND", default.colors.pink }, - ["ce"] = { "COMMAND", default.colors.pink }, - ["r"] = { "PROMPT", default.colors.teal }, - ["rm"] = { "MORE", default.colors.teal }, - ["r?"] = { "CONFIRM", default.colors.teal }, - ["!"] = { "SHELL", default.colors.green }, +local mode_colors = { + ["n"] = { "NORMAL", colors.red }, + ["no"] = { "N-PENDING", colors.red }, + ["i"] = { "INSERT", colors.dark_purple }, + ["ic"] = { "INSERT", colors.dark_purple }, + ["t"] = { "TERMINAL", colors.green }, + ["v"] = { "VISUAL", colors.cyan }, + ["V"] = { "V-LINE", colors.cyan }, + [""] = { "V-BLOCK", colors.cyan }, + ["R"] = { "REPLACE", colors.orange }, + ["Rv"] = { "V-REPLACE", colors.orange }, + ["s"] = { "SELECT", colors.nord_blue }, + ["S"] = { "S-LINE", colors.nord_blue }, + [""] = { "S-BLOCK", colors.nord_blue }, + ["c"] = { "COMMAND", colors.pink }, + ["cv"] = { "COMMAND", colors.pink }, + ["ce"] = { "COMMAND", colors.pink }, + ["r"] = { "PROMPT", colors.teal }, + ["rm"] = { "MORE", colors.teal }, + ["r?"] = { "CONFIRM", colors.teal }, + ["!"] = { "SHELL", colors.green }, } -default.chad_mode_hl = function() +local chad_mode_hl = function() return { - fg = default.mode_colors[vim.fn.mode()][2], - bg = default.colors.one_bg, + fg = mode_colors[vim.fn.mode()][2], + bg = colors.one_bg, } end -default.empty_space = { - provider = " " .. default.statusline_style.left, +local empty_space = { + provider = " " .. separator_style.left, hl = { - fg = default.colors.one_bg2, - bg = default.colors.statusline_bg, + fg = colors.one_bg2, + bg = colors.statusline_bg, }, } -- this matches the vi mode color -default.empty_spaceColored = { - provider = default.statusline_style.left, +local empty_spaceColored = { + provider = separator_style.left, hl = function() return { - fg = default.mode_colors[vim.fn.mode()][2], - bg = default.colors.one_bg2, + fg = mode_colors[vim.fn.mode()][2], + bg = colors.one_bg2, } end, } -default.mode_icon = { - provider = default.statusline_style.vi_mode_icon, +local mode_icon = { + provider = separator_style.vi_mode_icon, hl = function() return { - fg = default.colors.statusline_bg, - bg = default.mode_colors[vim.fn.mode()][2], + fg = colors.statusline_bg, + bg = mode_colors[vim.fn.mode()][2], } end, } -default.empty_space2 = { +local empty_space2 = { provider = function() - return " " .. default.mode_colors[vim.fn.mode()][1] .. " " + return " " .. mode_colors[vim.fn.mode()][1] .. " " end, - hl = default.chad_mode_hl, + hl = chad_mode_hl, } -default.separator_right = { - provider = default.statusline_style.left, - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 - end, +local separator_right = { + provider = separator_style.left, hl = { - fg = default.colors.grey, - bg = default.colors.one_bg, + fg = colors.grey, + bg = colors.one_bg, }, } -default.separator_right2 = { - provider = default.statusline_style.left, - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 - end, +local separator_right2 = { + provider = separator_style.left, hl = { - fg = default.colors.green, - bg = default.colors.grey, + fg = colors.green, + bg = colors.grey, }, } -default.position_icon = { - provider = default.statusline_style.position_icon, - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 - end, +local position_icon = { + provider = separator_style.position_icon, hl = { - fg = default.colors.black, - bg = default.colors.green, + fg = colors.black, + bg = colors.green, }, } -default.current_line = { +local current_line = { provider = function() local current_line = vim.fn.line "." local total_line = vim.fn.line "$" @@ -372,13 +341,9 @@ default.current_line = { return " " .. result .. "%% " end, - enabled = default.shortline or function(winid) - return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 - end, - hl = { - fg = default.colors.green, - bg = default.colors.one_bg, + fg = colors.green, + bg = colors.one_bg, }, } @@ -386,53 +351,45 @@ local function add_table(a, b) table.insert(a, b) end -local M = {} -M.setup = function(override_flag) - if override_flag then - default = require("core.utils").tbl_override_req("feline", default) - end - -- components are divided in 3 sections - default.left = {} - default.middle = {} - default.right = {} +-- components are divided in 3 sections +local left = {} +local middle = {} +local right = {} - -- left - add_table(default.left, default.main_icon) - add_table(default.left, default.file_name) - add_table(default.left, default.dir_name) - add_table(default.left, default.diff.add) - add_table(default.left, default.diff.change) - add_table(default.left, default.diff.remove) - add_table(default.left, default.diagnostic.error) - add_table(default.left, default.diagnostic.warning) - add_table(default.left, default.diagnostic.hint) - add_table(default.left, default.diagnostic.info) +-- left +add_table(left, main_icon) +add_table(left, file_name) +add_table(left, dir_name) +add_table(left, diff.add) +add_table(left, diff.change) +add_table(left, diff.remove) +add_table(left, diagnostic.error) +add_table(left, diagnostic.warning) +add_table(left, diagnostic.hint) +add_table(left, diagnostic.info) - add_table(default.middle, default.lsp_progress) +add_table(middle, lsp_progress) - -- right - add_table(default.right, default.lsp_icon) - add_table(default.right, default.git_branch) - add_table(default.right, default.empty_space) - add_table(default.right, default.empty_spaceColored) - add_table(default.right, default.mode_icon) - add_table(default.right, default.empty_space2) - add_table(default.right, default.separator_right) - add_table(default.right, default.separator_right2) - add_table(default.right, default.position_icon) - add_table(default.right, default.current_line) +-- right +add_table(right, lsp_icon) +add_table(right, git_branch) +add_table(right, empty_space) +add_table(right, empty_spaceColored) +add_table(right, mode_icon) +add_table(right, empty_space2) +add_table(right, separator_right) +add_table(right, separator_right2) +add_table(right, position_icon) +add_table(right, current_line) - default.components.active[1] = default.left - default.components.active[2] = default.middle - default.components.active[3] = default.right +components.active[1] = left +components.active[2] = middle +components.active[3] = right - feline.setup { - theme = { - bg = default.colors.statusline_bg, - fg = default.colors.fg, - }, - components = default.components, - } -end - -return M +feline.setup { + theme = { + bg = colors.statusline_bg, + fg = colors.fg, + }, + components = components, +} diff --git a/lua/plugins/configs/telescope.lua b/lua/plugins/configs/telescope.lua index 7a5af67..aff3cc0 100644 --- a/lua/plugins/configs/telescope.lua +++ b/lua/plugins/configs/telescope.lua @@ -4,7 +4,7 @@ if not present then return end -local default = { +local options = { defaults = { vimgrep_arguments = { "rg", @@ -53,21 +53,15 @@ local default = { }, } -local M = {} -M.setup = function(override_flag) - if override_flag then - default = require("core.utils").tbl_override_req("telescope", default) +-- check for any override +options = require("core.utils").load_override(options, "nvim-telescope/telescope.nvim") +telescope.setup(options) + +-- load extensions +local extensions = { "themes", "terms" } + +pcall(function() + for _, ext in ipairs(extensions) do + telescope.load_extension(ext) end - - telescope.setup(default) - - local extensions = { "themes", "terms" } - - pcall(function() - for _, ext in ipairs(extensions) do - telescope.load_extension(ext) - end - end) -end - -return M +end) diff --git a/lua/plugins/configs/treesitter.lua b/lua/plugins/configs/treesitter.lua index 777b907..a6e6483 100644 --- a/lua/plugins/configs/treesitter.lua +++ b/lua/plugins/configs/treesitter.lua @@ -1,10 +1,10 @@ -local present, ts_config = pcall(require, "nvim-treesitter.configs") +local present, treesitter = pcall(require, "nvim-treesitter.configs") if not present then return end -local default = { +local options = { ensure_installed = { "lua", "vim", @@ -15,12 +15,7 @@ local default = { }, } -local M = {} -M.setup = function(override_flag) - if override_flag then - default = require("core.utils").tbl_override_req("nvim_treesitter", default) - end - ts_config.setup(default) -end +-- check for any override +options = require("core.utils").load_override(options, "nvim-treesitter/nvim-treesitter") -return M +treesitter.setup(options) diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 1e15ef7..f145f45 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -5,84 +5,83 @@ if not present then return false end -local override_req = require("core.utils").override_req - local plugins = { - { "nvim-lua/plenary.nvim" }, - { "lewis6991/impatient.nvim" }, - { "nathom/filetype.nvim" }, + ["nvim-lua/plenary.nvim"] = {}, + ["lewis6991/impatient.nvim"] = {}, - { - "wbthomason/packer.nvim", + ["wbthomason/packer.nvim"] = { event = "VimEnter", }, - { - "NvChad/extensions", - config = function () - vim.schedule_wrap(require("nvchad.terminal").init()) - end - }, + ["NvChad/extensions"] = {}, - { - "NvChad/nvim-base16.lua", + ["NvChad/nvim-base16.lua"] = { after = "packer.nvim", config = function() require("colors").init() end, }, - { - "kyazdani42/nvim-web-devicons", - after = "nvim-base16.lua", - config = override_req("nvim_web_devicons", "plugins.configs.icons", "setup"), - }, - - { - "feline-nvim/feline.nvim", - disable = not plugin_settings.status.feline, - after = "nvim-web-devicons", - config = override_req("feline", "plugins.configs.statusline", "setup"), - }, - - { - "akinsho/bufferline.nvim", - branch = "main", - disable = not plugin_settings.status.bufferline, - after = "nvim-web-devicons", - config = override_req("bufferline", "plugins.configs.bufferline", "setup"), - setup = function() - require("core.mappings").bufferline() + ["NvChad/nvterm"] = { + config = function() + require "plugins.configs.nvterm" end, }, - { - "lukas-reineke/indent-blankline.nvim", - disable = not plugin_settings.status.blankline, - event = "BufRead", - config = override_req("indent_blankline", "plugins.configs.others", "blankline"), + ["kyazdani42/nvim-web-devicons"] = { + after = "nvim-base16.lua", + config = function() + require "plugins.configs.icons" + end, }, - { - "NvChad/nvim-colorizer.lua", - disable = not plugin_settings.status.colorizer, - event = "BufRead", - config = override_req("nvim_colorizer", "plugins.configs.others", "colorizer"), + ["feline-nvim/feline.nvim"] = { + after = "nvim-web-devicons", + config = function() + require "plugins.configs.statusline" + end, }, - { - "nvim-treesitter/nvim-treesitter", + ["akinsho/bufferline.nvim"] = { + after = "nvim-web-devicons", + + setup = function() + require("core.mappings").bufferline() + end, + + config = function() + require "plugins.configs.bufferline" + end, + }, + + ["lukas-reineke/indent-blankline.nvim"] = { + event = "BufRead", + config = function() + require("plugins.configs.others").blankline() + end, + }, + + ["NvChad/nvim-colorizer.lua"] = { + event = "BufRead", + config = function() + require("plugins.configs.others").colorizer() + end, + }, + + ["nvim-treesitter/nvim-treesitter"] = { event = { "BufRead", "BufNewFile" }, - config = override_req("nvim_treesitter", "plugins.configs.treesitter", "setup"), run = ":TSUpdate", + config = function() + require "plugins.configs.treesitter" + end, }, -- git stuff - { - "lewis6991/gitsigns.nvim", - disable = not plugin_settings.status.gitsigns, + ["lewis6991/gitsigns.nvim"] = { opt = true, - config = override_req("gitsigns", "plugins.configs.others", "gitsigns"), + config = function() + require("plugins.configs.others").gitsigns() + end, setup = function() require("core.utils").packer_lazy_load "gitsigns.nvim" end, @@ -90,8 +89,7 @@ local plugins = { -- lsp stuff - { - "neovim/nvim-lspconfig", + ["neovim/nvim-lspconfig"] = { module = "lspconfig", opt = true, setup = function() @@ -101,141 +99,131 @@ local plugins = { vim.cmd 'if &ft == "packer" | echo "" | else | silent! e %' end, 0) end, - config = override_req("lspconfig", "plugins.configs.lspconfig"), + config = function() + require "plugins.configs.lspconfig" + end, }, - { - "ray-x/lsp_signature.nvim", - disable = not plugin_settings.status.lspsignature, + ["ray-x/lsp_signature.nvim"] = { after = "nvim-lspconfig", - config = override_req("signature", "plugins.configs.others", "signature"), + config = function() + require("plugins.configs.others").signature() + end, }, - { - "andymass/vim-matchup", - disable = not plugin_settings.status.vim_matchup, + ["andymass/vim-matchup"] = { opt = true, setup = function() require("core.utils").packer_lazy_load "vim-matchup" end, }, - { - "max397574/better-escape.nvim", - disable = not plugin_settings.status.better_escape, + ["max397574/better-escape.nvim"] = { event = "InsertCharPre", - config = override_req("better_escape", "plugins.configs.others", "better_escape"), + config = function() + require("plugins.configs.others").better_escape() + end, }, -- load luasnips + cmp related in insert mode only - { - "rafamadriz/friendly-snippets", + ["rafamadriz/friendly-snippets"] = { module = "cmp_nvim_lsp", - disable = not plugin_settings.status.cmp, event = "InsertEnter", }, - { - "hrsh7th/nvim-cmp", - disable = not plugin_settings.status.cmp, + ["hrsh7th/nvim-cmp"] = { after = "friendly-snippets", - config = override_req("nvim_cmp", "plugins.configs.cmp", "setup"), + config = function() + require "plugins.configs.cmp" + end, }, - { - "L3MON4D3/LuaSnip", - disable = not plugin_settings.status.cmp, + ["L3MON4D3/LuaSnip"] = { wants = "friendly-snippets", after = "nvim-cmp", - config = override_req("luasnip", "plugins.configs.others", "luasnip"), + config = function() + require("plugins.configs.others").luasnip() + end, }, - { - "saadparwaiz1/cmp_luasnip", - disable = not plugin_settings.status.cmp, - after = plugin_settings.options.cmp.lazy_load and "LuaSnip", + ["saadparwaiz1/cmp_luasnip"] = { + after = "LuaSnip", }, - { - "hrsh7th/cmp-nvim-lua", - disable = not plugin_settings.status.cmp, + ["hrsh7th/cmp-nvim-lua"] = { after = "cmp_luasnip", }, - { - "hrsh7th/cmp-nvim-lsp", - disable = not plugin_settings.status.cmp, + ["hrsh7th/cmp-nvim-lsp"] = { after = "cmp-nvim-lua", }, - { - "hrsh7th/cmp-buffer", - disable = not plugin_settings.status.cmp, + ["hrsh7th/cmp-buffer"] = { after = "cmp-nvim-lsp", }, - { - "hrsh7th/cmp-path", - disable = not plugin_settings.status.cmp, + ["hrsh7th/cmp-path"] = { after = "cmp-buffer", }, -- misc plugins - { - "windwp/nvim-autopairs", - disable = not plugin_settings.status.autopairs, - after = plugin_settings.options.autopairs.loadAfter, - config = override_req("nvim_autopairs", "plugins.configs.others", "autopairs"), + ["windwp/nvim-autopairs"] = { + after = "nvim-cmp", + config = function() + require("plugins.configs.others").autopairs() + end, }, - { - disable = not plugin_settings.status.alpha, - "goolord/alpha-nvim", - config = override_req("alpha", "plugins.configs.alpha", "setup"), + ["goolord/alpha-nvim"] = { + disable = true, + config = function() + require "plugins.configs.alpha" + end, }, - { - "numToStr/Comment.nvim", - disable = not plugin_settings.status.comment, + ["numToStr/Comment.nvim"] = { module = "Comment", keys = { "gcc" }, - config = override_req("nvim_comment", "plugins.configs.others", "comment"), + setup = function() require("core.mappings").comment() end, + + config = function() + require("plugins.configs.others").comment() + end, }, -- file managing , picker etc - { - "kyazdani42/nvim-tree.lua", - disable = not plugin_settings.status.nvimtree, - -- only set "after" if lazy load is disabled and vice versa for "cmd" - after = not plugin_settings.options.nvimtree.lazy_load and "nvim-web-devicons", - cmd = plugin_settings.options.nvimtree.lazy_load and { "NvimTreeToggle", "NvimTreeFocus" }, - config = override_req("nvim_tree", "plugins.configs.nvimtree", "setup"), + ["kyazdani42/nvim-tree.lua"] = { + cmd = { "NvimTreeToggle", "NvimTreeFocus" }, + setup = function() require("core.mappings").nvimtree() end, + + config = function() + require "plugins.configs.nvimtree" + end, }, - { - "nvim-telescope/telescope.nvim", + ["nvim-telescope/telescope.nvim"] = { module = "telescope", cmd = "Telescope", - config = override_req("telescope", "plugins.configs.telescope", "setup"), + setup = function() require("core.mappings").telescope() end, + + config = function() + require "plugins.configs.telescope" + end, }, } ---label plugins for operational assistance -plugins = require("core.utils").label_plugins(plugins) ---remove plugins specified in chadrc -plugins = require("core.utils").remove_default_plugins(plugins) ---add plugins specified in chadrc -plugins = require("core.utils").add_user_plugins(plugins) +-- merge user plugin table & default plugin table +plugins = require("core.utils").plugin_list(plugins) return packer.startup(function(use) for _, v in pairs(plugins) do