From c8a27d701c5f119a97a2ae619a3138638592ed21 Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 13 Nov 2021 21:59:31 +0530 Subject: [PATCH 01/20] cleanup! --- lua/core/custom.lua | 23 +++------------- lua/core/hooks.lua | 44 ++++--------------------------- lua/core/init.lua | 4 --- lua/core/options.lua | 3 --- lua/core/utils.lua | 2 +- lua/plugins/configs/lspconfig.lua | 8 +----- 6 files changed, 10 insertions(+), 74 deletions(-) diff --git a/lua/core/custom.lua b/lua/core/custom.lua index c058061..44c1696 100644 --- a/lua/core/custom.lua +++ b/lua/core/custom.lua @@ -1,22 +1,5 @@ -local function isModuleAvailable(name) - if package.loaded[name] then - return true - else - for _, searcher in ipairs(package.searchers or package.loaders) do - local loader = searcher(name) - if type(loader) == "function" then - package.preload[name] = loader - return true - end - end - return false - end -end +local moduleExists = pcall(require, "custom") -local loadIfExists = function(module) - if isModuleAvailable(module) then - require(module) - end +if moduleExists then + require "custom" end - -loadIfExists "custom" diff --git a/lua/core/hooks.lua b/lua/core/hooks.lua index 2602ff7..af70156 100644 --- a/lua/core/hooks.lua +++ b/lua/core/hooks.lua @@ -1,4 +1,4 @@ -local hooks, overrides, M = {}, {}, {} +local hooks, M = {}, {} local allowed_hooks = { "install_plugins", "setup_mappings", @@ -11,13 +11,11 @@ local function has_value(tab, val) return true end end - - return false end M.add = function(name, fn) if not (has_value(allowed_hooks, name)) then - error("Custom lua uses unallowed hook " .. name) + print("Custom lua uses unallowed hook " .. name) end if hooks[name] == nil then hooks[name] = {} @@ -26,43 +24,11 @@ M.add = function(name, fn) end M.run = function(name, args) - if hooks[name] == nil then - return - end - - for _, hook in pairs(hooks[name]) do - hook(args) - end -end - -M.createOverrides = function(module) - local O = {} - - O.get = function(name, default) - local current = default - if overrides[module] and overrides[module][name] then - if type(overrides[module][name]) == "function" then - current = overrides[module][name] - elseif type(overrides[module][name]) == "table" then - for _, override in pairs(overrides[module][name]) do - current = override(current) - end - end + if hooks[name] ~= nil then + for _, hook in pairs(hooks[name]) do + hook(args) end - return current end - - return O -end - -M.override = function(module, name, overwrite) - if overrides[module] == nil then - overrides[module] = {} - end - if overrides[module][name] == nil then - overrides[module][name] = {} - end - table.insert(overrides[module][name], overwrite) end return M diff --git a/lua/core/init.lua b/lua/core/init.lua index dc1198c..634087f 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -5,8 +5,6 @@ local core_modules = { "core.mappings", } -local hooks = require "core.hooks" - for _, module in ipairs(core_modules) do local ok, err = pcall(require, module) if not ok then @@ -16,5 +14,3 @@ end -- set all the non plugin mappings require("core.mappings").misc() - -hooks.run "ready" diff --git a/lua/core/options.lua b/lua/core/options.lua index 2438b16..5be456d 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -1,9 +1,6 @@ local opt = vim.opt local g = vim.g --- export user config as a global varibale -g.nvchad_user_config = "chadrc" - local options = require("core.utils").load_config().options opt.title = true diff --git a/lua/core/utils.lua b/lua/core/utils.lua index e9fbd1f..d7fa99b 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -154,7 +154,7 @@ M.load_config = function(reload) } local default_config = "core.default_config" - local config_name = vim.g.nvchad_user_config or "chadrc" + local config_name = "chadrc" local config_file = vim.fn.stdpath "config" .. "/lua/custom/" .. config_name .. ".lua" -- unload the modules if force reload diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index be12585..76fe1b0 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -1,5 +1,3 @@ -local overrides = require("core.hooks").createOverrides "lsp" - local function on_attach(_, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) @@ -62,7 +60,7 @@ lspSymbol("Information", "") lspSymbol("Hint", "") lspSymbol("Warning", "") -local lsp_publish_diagnostics_options = overrides.get("publish_diagnostics", { +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = { prefix = "", spacing = 0, @@ -71,10 +69,6 @@ local lsp_publish_diagnostics_options = overrides.get("publish_diagnostics", { underline = true, update_in_insert = false, -- update diagnostics insert mode }) -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, - lsp_publish_diagnostics_options -) vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "single", }) From b4c50fa443279095f648630709400d38f1cb9809 Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 13 Nov 2021 22:26:38 +0530 Subject: [PATCH 02/20] misc change in override function --- lua/plugins/init.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 283d05c..078233d 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -15,11 +15,9 @@ return packer.startup(function() -- if override or default_req start with `(`, then strip that and assume override calls a function, not a whole file local override_req = function(name, default_req) local override = require("core.utils").load_config().plugins.default_plugin_config_replace[name] - local result + local result = default_req - if override == nil then - result = default_req - else + if override ~= nil then result = override end From a256591e90cafdf397db7c1739c96837facc1fcc Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 13 Nov 2021 23:07:20 +0530 Subject: [PATCH 03/20] move plugin override function to utils | increase packer clone timeout --- lua/core/utils.lua | 23 +++++++++++++++++++++++ lua/plugins/init.lua | 33 ++++----------------------------- lua/plugins/packerInit.lua | 9 +++------ 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/lua/core/utils.lua b/lua/core/utils.lua index d7fa99b..d3e0df5 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -356,4 +356,27 @@ 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 + +-- FUNCTION: override_req, use `chadrc` plugin config override if present +-- name = name inside `default_config` / `chadrc` +-- default_req = run this if 'name' does not exist in `default_config` / `chadrc` +-- if override or default_req start with `(`, then strip that and assume override calls a function, not a whole file +M.override_req = function(name, default_req) + local override = require("core.utils").load_config().plugins.default_plugin_config_replace[name] + local result = default_req + + if override ~= nil then + result = override + end + + if string.match(result, "^%(") then + result = result:sub(2) + result = result:gsub("%)%.", "').", 1) + return "require('" .. result + else + return "require('" .. result .. "')" + end +end + return M diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 078233d..39a3c14 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -8,38 +8,13 @@ local use = packer.use return packer.startup(function() local plugin_settings = require("core.utils").load_config().plugins - - -- FUNCTION: override_req, use `chadrc` plugin config override if present - -- name = name inside `default_config` / `chadrc` - -- default_req = run this if 'name' does not exist in `default_config` / `chadrc` - -- if override or default_req start with `(`, then strip that and assume override calls a function, not a whole file - local override_req = function(name, default_req) - local override = require("core.utils").load_config().plugins.default_plugin_config_replace[name] - local result = default_req - - if override ~= nil then - result = override - end - - if string.match(result, "^%(") then - result = result:sub(2) - result = result:gsub("%)%.", "').", 1) - return "require('" .. result - else - return "require('" .. result .. "')" - end - end + local override_req = require("core.utils").override_req -- this is arranged on the basis of when a plugin starts -- this is the nvchad core repo containing utilities for some features like theme swticher, no need to lazy load - use { - "Nvchad/extensions", - } - - use { - "nvim-lua/plenary.nvim", - } + use "Nvchad/extensions" + use "nvim-lua/plenary.nvim" use { "wbthomason/packer.nvim", @@ -259,6 +234,6 @@ return packer.startup(function() require("core.mappings").telescope() end, } - + -- load user defined plugins require("core.hooks").run("install_plugins", use) end) diff --git a/lua/plugins/packerInit.lua b/lua/plugins/packerInit.lua index 964ff59..cafdd4f 100644 --- a/lua/plugins/packerInit.lua +++ b/lua/plugins/packerInit.lua @@ -1,6 +1,4 @@ -local cmd = vim.cmd - -cmd "packadd packer.nvim" +vim.cmd "packadd packer.nvim" local present, packer = pcall(require, "packer") @@ -19,7 +17,7 @@ if not present then packer_path, } - cmd "packadd packer.nvim" + vim.cmd "packadd packer.nvim" present, packer = pcall(require, "packer") if present then @@ -37,11 +35,10 @@ packer.init { prompt_border = "single", }, git = { - clone_timeout = 600, -- Timeout, in seconds, for git clones + clone_timeout = 6000, -- seconds }, auto_clean = true, compile_on_sync = true, - -- auto_reload_compiled = true } return packer From 8de3f4e84c5f4c41db3b3142734929cc89ed5b45 Mon Sep 17 00:00:00 2001 From: siduck Date: Sun, 14 Nov 2021 06:49:33 +0530 Subject: [PATCH 04/20] restructure init.lua | lspconfig --- init.lua | 22 ++++++++++++++--- lua/core/custom.lua | 5 ---- lua/core/init.lua | 16 ------------ lua/core/utils.lua | 18 +++++++------- lua/plugins/configs/lspconfig.lua | 41 ++----------------------------- lua/plugins/configs/others.lua | 39 +++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 72 deletions(-) delete mode 100644 lua/core/custom.lua delete mode 100644 lua/core/init.lua diff --git a/init.lua b/init.lua index 6ea9843..23322bd 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,21 @@ -local ok, err = pcall(require, "core") +local userconf = pcall(require, "custom") -if not ok then - error("Error loading core" .. "\n\n" .. err) +if userconf then + require "custom" end + +local core_modules = { + "core.options", + "core.autocmds", + "core.mappings", +} + +for _, module in ipairs(core_modules) do + local ok, err = pcall(require, module) + if not ok then + error("Error loading " .. module .. "\n\n" .. err) + end +end + +-- non plugin mappings +require("core.mappings").misc() diff --git a/lua/core/custom.lua b/lua/core/custom.lua deleted file mode 100644 index 44c1696..0000000 --- a/lua/core/custom.lua +++ /dev/null @@ -1,5 +0,0 @@ -local moduleExists = pcall(require, "custom") - -if moduleExists then - require "custom" -end diff --git a/lua/core/init.lua b/lua/core/init.lua deleted file mode 100644 index 634087f..0000000 --- a/lua/core/init.lua +++ /dev/null @@ -1,16 +0,0 @@ -local core_modules = { - "core.custom", - "core.options", - "core.autocmds", - "core.mappings", -} - -for _, module in ipairs(core_modules) do - local ok, err = pcall(require, module) - if not ok then - error("Error loading " .. module .. "\n\n" .. err) - end -end - --- set all the non plugin mappings -require("core.mappings").misc() diff --git a/lua/core/utils.lua b/lua/core/utils.lua index d3e0df5..37ffa68 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -258,13 +258,13 @@ M.merge_table = function(into, from, nodes_to_replace) -- function that will be executed with loadstring local replace_fn = function(node) local base_fn = [[ -return function(table1, table2) - local t1, t2 = table1_node or false , table2_node or false - if t1 and t2 then - table1_node = table2_node - end - return table1 -end]] + return function(table1, table2) + local t1, t2 = table1_node or false , table2_node or false + if t1 and t2 then + table1_node = table2_node + end + return table1 + end]] -- replace the _node in base_fn to actual given node value local fn = base_fn:gsub("_node", node) @@ -374,9 +374,9 @@ M.override_req = function(name, default_req) result = result:sub(2) result = result:gsub("%)%.", "').", 1) return "require('" .. result - else - return "require('" .. result .. "')" end + + return "require('" .. result .. "')" end return M diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index 76fe1b0..391a9fb 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -50,48 +50,11 @@ capabilities.textDocument.completion.completionItem.resolveSupport = { }, } --- replace the default lsp diagnostic symbols -local function lspSymbol(name, icon) - vim.fn.sign_define("LspDiagnosticsSign" .. name, { text = icon, numhl = "LspDiagnosticsDefault" .. name }) -end - -lspSymbol("Error", "") -lspSymbol("Information", "") -lspSymbol("Hint", "") -lspSymbol("Warning", "") - -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = { - prefix = "", - spacing = 0, - }, - signs = true, - underline = true, - update_in_insert = false, -- update diagnostics insert mode -}) -vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { - border = "single", -}) -vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = "single", -}) - --- suppress error messages from lang servers -vim.notify = function(msg, log_level, _opts) - if msg:match "exit code" then - return - end - if log_level == vim.log.levels.ERROR then - vim.api.nvim_err_writeln(msg) - else - vim.api.nvim_echo({ { msg } }, true, {}) - end -end - -- requires a file containing user's lspconfigs - local addlsp_confs = require("core.utils").load_config().plugins.options.lspconfig.setup_lspconf if #addlsp_confs ~= 0 then require(addlsp_confs).setup_lsp(on_attach, capabilities) end + +require("plugins.configs.others").lsp_handlers() diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index af24c60..9a55fab 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -107,4 +107,43 @@ M.signature = function() end end +M.lsp_handlers = function() + local function lspSymbol(name, icon) + vim.fn.sign_define("LspDiagnosticsSign" .. name, { text = icon, numhl = "LspDiagnosticsDefault" .. name }) + end + + lspSymbol("Error", "") + lspSymbol("Information", "") + lspSymbol("Hint", "") + lspSymbol("Warning", "") + + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = { + prefix = "", + spacing = 0, + }, + signs = true, + underline = true, + update_in_insert = false, -- update diagnostics insert mode + }) + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "single", + }) + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = "single", + }) + + -- suppress error messages from lang servers + vim.notify = function(msg, log_level, _opts) + if msg:match "exit code" then + return + end + if log_level == vim.log.levels.ERROR then + vim.api.nvim_err_writeln(msg) + else + vim.api.nvim_echo({ { msg } }, true, {}) + end + end +end + return M From 5db36d44fb632e2d996721c3f8451fcda105359c Mon Sep 17 00:00:00 2001 From: siduck Date: Sun, 14 Nov 2021 06:57:49 +0530 Subject: [PATCH 05/20] restructure highlights.lua --- lua/colors/highlights.lua | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index c16675d..895a929 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -1,8 +1,8 @@ -local override = require("core.utils").load_config().ui.hl_override - local cmd = vim.cmd +local override = require("core.utils").load_config().ui.hl_override local colors = require("colors").get() +local ui = require("core.utils").load_config().ui local black = colors.black local black2 = colors.black2 @@ -23,8 +23,7 @@ local white = colors.white local yellow = colors.yellow local one_bg3 = colors.one_bg3 -local ui = require("core.utils").load_config().ui - +-- functions for setting highlights local fg = require("core.utils").fg local fg_bg = require("core.utils").fg_bg local bg = require("core.utils").bg @@ -126,20 +125,20 @@ fg("NvimTreeVertSplit", darker_black) bg("NvimTreeVertSplit", darker_black) fg_bg("NvimTreeWindowPicker", red, black2) --- Disable some highlight in nvim tree if transparency enabled -if ui.transparency then - bg("NvimTreeNormal", "NONE") - bg("NvimTreeStatusLineNC", "NONE") - bg("NvimTreeVertSplit", "NONE") - fg("NvimTreeVertSplit", grey) -end - -- Telescope fg("TelescopeBorder", one_bg) fg_bg("TelescopePreviewTitle", green, one_bg) fg_bg("TelescopePromptTitle", blue, one_bg) fg_bg("TelescopeResultsTitle", red, one_bg) +-- Disable some highlight in nvim tree if transparency enabled +if ui.transparency then + bg("NvimTreeNormal", "NONE") + bg("NvimTreeStatusLineNC", "NONE") + bg("NvimTreeVertSplit", "NONE") + fg("NvimTreeVertSplit", grey) + end + if #override ~= 0 then require(override) end From bdd6dc12c27208ed34af6948eec5f7d20a2b16b1 Mon Sep 17 00:00:00 2001 From: siduck Date: Sun, 14 Nov 2021 12:43:36 +0530 Subject: [PATCH 06/20] restructure | clean default_config --- lua/core/default_config.lua | 127 ++++++++++++++++++++---------------- lua/core/hooks.lua | 1 + lua/core/mappings.lua | 16 ++--- lua/core/utils.lua | 9 ++- 4 files changed, 83 insertions(+), 70 deletions(-) diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index 9b087cf..fde5bd9 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -4,9 +4,10 @@ local M = {} M.options, M.ui, M.mappings, M.plugins = {}, {}, {}, {} --- non plugin normal, available without any plugins M.options = { - -- NeoVim/Vim options + -- custom = {} + -- general nvim/vim options , check :h optionname to know more about an option + clipboard = "unnamedplus", cmdheight = 1, ruler = false, @@ -16,17 +17,16 @@ M.options = { mapleader = " ", mouse = "a", number = true, - -- relative numbers in normal mode tool at the bottom of options.lua numberwidth = 2, relativenumber = false, expandtab = true, shiftwidth = 2, smartindent = true, - tabstop = 8, -- Number of spaces that a in the file counts for + tabstop = 8, timeoutlen = 400, - -- interval for writing swap file to disk, also used by gitsigns updatetime = 250, - undofile = true, -- keep a permanent undo (across restarts) + undofile = true, + -- NvChad options nvChad = { copy_cut = true, -- copy cut text ( x key ), visual and normal mode @@ -34,43 +34,46 @@ M.options = { insert_nav = true, -- navigation in insertmode window_nav = true, theme_toggler = false, - -- used for updater + + -- updater update_url = "https://github.com/NvChad/NvChad", update_branch = "main", }, } --- ui configs +---- UI ----- + M.ui = { - hl_override = "", -- path of your file which contains highlight stuffs + hl_override = "", -- path of your file that contains highlights italic_comments = false, - -- theme to be used, check available themes with ` + t + h` - theme = "onedark", + theme = "onedark", -- default theme -- toggle between two themes, see theme_toggler mappings theme_toggler = { "onedark", "gruvchad", }, - -- Enable this only if your terminal has the colorscheme set which nvchad uses + + -- 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, } --- these are plugin related options +---- PLUGIN OPTIONS ---- + M.plugins = { - -- enable and disable plugins (false for disable) + -- enable/disable plugins (false for disable) status = { - blankline = true, -- show code scope with symbols - bufferline = true, -- list open buffers up the top, easy switching too + 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 - dashboard = false, -- NeoVim 'home screen' on open + dashboard = false, esc_insertmode = true, -- map to with no lag feline = true, -- statusline - gitsigns = true, -- gitsigns in statusline + gitsigns = true, lspsignature = true, -- lsp enhancements - telescope_media = false, -- media previews within telescope finders - vim_matchup = true, -- % operator enhancements + telescope_media = false, + vim_matchup = true, -- improved matchit cmp = true, nvimtree = true, autopairs = true, @@ -86,39 +89,46 @@ M.plugins = { luasnip = { snippet_path = {}, }, - statusline = { -- statusline related options - -- these are filetypes, not pattern matched - -- shown filetypes will overrule hidden filetypes + statusline = { + -- hide, show on specific filetypes hidden = { "help", "dashboard", "NvimTree", "terminal", }, - -- show short statusline on small screens - shortline = true, shown = {}, - -- default, round , slant , block , arrow - style = "default", + + -- truncate statusline on small screens + shortline = true, + style = "default", -- default, round , slant , block , arrow }, esc_insertmode_timeout = 300, }, default_plugin_config_replace = {}, } --- mappings -- don't use a single keymap twice -- --- non plugin mappings +-- Don't use a single keymap twice + +--- MAPPINGS ---- + +-- non plugin M.mappings = { - -- custom = {}, -- all custom user mappings - -- close current focused buffer - close_buffer = "x", - copy_whole_file = "", -- copy all contents of the current buffer - line_number_toggle = "n", -- show or hide line number - new_buffer = "", -- open a new buffer - new_tab = "b", -- open a new vim tab - save_file = "", -- save file using :w - theme_toggler = "tt", -- for theme toggler, see in ui.theme_toggler + -- custom = {}, -- custom user mappings + + misc = { + close_buffer = "x", + copy_whole_file = "", -- copy all contents of current buffer + line_number_toggle = "n", -- toggle line number + update_nvchad = "uu", + new_buffer = "", + new_tab = "b", + save_file = "", -- save file using :w + theme_toggler = "tt", -- see in ui.theme_toggler + }, + -- navigation in insert mode, only if enabled in options + insert_nav = { backward = "", end_of_line = "", @@ -127,60 +137,63 @@ M.mappings = { prev_line = "", beginning_of_line = "", }, - --better window movement + + -- better window movement window_nav = { moveLeft = "", moveRight = "", moveUp = "", moveDown = "", }, + -- terminal related mappings terminal = { - -- multiple mappings can be given for esc_termmode and esc_hide_termmode + -- multiple mappings can be given for esc_termmode, esc_hide_termmode + -- get out of terminal mode - esc_termmode = { "jk" }, -- multiple mappings allowed + esc_termmode = { "jk" }, + -- get out of terminal mode and hide it - esc_hide_termmode = { "JK" }, -- multiple mappings allowed + esc_hide_termmode = { "JK" }, -- show & recover hidden terminal buffers in a telescope picker pick_term = "W", - -- below three are for spawning terminals + + -- spawn terminals new_horizontal = "h", new_vertical = "v", new_window = "w", }, - -- update nvchad from nvchad, chadness 101 - update_nvchad = "uu", } --- all plugins related mappings +-- plugins related mappings + M.mappings.plugins = { - -- list open buffers up the top, easy switching too bufferline = { - next_buffer = "", -- next buffer - prev_buffer = "", -- previous buffer + next_buffer = "", + prev_buffer = "", }, - -- easily (un)comment code, language aware comment = { - toggle = "/", -- toggle comment (works on multiple lines) + toggle = "/", }, - -- NeoVim 'home screen' on open + dashboard = { bookmarks = "bm", new_file = "fn", -- basically create a new buffer open = "db", -- open dashboard - session_load = "l", -- load a saved session - session_save = "s", -- save a session + session_load = "l", + session_save = "s", }, + -- map to with no lag better_escape = { -- will still work esc_insertmode = { "jk" }, -- multiple mappings allowed }, - -- file explorer/tree + nvimtree = { toggle = "", focus = "e", }, - -- multitool for finding & picking things + telescope = { buffers = "fb", find_files = "ff", @@ -191,7 +204,7 @@ M.mappings.plugins = { live_grep = "fw", oldfiles = "fo", themes = "th", -- NvChad theme picker - -- media previews within telescope finders + telescope_media = { media_files = "fp", }, diff --git a/lua/core/hooks.lua b/lua/core/hooks.lua index af70156..02394a1 100644 --- a/lua/core/hooks.lua +++ b/lua/core/hooks.lua @@ -1,4 +1,5 @@ local hooks, M = {}, {} + local allowed_hooks = { "install_plugins", "setup_mappings", diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index cf9d2a0..3e0162b 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -68,19 +68,19 @@ M.misc = function() if nvChad_options.theme_toggler then map( "n", - maps.theme_toggler, + maps.misc.theme_toggler, ":lua require('nvchad').toggle_theme(require('core.utils').load_config().ui.theme_toggler) " ) end end local function required_mappings() - map("n", maps.close_buffer, ":lua require('core.utils').close_buffer() ") -- close buffer - map("n", maps.copy_whole_file, ":%y+ ") -- copy whole file content - map("n", maps.new_buffer, ":enew ") -- new buffer - map("n", maps.new_tab, ":tabnew ") -- new tabs - map("n", maps.line_number_toggle, ":set nu! ") -- toggle numbers - map("n", maps.save_file, ":w ") -- ctrl + s to save file + map("n", maps.misc.close_buffer, ":lua require('core.utils').close_buffer() ") -- close buffer + map("n", maps.misc.copy_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.line_number_toggle, ":set nu! ") -- toggle numbers + map("n", maps.misc.save_file, ":w ") -- ctrl + s to save file -- terminal mappings -- local term_maps = maps.terminal @@ -107,7 +107,7 @@ M.misc = function() -- add NvChadUpdate command and mapping cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" - map("n", maps.update_nvchad, ":NvChadUpdate ") + map("n", maps.misc.update_nvchad, ":NvChadUpdate ") -- add ChadReload command and maping -- cmd "silent! command! NvChadReload lua require('nvchad').reload_config()" diff --git a/lua/core/utils.lua b/lua/core/utils.lua index 37ffa68..be6da90 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -154,13 +154,12 @@ M.load_config = function(reload) } local default_config = "core.default_config" - local config_name = "chadrc" - local config_file = vim.fn.stdpath "config" .. "/lua/custom/" .. config_name .. ".lua" + local config_file = vim.fn.stdpath "config" .. "/lua/custom/" .. "chadrc.lua" -- unload the modules if force reload if reload then package.loaded[default_config or false] = nil - package.loaded[config_name or false] = nil + package.loaded["chadrc" or false] = nil end -- don't enclose in pcall, it better break when default config is faulty @@ -171,7 +170,7 @@ M.load_config = function(reload) -- print warning texts if user config file is present -- check if the user config is present if vim.fn.filereadable(vim.fn.glob(config_file)) == 1 then - local present, config = pcall(require, "custom/" .. config_name) + local present, config = pcall(require, "custom/chadrc") if present then -- make sure the returned value is table if type(config) == "table" then @@ -182,7 +181,7 @@ M.load_config = function(reload) to_replace ) else - print("Warning: " .. config_name .. " sourced successfully but did not return a lua table.") + print("Warning: chadrc " .. " sourced successfully but did not return a lua table.") end else print("Warning: " .. config_file .. " is present but sourcing failed.") From e8b919723e57beb1aa8d9886dfd2447c3d925968 Mon Sep 17 00:00:00 2001 From: siduck Date: Sun, 14 Nov 2021 18:23:59 +0530 Subject: [PATCH 07/20] add cheatsheet.nvim --- lua/colors/highlights.lua | 2 +- lua/core/default_config.lua | 7 +++++ lua/core/mappings.lua | 11 ++++++++ lua/plugins/configs/cheatsheet.lua | 45 ++++++++++++++++++++++++++++++ lua/plugins/init.lua | 14 +++++++++- 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 lua/plugins/configs/cheatsheet.lua diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index 895a929..46823d2 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -137,7 +137,7 @@ if ui.transparency then bg("NvimTreeStatusLineNC", "NONE") bg("NvimTreeVertSplit", "NONE") fg("NvimTreeVertSplit", grey) - end +end if #override ~= 0 then require(override) diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index fde5bd9..91147f9 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -67,6 +67,7 @@ M.plugins = { bufferline = true, -- manage and preview opened buffers colorizer = false, -- color RGB, HEX, CSS, NAME color codes comment = true, -- easily (un)comment code, language aware + cheatsheet = true, dashboard = false, esc_insertmode = true, -- map to with no lag feline = true, -- statusline @@ -172,6 +173,12 @@ M.mappings.plugins = { next_buffer = "", prev_buffer = "", }, + + cheatsheet = { + default_keys = "dk", + user_keys = "uk", + }, + comment = { toggle = "/", }, diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 3e0162b..37a1a73 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -169,4 +169,15 @@ M.telescope_media = function() map("n", m.media_files, ":Telescope media_files ") end +M.cheatsheet = function() + local m = plugin_maps.cheatsheet + + map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope() ") + map( + "n", + m.user_keys, + ":lua require('cheatsheet').show_cheatsheet_telescope{bundled_cheatsheets = false, bundled_plugin_cheatsheets = false } " + ) +end + return M diff --git a/lua/plugins/configs/cheatsheet.lua b/lua/plugins/configs/cheatsheet.lua new file mode 100644 index 0000000..aece17c --- /dev/null +++ b/lua/plugins/configs/cheatsheet.lua @@ -0,0 +1,45 @@ +local present, cheatsheet = pcall(require, "cheatsheet") + +if not present then + return +end + +local mappings = require("core.utils").load_config().mappings + +-- add user mappings to the cheetsheet +-- improve this function to not hardcode plugin +local function add_to_cheatsheet(section, keymap, desc) + if section == "plugins" then + for sec, key in pairs(mappings.plugins) do + add_to_cheatsheet(sec, key, sec) + end + + else + if type(keymap) == "table" then + for sec, key in pairs(keymap) do + if type(sec) == "number" then + add_to_cheatsheet(section, key, desc or section) + else + add_to_cheatsheet(sec, key, desc or section) + end + end + else + cheatsheet.add_cheat(section, keymap, desc or "Misc") + end + end +end + +for section, keymap in pairs(mappings) do + add_to_cheatsheet(section, keymap) +end + +require("cheatsheet").setup { + + bundled_cheatsheets = { + enabled = { "default" }, + disabled = { "unicode", "nerd-fonts" }, + }, + + bundled_plugin_cheatsheets = false, + include_only_installed_plugins = true, +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 39a3c14..6825cf0 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -234,6 +234,18 @@ return packer.startup(function() require("core.mappings").telescope() end, } - -- load user defined plugins + + use { + "sudormrfbin/cheatsheet.nvim", + disable = not plugin_settings.status.cheatsheet, + module = "cheatsheet", + config = function() + require "plugins.configs.cheatsheet" + end, + setup = function() + require("core.mappings").cheatsheet() + end, + } + require("core.hooks").run("install_plugins", use) end) From 1567a9c73a7e1f25ca571db53cd6e430813bef37 Mon Sep 17 00:00:00 2001 From: siduck Date: Mon, 15 Nov 2021 21:39:35 +0530 Subject: [PATCH 08/20] use tbl_deep_extend to merge configs | rm other functions --- lua/core/default_config.lua | 1 - lua/core/utils.lua | 138 +++------------------------------- lua/custom/example_chadrc.lua | 37 +-------- 3 files changed, 14 insertions(+), 162 deletions(-) diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index 91147f9..c7c3ba8 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -2,7 +2,6 @@ -- use custom/chadrc.lua instead local M = {} -M.options, M.ui, M.mappings, M.plugins = {}, {}, {}, {} M.options = { -- custom = {} diff --git a/lua/core/utils.lua b/lua/core/utils.lua index be6da90..ee1002e 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -137,57 +137,21 @@ M.hide_statusline = function() end end --- load config --- 1st arg = boolean - whether to force reload --- Modifies _G._NVCHAD_CONFIG global variable M.load_config = function(reload) - -- only do the stuff below one time, otherwise just return the set config - if _G._NVCHAD_CONFIG_CONTENTS ~= nil and not (reload or false) then - return _G._NVCHAD_CONFIG_CONTENTS - end + local conf = require "core.default_config" - -- these are the table value which will be always prioritiezed to take user config value - local to_replace = { - "['mappings']['plugins']['esc_insertmode']", - "['mappings']['terminal']['esc_termmode']", - "['mappings']['terminal']['esc_hide_termmode']", - } + local chadrcExists, _ = pcall(require, "custom.chadrc") - local default_config = "core.default_config" - local config_file = vim.fn.stdpath "config" .. "/lua/custom/" .. "chadrc.lua" +-- if chadrc exists , then merge its table into the default config's - -- unload the modules if force reload - if reload then - package.loaded[default_config or false] = nil - package.loaded["chadrc" or false] = nil - end +if chadrcExists then + local change = require "custom.chadrc" + conf = vim.tbl_deep_extend("force", conf, change) + return conf +end - -- don't enclose in pcall, it better break when default config is faulty - _G._NVCHAD_CONFIG_CONTENTS = require(default_config) - - -- user config is not required to run nvchad but a optional - -- Make sure the config doesn't break the whole system if user config is not present or in bad state or not a table - -- print warning texts if user config file is present - -- check if the user config is present - if vim.fn.filereadable(vim.fn.glob(config_file)) == 1 then - local present, config = pcall(require, "custom/chadrc") - if present then - -- make sure the returned value is table - if type(config) == "table" then - -- data = require(config_name) - _G._NVCHAD_CONFIG_CONTENTS = require("core.utils").merge_table( - _G._NVCHAD_CONFIG_CONTENTS, - config, - to_replace - ) - else - print("Warning: chadrc " .. " sourced successfully but did not return a lua table.") - end - else - print("Warning: " .. config_file .. " is present but sourcing failed.") - end - end - return _G._NVCHAD_CONFIG_CONTENTS +-- or load default config + return conf end M.map = function(mode, keys, cmd, opt) @@ -238,88 +202,6 @@ M.map = function(mode, keys, cmd, opt) map_wrapper(mode, keys, cmd, options) end --- Base code: https://gist.github.com/revolucas/184aec7998a6be5d2f61b984fac1d7f7 --- Changes over it: preserving table 1 contents and also update with table b, without duplicating --- 1st arg - base table --- 2nd arg - table to merge --- 3rg arg - list of nodes as a table, if the node is found replace the from table2 to result, rather than adding the value --- e.g: merge_table(t1, t2, { ['mappings']['plugins']['bufferline'] }) -M.merge_table = function(into, from, nodes_to_replace) - -- make sure both are table - if type(into) ~= "table" or type(from) ~= "table" then - return into - end - - local stack, seen = {}, {} - local table1, table2 = into, from - - if type(nodes_to_replace) == "table" then - -- function that will be executed with loadstring - local replace_fn = function(node) - local base_fn = [[ - return function(table1, table2) - local t1, t2 = table1_node or false , table2_node or false - if t1 and t2 then - table1_node = table2_node - end - return table1 - end]] - - -- replace the _node in base_fn to actual given node value - local fn = base_fn:gsub("_node", node) - -- return the function created from the string base_fn - return loadstring(fn)()(table1, table2) - end - - for _, node in ipairs(nodes_to_replace) do - -- pcall() is a poor workaround for if "['mappings']['plugins']['esc_insertmode']" 'plugins' sub-table does not exist - local ok, result = pcall(replace_fn, node) - if ok then - -- if the node is found then replace - table1 = result - end - end - end - - while true do - for k, v in pairs(table2) do - if type(v) == "table" and type(table1[k]) == "table" then - table.insert(stack, { table1[k], table2[k] }) - else - local present = seen[v] or false - if not present then - if type(k) == "number" then - -- add the value to seen table until value is found - -- only do when key is number we just want to append to subtables - -- todo: maybe improve this - - for _, value in pairs(table1) do - if value == v then - present = true - break - end - end - seen[v] = true - if not present then - table1[#table1 + 1] = v - end - else - table1[k] = v - end - end - end - end - if #stack > 0 then - local t = stack[#stack] - table1, table2 = t[1], t[2] - stack[#stack] = nil - else - break - end - end - return into -end - -- load plugin after entering vim ui M.packer_lazy_load = function(plugin, timer) if plugin then diff --git a/lua/custom/example_chadrc.lua b/lua/custom/example_chadrc.lua index 02d5566..f503361 100644 --- a/lua/custom/example_chadrc.lua +++ b/lua/custom/example_chadrc.lua @@ -1,39 +1,10 @@ --- IMPORTANT NOTE : This is the user config, can be edited. Will be preserved if updated with internal updater --- This file is for NvChad options & tools, custom settings are split between here and 'lua/custom/init.lua' - local M = {} -M.options, M.ui, M.mappings, M.plugins = {}, {}, {}, {} --- NOTE: To use this, make a copy with `cp example_chadrc.lua chadrc.lua` +-- make sure you maintain the structure of `core/default_config.lua` here, +-- example of changing theme: --------------------------------------------------------------------- - --- To use this file, copy the structure of `core/default_config.lua`, --- examples of setting relative number & changing theme: - --- M.options = { --- relativenumber = true, --- } - --- M.ui = { --- theme = "nord" --- } - --- NvChad included plugin options & overrides -M.plugins = { - options = { - -- lspconfig = { - -- path of file containing setups of different lsps (ex : "custom.plugins.lspconfig"), read the docs for more info - -- setup_lspconf = "", - -- }, - }, - -- To change the Packer `config` of a plugin that comes with NvChad, - -- add a table entry below matching the plugin github name - -- '-' -> '_', remove any '.lua', '.nvim' extensions - -- this string will be called in a `require` - -- use "(custom.configs).my_func()" to call a function - -- use "custom.blankline" to call a file - default_plugin_config_replace = {}, +M.ui = { + theme = "gruvchad", } return M From aa9667a5de855c271eab255e87d3d0b40d337235 Mon Sep 17 00:00:00 2001 From: siduck Date: Mon, 15 Nov 2021 22:51:51 +0530 Subject: [PATCH 09/20] Revert "add cheatsheet.nvim" This reverts commit e8b919723e57beb1aa8d9886dfd2447c3d925968. --- lua/colors/highlights.lua | 2 +- lua/core/default_config.lua | 7 ----- lua/core/mappings.lua | 11 -------- lua/plugins/configs/cheatsheet.lua | 45 ------------------------------ lua/plugins/init.lua | 14 +--------- 5 files changed, 2 insertions(+), 77 deletions(-) delete mode 100644 lua/plugins/configs/cheatsheet.lua diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index 46823d2..895a929 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -137,7 +137,7 @@ if ui.transparency then bg("NvimTreeStatusLineNC", "NONE") bg("NvimTreeVertSplit", "NONE") fg("NvimTreeVertSplit", grey) -end + end if #override ~= 0 then require(override) diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index c7c3ba8..6c73a9d 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -66,7 +66,6 @@ M.plugins = { bufferline = true, -- manage and preview opened buffers colorizer = false, -- color RGB, HEX, CSS, NAME color codes comment = true, -- easily (un)comment code, language aware - cheatsheet = true, dashboard = false, esc_insertmode = true, -- map to with no lag feline = true, -- statusline @@ -172,12 +171,6 @@ M.mappings.plugins = { next_buffer = "", prev_buffer = "", }, - - cheatsheet = { - default_keys = "dk", - user_keys = "uk", - }, - comment = { toggle = "/", }, diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 37a1a73..3e0162b 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -169,15 +169,4 @@ M.telescope_media = function() map("n", m.media_files, ":Telescope media_files ") end -M.cheatsheet = function() - local m = plugin_maps.cheatsheet - - map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope() ") - map( - "n", - m.user_keys, - ":lua require('cheatsheet').show_cheatsheet_telescope{bundled_cheatsheets = false, bundled_plugin_cheatsheets = false } " - ) -end - return M diff --git a/lua/plugins/configs/cheatsheet.lua b/lua/plugins/configs/cheatsheet.lua deleted file mode 100644 index aece17c..0000000 --- a/lua/plugins/configs/cheatsheet.lua +++ /dev/null @@ -1,45 +0,0 @@ -local present, cheatsheet = pcall(require, "cheatsheet") - -if not present then - return -end - -local mappings = require("core.utils").load_config().mappings - --- add user mappings to the cheetsheet --- improve this function to not hardcode plugin -local function add_to_cheatsheet(section, keymap, desc) - if section == "plugins" then - for sec, key in pairs(mappings.plugins) do - add_to_cheatsheet(sec, key, sec) - end - - else - if type(keymap) == "table" then - for sec, key in pairs(keymap) do - if type(sec) == "number" then - add_to_cheatsheet(section, key, desc or section) - else - add_to_cheatsheet(sec, key, desc or section) - end - end - else - cheatsheet.add_cheat(section, keymap, desc or "Misc") - end - end -end - -for section, keymap in pairs(mappings) do - add_to_cheatsheet(section, keymap) -end - -require("cheatsheet").setup { - - bundled_cheatsheets = { - enabled = { "default" }, - disabled = { "unicode", "nerd-fonts" }, - }, - - bundled_plugin_cheatsheets = false, - include_only_installed_plugins = true, -} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 6825cf0..39a3c14 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -234,18 +234,6 @@ return packer.startup(function() require("core.mappings").telescope() end, } - - use { - "sudormrfbin/cheatsheet.nvim", - disable = not plugin_settings.status.cheatsheet, - module = "cheatsheet", - config = function() - require "plugins.configs.cheatsheet" - end, - setup = function() - require("core.mappings").cheatsheet() - end, - } - + -- load user defined plugins require("core.hooks").run("install_plugins", use) end) From 3330d1cc06f79625c01f6eb4b3d01ec9a42985d6 Mon Sep 17 00:00:00 2001 From: siduck Date: Wed, 17 Nov 2021 11:00:57 +0530 Subject: [PATCH 10/20] clean up! --- lua/colors/highlights.lua | 10 +++--- lua/colors/init.lua | 4 +-- lua/core/mappings.lua | 3 -- lua/core/utils.lua | 20 +++++------ lua/plugins/configs/bufferline.lua | 9 +++-- lua/plugins/configs/cmp.lua | 9 ++--- lua/plugins/configs/gitsigns.lua | 34 ------------------ lua/plugins/configs/lspkind_icons.lua | 6 ++-- lua/plugins/configs/nvimtree.lua | 8 ++--- lua/plugins/configs/others.lua | 51 ++++++++++++++++----------- lua/plugins/configs/statusline.lua | 11 +++--- lua/plugins/configs/telescope.lua | 1 + lua/plugins/configs/treesitter.lua | 1 + lua/plugins/init.lua | 2 +- 14 files changed, 68 insertions(+), 101 deletions(-) delete mode 100644 lua/plugins/configs/gitsigns.lua diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index 895a929..d460a64 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -82,9 +82,11 @@ fg("DashboardHeader", grey_fg) fg("DashboardShortcut", grey_fg) -- Git signs -fg_bg("DiffAdd", nord_blue, "none") -fg_bg("DiffChange", grey_fg, "none") -fg_bg("DiffModified", nord_blue, "none") +fg_bg("DiffAdd", blue, "NONE") +fg_bg("DiffChange", grey_fg, "NONE") +fg_bg("DiffChangeDelete", red, "NONE") +fg_bg("DiffModified", red, "NONE") +fg_bg("DiffDelete", red, "NONE") -- Indent blankline plugin fg("IndentBlanklineChar", line) @@ -137,7 +139,7 @@ if ui.transparency then bg("NvimTreeStatusLineNC", "NONE") bg("NvimTreeVertSplit", "NONE") fg("NvimTreeVertSplit", grey) - end +end if #override ~= 0 then require(override) diff --git a/lua/colors/init.lua b/lua/colors/init.lua index 3b23c86..1de4a62 100644 --- a/lua/colors/init.lua +++ b/lua/colors/init.lua @@ -19,9 +19,7 @@ M.init = function(theme) package.loaded["colors.highlights" or false] = nil -- then load the highlights require "colors.highlights" - else - return false - end + end end -- returns a table of colors for givem or current theme diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 3e0162b..e192ea5 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -108,9 +108,6 @@ M.misc = function() -- add NvChadUpdate command and mapping cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" map("n", maps.misc.update_nvchad, ":NvChadUpdate ") - - -- add ChadReload command and maping - -- cmd "silent! command! NvChadReload lua require('nvchad').reload_config()" end non_config_mappings() diff --git a/lua/core/utils.lua b/lua/core/utils.lua index ee1002e..41c70e1 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -132,25 +132,25 @@ M.hide_statusline = function() if vim.tbl_contains(hidden, buftype) then api.nvim_set_option("laststatus", 0) return - else - api.nvim_set_option("laststatus", 2) end + + api.nvim_set_option("laststatus", 2) end -M.load_config = function(reload) +M.load_config = function() local conf = require "core.default_config" local chadrcExists, _ = pcall(require, "custom.chadrc") --- if chadrc exists , then merge its table into the default config's + -- if chadrc exists , then merge its table into the default config's -if chadrcExists then - local change = require "custom.chadrc" - conf = vim.tbl_deep_extend("force", conf, change) - return conf -end + if chadrcExists then + local change = require "custom.chadrc" + conf = vim.tbl_deep_extend("force", conf, change) + return conf + end --- or load default config + -- or load default config return conf end diff --git a/lua/plugins/configs/bufferline.lua b/lua/plugins/configs/bufferline.lua index cda1a7a..a396ed4 100644 --- a/lua/plugins/configs/bufferline.lua +++ b/lua/plugins/configs/bufferline.lua @@ -10,7 +10,6 @@ bufferline.setup { offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, buffer_close_icon = "", modified_icon = "", - -- close_icon = "%@NvChad_bufferline_quitvim@%X", close_icon = "", show_close_icon = true, left_trunc_marker = "", @@ -24,7 +23,7 @@ bufferline.setup { show_buffer_close_icons = true, separator_style = "thin", always_show_bufferline = true, - diagnostics = false, -- "or nvim_lsp" + diagnostics = false, custom_filter = function(buf_number) -- Func to filter out our managed/persistent split terms local present_type, type = pcall(function() @@ -36,12 +35,11 @@ bufferline.setup { return false elseif type == "hori" then return false - else - return true end - else return true end + + return true end, }, @@ -121,6 +119,7 @@ bufferline.setup { guifg = colors.black2, guibg = colors.black2, }, + -- tabs tab = { guifg = colors.light_grey, diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index eab3bd2..80e2df4 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -6,7 +6,6 @@ end vim.opt.completeopt = "menuone,noselect" --- nvim-cmp setup cmp.setup { snippet = { expand = function(args) @@ -15,12 +14,8 @@ cmp.setup { }, formatting = { format = function(entry, vim_item) - -- load lspkind icons - vim_item.kind = string.format( - "%s %s", - require("plugins.configs.lspkind_icons").icons[vim_item.kind], - vim_item.kind - ) + local icons = require "plugins.configs.lspkind_icons" + vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) vim_item.menu = ({ nvim_lsp = "[LSP]", diff --git a/lua/plugins/configs/gitsigns.lua b/lua/plugins/configs/gitsigns.lua deleted file mode 100644 index f2b58f6..0000000 --- a/lua/plugins/configs/gitsigns.lua +++ /dev/null @@ -1,34 +0,0 @@ -local present, gitsigns = pcall(require, "gitsigns") -if not present then - return -end - -gitsigns.setup { - keymaps = { - -- Default keymap options - buffer = true, - noremap = true, - ["n ]c"] = { expr = true, "&diff ? ']c' : 'lua require\"gitsigns\".next_hunk()'" }, - ["n [c"] = { expr = true, "&diff ? '[c' : 'lua require\"gitsigns\".prev_hunk()'" }, - ["n hs"] = 'lua require"gitsigns".stage_hunk()', - ["n hu"] = 'lua require"gitsigns".undo_stage_hunk()', - ["n hr"] = 'lua require"gitsigns".reset_hunk()', - ["n hp"] = 'lua require"gitsigns".preview_hunk()', - ["n hb"] = 'lua require"gitsigns".blame_line()', - }, - numhl = false, - - sign_priority = 5, - signs = { - add = { hl = "DiffAdd", text = "│", numhl = "GitSignsAddNr" }, - change = { hl = "DiffChange", text = "│", numhl = "GitSignsChangeNr" }, - changedelete = { hl = "DiffChange", text = "~", numhl = "GitSignsChangeNr" }, - delete = { hl = "DiffDelete", text = "_", numhl = "GitSignsDeleteNr" }, - topdelete = { hl = "DiffDelete", text = "‾", numhl = "GitSignsDeleteNr" }, - }, - - status_formatter = nil, -- Use default - watch_gitdir = { - interval = 100, - }, -} diff --git a/lua/plugins/configs/lspkind_icons.lua b/lua/plugins/configs/lspkind_icons.lua index dd775b7..ea584ae 100644 --- a/lua/plugins/configs/lspkind_icons.lua +++ b/lua/plugins/configs/lspkind_icons.lua @@ -1,6 +1,4 @@ -local M = {} - -M.icons = { +local icons = { Text = "", Method = "", Function = "", @@ -28,4 +26,4 @@ M.icons = { TypeParameter = "", } -return M +return icons diff --git a/lua/plugins/configs/nvimtree.lua b/lua/plugins/configs/nvimtree.lua index 95b0319..e741d69 100644 --- a/lua/plugins/configs/nvimtree.lua +++ b/lua/plugins/configs/nvimtree.lua @@ -17,10 +17,9 @@ g.nvim_tree_indent_markers = 1 g.nvim_tree_ignore = { ".git", "node_modules", ".cache" } g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened g.nvim_tree_root_folder_modifier = table.concat { ":t:gs?$?/..", string.rep(" ", 1000), "?:gs?^??" } --- + g.nvim_tree_show_icons = { folders = 1, - -- folder_arrows= 1 files = 1, git = git_status, } @@ -38,11 +37,8 @@ g.nvim_tree_icons = { untracked = "★", }, folder = { - -- disable indent_markers option to get arrows working or if you want both arrows and indent then just add the arrow icons in front ofthe default and opened folders below! - -- arrow_open = "", - -- arrow_closed = "", default = "", - empty = "", --  + empty = "", empty_open = "", open = "", symlink = "", diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index 9a55fab..e44ed8e 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -1,19 +1,17 @@ local M = {} local chadrc_config = require("core.utils").load_config() + M.autopairs = function() local present1, autopairs = pcall(require, "nvim-autopairs") local present2, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp") - if not (present1 or present2) then - return + if present1 and present2 then + autopairs.setup() + + local cmp = require "cmp" + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) end - - autopairs.setup() - - -- not needed if you disable cmp, the above var related to cmp tooo! override default config for autopairs - local cmp = require "cmp" - cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) end M.better_escape = function() @@ -71,17 +69,15 @@ end M.luasnip = function() local present, luasnip = pcall(require, "luasnip") - if not present then - return + if present then + luasnip.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + } + + require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path } + require("luasnip/loaders/from_vscode").load() end - - luasnip.config.set_config { - history = true, - updateevents = "TextChanged,TextChangedI", - } - - require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path } - require("luasnip/loaders/from_vscode").load() end M.signature = function() @@ -114,8 +110,8 @@ M.lsp_handlers = function() lspSymbol("Error", "") lspSymbol("Information", "") - lspSymbol("Hint", "") - lspSymbol("Warning", "") + lspSymbol("Hint", "") + lspSymbol("Warning", "") vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = { @@ -146,4 +142,19 @@ M.lsp_handlers = function() end end +M.gitsigns = function() + local present, gitsigns = pcall(require, "gitsigns") + if present then + 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 +end + return M diff --git a/lua/plugins/configs/statusline.lua b/lua/plugins/configs/statusline.lua index 0a8f4aa..b7bf633 100644 --- a/lua/plugins/configs/statusline.lua +++ b/lua/plugins/configs/statusline.lua @@ -43,10 +43,12 @@ local icon_styles = { } local config = require("core.utils").load_config().plugins.options.statusline + -- statusline style local user_statusline_style = config.style local statusline_style = icon_styles[user_statusline_style] --- if show short statusline on small screens + +-- show short statusline on small screens local shortline = config.shortline == false and true -- Initialize the components table @@ -55,7 +57,6 @@ local components = { inactive = {}, } --- Initialize left, mid and right table.insert(components.active, {}) table.insert(components.active, {}) table.insert(components.active, {}) @@ -186,6 +187,7 @@ components.active[1][10] = { components.active[2][1] = { provider = function() local Lsp = vim.lsp.util.get_progress_messages()[1] + if Lsp then local msg = Lsp.message or "" local percentage = Lsp.percentage or 0 @@ -207,10 +209,11 @@ components.active[2][1] = { if percentage >= 70 then return string.format(" %%<%s %s %s (%s%%%%) ", success_icon[frame + 1], title, msg, percentage) - else - return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage) end + + return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage) end + return "" end, enabled = shortline or function(winid) diff --git a/lua/plugins/configs/telescope.lua b/lua/plugins/configs/telescope.lua index 6db93db..c29b28d 100644 --- a/lua/plugins/configs/telescope.lua +++ b/lua/plugins/configs/telescope.lua @@ -1,4 +1,5 @@ local present, telescope = pcall(require, "telescope") + if not present then return end diff --git a/lua/plugins/configs/treesitter.lua b/lua/plugins/configs/treesitter.lua index 42ab87e..a9a7f49 100644 --- a/lua/plugins/configs/treesitter.lua +++ b/lua/plugins/configs/treesitter.lua @@ -1,4 +1,5 @@ local present, ts_config = pcall(require, "nvim-treesitter.configs") + if not present then return end diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 39a3c14..5a7fa7b 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -78,7 +78,7 @@ return packer.startup(function() "lewis6991/gitsigns.nvim", disable = not plugin_settings.status.gitsigns, opt = true, - config = override_req("gitsigns", "plugins.configs.gitsigns"), + config = override_req("gitsigns", "(plugins.configs.others).gitsigns()"), setup = function() require("core.utils").packer_lazy_load "gitsigns.nvim" end, From 5c69d46dd671f7923bbde0eac20b4ab905ce882c Mon Sep 17 00:00:00 2001 From: siduck Date: Fri, 19 Nov 2021 07:17:09 +0530 Subject: [PATCH 11/20] rm unused config in nvimtree | include vim highlighting support by default --- lua/plugins/configs/nvimtree.lua | 17 +++++------------ lua/plugins/configs/treesitter.lua | 1 + lua/plugins/init.lua | 1 - 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lua/plugins/configs/nvimtree.lua b/lua/plugins/configs/nvimtree.lua index e741d69..b4d3d17 100644 --- a/lua/plugins/configs/nvimtree.lua +++ b/lua/plugins/configs/nvimtree.lua @@ -7,17 +7,19 @@ end local g = vim.g -vim.o.termguicolors = true - g.nvim_tree_add_trailing = 0 -- append a trailing slash to folder names g.nvim_tree_git_hl = git_status g.nvim_tree_gitignore = 0 g.nvim_tree_highlight_opened_files = 0 g.nvim_tree_indent_markers = 1 -g.nvim_tree_ignore = { ".git", "node_modules", ".cache" } g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened g.nvim_tree_root_folder_modifier = table.concat { ":t:gs?$?/..", string.rep(" ", 1000), "?:gs?^??" } +g.nvim_tree_window_picker_exclude = { + filetype = { "notify", "packer", "qf" }, + buftype = { "terminal" }, +} + g.nvim_tree_show_icons = { folders = 1, files = 1, @@ -47,15 +49,6 @@ g.nvim_tree_icons = { } nvimtree.setup { - diagnostics = { - enable = false, - icons = { - hint = "", - info = "", - warning = "", - error = "", - }, - }, filters = { dotfiles = false, }, diff --git a/lua/plugins/configs/treesitter.lua b/lua/plugins/configs/treesitter.lua index a9a7f49..6e65340 100644 --- a/lua/plugins/configs/treesitter.lua +++ b/lua/plugins/configs/treesitter.lua @@ -7,6 +7,7 @@ end ts_config.setup { ensure_installed = { "lua", + "vim", }, highlight = { enable = true, diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 5a7fa7b..bc1004a 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -68,7 +68,6 @@ return packer.startup(function() use { "nvim-treesitter/nvim-treesitter", - branch = "0.5-compat", event = "BufRead", config = override_req("nvim_treesitter", "plugins.configs.treesitter"), } From b4da4901382aebb948ff018d63f7206897287643 Mon Sep 17 00:00:00 2001 From: siduck Date: Fri, 19 Nov 2021 07:44:06 +0530 Subject: [PATCH 12/20] gitignore custom dir | add example configs --- .gitignore | 1 + examples/example_chadrc.lua | 13 +++++++++++ examples/example_init.lua | 39 ++++++++++++++++++++++++++++++++ lua/plugins/configs/nvimtree.lua | 1 - 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 examples/example_chadrc.lua create mode 100644 examples/example_init.lua diff --git a/.gitignore b/.gitignore index 8cb205e..cfcf4e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ plugin +custom/ diff --git a/examples/example_chadrc.lua b/examples/example_chadrc.lua new file mode 100644 index 0000000..e810f1c --- /dev/null +++ b/examples/example_chadrc.lua @@ -0,0 +1,13 @@ +-- This is an example chadrc file , its supposed to be placed in /lua/custom dir +-- lua/custom/chadrc.lua + +local M = {} + +-- make sure you maintain the structure of `core/default_config.lua` here, +-- example of changing theme: + +M.ui = { + theme = "gruvchad", +} + +return M diff --git a/examples/example_init.lua b/examples/example_init.lua new file mode 100644 index 0000000..5d08fd5 --- /dev/null +++ b/examples/example_init.lua @@ -0,0 +1,39 @@ +-- This is an example init file , its supposed to be placed in /lua/custom dir +-- lua/custom/init.lua + +-- This is where your custom modules and plugins go. +-- Please check NvChad docs if you're totally new to nvchad + dont know lua!! + +local hooks = require "core.hooks" + +-- MAPPINGS +-- To add new plugins, use the "setup_mappings" hook, + +hooks.add("setup_mappings", function(map) + map("n", "cc", ":Telescope ", opt) + map("n", "q", ":q ", opt) +end) + +-- NOTE : opt is a variable there (most likely a table if you want multiple options), +-- you can remove it if you dont have any custom options + +-- Install plugins +-- To add new plugins, use the "install_plugin" hook, + +-- examples below: + +hooks.add("install_plugins", function(use) + use { + "max397574/better-escape.nvim", + event = "InsertEnter", + } + + use { + "user or orgname/reponame", + --further packer options + } +end) + +-- NOTE: we heavily suggest using Packer's lazy loading (with the 'event' field) +-- see: https://github.com/wbthomason/packer.nvim +-- https://nvchad.github.io/config/walkthrough diff --git a/lua/plugins/configs/nvimtree.lua b/lua/plugins/configs/nvimtree.lua index b4d3d17..22d2f41 100644 --- a/lua/plugins/configs/nvimtree.lua +++ b/lua/plugins/configs/nvimtree.lua @@ -9,7 +9,6 @@ local g = vim.g g.nvim_tree_add_trailing = 0 -- append a trailing slash to folder names g.nvim_tree_git_hl = git_status -g.nvim_tree_gitignore = 0 g.nvim_tree_highlight_opened_files = 0 g.nvim_tree_indent_markers = 1 g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened From 7114ebd945a96387bfbd00012106fb9efabc9a80 Mon Sep 17 00:00:00 2001 From: siduck Date: Fri, 19 Nov 2021 09:27:55 +0530 Subject: [PATCH 13/20] Delete example_chadrc.lua --- lua/custom/example_chadrc.lua | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 lua/custom/example_chadrc.lua diff --git a/lua/custom/example_chadrc.lua b/lua/custom/example_chadrc.lua deleted file mode 100644 index f503361..0000000 --- a/lua/custom/example_chadrc.lua +++ /dev/null @@ -1,10 +0,0 @@ -local M = {} - --- make sure you maintain the structure of `core/default_config.lua` here, --- example of changing theme: - -M.ui = { - theme = "gruvchad", -} - -return M From 067c6cc7fc4b56fb1aab2946decdd506cc8f7409 Mon Sep 17 00:00:00 2001 From: siduck Date: Fri, 19 Nov 2021 09:28:09 +0530 Subject: [PATCH 14/20] Delete example_init.lua --- lua/custom/example_init.lua | 44 ------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 lua/custom/example_init.lua diff --git a/lua/custom/example_init.lua b/lua/custom/example_init.lua deleted file mode 100644 index 51e3dcb..0000000 --- a/lua/custom/example_init.lua +++ /dev/null @@ -1,44 +0,0 @@ --- This is where your custom modules and plugins go. --- See the wiki for a guide on how to extend NvChad - -local hooks = require "core.hooks" - --- NOTE: To use this, make a copy with `cp example_init.lua init.lua` - --------------------------------------------------------------------- - --- To modify packaged plugin configs, use the overrides functionality --- if the override does not exist in the plugin config, make or request a PR, --- or you can override the whole plugin config with 'chadrc' -> M.plugins.default_plugin_config_replace{} --- this will run your config instead of the NvChad config for the given plugin - --- hooks.override("lsp", "publish_diagnostics", function(current) --- current.virtual_text = false; --- return current; --- end) - --- To add new mappings, use the "setup_mappings" hook, --- you can set one or many mappings --- example below: - --- hooks.add("setup_mappings", function(map) --- map("n", "cc", "gg0vG$d", opt) -- example to delete the buffer --- .... many more mappings .... --- end) - --- To add new plugins, use the "install_plugin" hook, --- NOTE: we heavily suggest using Packer's lazy loading (with the 'event' field) --- see: https://github.com/wbthomason/packer.nvim --- examples below: - --- hooks.add("install_plugins", function(use) --- use { --- "max397574/better-escape.nvim", --- event = "InsertEnter", --- } --- end) - --- alternatively, put this in a sub-folder like "lua/custom/plugins/mkdir" --- then source it with - --- require "custom.plugins.mkdir" From 9e8af5ad93a84a005a314a8cb619e0b1a617c05a Mon Sep 17 00:00:00 2001 From: siduck Date: Wed, 24 Nov 2021 20:08:11 +0530 Subject: [PATCH 15/20] include NvimTreeNormalNC for transparency | add #608 --- lua/colors/highlights.lua | 1 + lua/core/mappings.lua | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index d460a64..3fed96b 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -136,6 +136,7 @@ fg_bg("TelescopeResultsTitle", red, one_bg) -- Disable some highlight in nvim tree if transparency enabled if ui.transparency then bg("NvimTreeNormal", "NONE") + bg("NvimTreeNormalNC", "NONE") bg("NvimTreeStatusLineNC", "NONE") bg("NvimTreeVertSplit", "NONE") fg("NvimTreeVertSplit", grey) diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index e192ea5..0036234 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -29,6 +29,12 @@ M.misc = function() -- use ESC to turn off search highlighting map("n", "", ":noh ") + + -- center cursor when moving (goto_definition) + + + -- yank from current cursor to end of line + map("n", "Y", "yg$") end local function optional_mappings() @@ -150,7 +156,7 @@ M.telescope = function() local m = plugin_maps.telescope map("n", m.buffers, ":Telescope buffers ") - map("n", m.find_files, ":Telescope find_files ") + map("n", m.find_files, ":Telescope find_files no_ignore=true ") map("n", m.find_hiddenfiles, ":Telescope find_files hidden=true ") map("n", m.git_commits, ":Telescope git_commits ") map("n", m.git_status, ":Telescope git_status ") From 653a2f5337371eaabbb114f8d942952b7f659392 Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 4 Dec 2021 20:42:44 +0530 Subject: [PATCH 16/20] add flat look to telescope | disable gitignore on nvimtree --- .gitignore | 2 +- lua/colors/highlights.lua | 17 +++++++++++++---- lua/plugins/configs/nvimtree.lua | 4 ++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index cfcf4e2..8389435 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ plugin -custom/ +custom diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index 3fed96b..5d2fcd0 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -128,10 +128,19 @@ bg("NvimTreeVertSplit", darker_black) fg_bg("NvimTreeWindowPicker", red, black2) -- Telescope -fg("TelescopeBorder", one_bg) -fg_bg("TelescopePreviewTitle", green, one_bg) -fg_bg("TelescopePromptTitle", blue, one_bg) -fg_bg("TelescopeResultsTitle", red, one_bg) +fg_bg("TelescopeBorder", darker_black, darker_black) +fg_bg("TelescopePromptBorder", black2, black2) + +fg_bg("TelescopePromptNormal", white, black2) +fg_bg("TelescopePromptPrefix", red, black2) + +bg("TelescopeNormal", darker_black) + +fg_bg("TelescopePreviewTitle", black, green) +fg_bg("TelescopePromptTitle", black, red) +fg_bg("TelescopeResultsTitle", darker_black,darker_black) + +bg("TelescopeSelection", black2) -- Disable some highlight in nvim tree if transparency enabled if ui.transparency then diff --git a/lua/plugins/configs/nvimtree.lua b/lua/plugins/configs/nvimtree.lua index 22d2f41..58c89d4 100644 --- a/lua/plugins/configs/nvimtree.lua +++ b/lua/plugins/configs/nvimtree.lua @@ -67,4 +67,8 @@ nvimtree.setup { side = "left", width = 25, }, + + git = { + ignore = false, + }, } From 6347a00023002fa4d609cfebd031c14d6618f32c Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 4 Dec 2021 21:04:04 +0530 Subject: [PATCH 17/20] add mapping, highlights for keybind cheatsheet | disable indentline in it --- lua/colors/highlights.lua | 24 ++++++++++++++++++++++-- lua/core/default_config.lua | 1 + lua/core/mappings.lua | 2 +- lua/plugins/configs/others.lua | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index 5d2fcd0..75e5580 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -21,6 +21,7 @@ local purple = colors.purple local red = colors.red local white = colors.white local yellow = colors.yellow +local orange = colors.orange local one_bg3 = colors.one_bg3 -- functions for setting highlights @@ -45,7 +46,7 @@ fg("EndOfBuffer", black) -- For floating windows fg("FloatBorder", blue) -bg("NormalFloat", one_bg) +bg("NormalFloat", darker_black) -- Pmenu bg("Pmenu", one_bg) @@ -138,10 +139,29 @@ bg("TelescopeNormal", darker_black) fg_bg("TelescopePreviewTitle", black, green) fg_bg("TelescopePromptTitle", black, red) -fg_bg("TelescopeResultsTitle", darker_black,darker_black) +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("NvimTreeNormal", "NONE") diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index 6c73a9d..1791f7e 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -116,6 +116,7 @@ M.mappings = { -- custom = {}, -- custom user mappings misc = { + cheatsheet = "ch", close_buffer = "x", copy_whole_file = "", -- copy all contents of current buffer line_number_toggle = "n", -- toggle line number diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 0036234..9e5f84a 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -31,7 +31,6 @@ M.misc = function() map("n", "", ":noh ") -- center cursor when moving (goto_definition) - -- yank from current cursor to end of line map("n", "Y", "yg$") @@ -81,6 +80,7 @@ M.misc = function() 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.copy_whole_file, ":%y+ ") -- copy whole file content map("n", maps.misc.new_buffer, ":enew ") -- new buffer diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index e44ed8e..310118f 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -33,6 +33,7 @@ M.blankline = function() "lspinfo", "TelescopePrompt", "TelescopeResults", + "nvchad_cheatsheet", }, buftype_exclude = { "terminal" }, show_trailing_blankline_indent = false, From 84c3a18fab9e374dacd87b405195183ccfddc57e Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 4 Dec 2021 21:38:30 +0530 Subject: [PATCH 18/20] include telescope highlights for transparency --- lua/colors/highlights.lua | 11 +++++++++++ lua/plugins/configs/telescope.lua | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index 75e5580..0da5e41 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -164,11 +164,22 @@ end -- Disable some highlight in nvim tree if transparency enabled if ui.transparency then + bg("NormalFloat", "NONE") bg("NvimTreeNormal", "NONE") bg("NvimTreeNormalNC", "NONE") bg("NvimTreeStatusLineNC", "NONE") bg("NvimTreeVertSplit", "NONE") fg("NvimTreeVertSplit", grey) + + -- telescope + bg("TelescopeBorder", "NONE") + bg("TelescopePrompt", "NONE") + bg("TelescopeResults", "NONE") + bg("TelescopePromptBorder", "NONE") + bg("TelescopePromptNormal", "NONE") + bg("TelescopeNormal", "NONE") + bg("TelescopePromptPrefix", "NONE") + fg("TelescopeBorder", one_bg) end if #override ~= 0 then diff --git a/lua/plugins/configs/telescope.lua b/lua/plugins/configs/telescope.lua index c29b28d..5567de6 100644 --- a/lua/plugins/configs/telescope.lua +++ b/lua/plugins/configs/telescope.lua @@ -38,7 +38,7 @@ telescope.setup { file_sorter = require("telescope.sorters").get_fuzzy_file, file_ignore_patterns = { "node_modules" }, generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, - path_display = { "absolute" }, + path_display = { "truncate" }, winblend = 0, border = {}, borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, From 03d55e94a44b24cddf57dea5a98236754f9f1d42 Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 4 Dec 2021 23:06:07 +0530 Subject: [PATCH 19/20] update highlights for lsp diagnostics --- lua/colors/highlights.lua | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index 0da5e41..4ac4ff2 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -92,25 +92,12 @@ fg_bg("DiffDelete", red, "NONE") -- Indent blankline plugin fg("IndentBlanklineChar", line) --- ]] +-- Lsp diagnostics --- [[ LspDiagnostics - --- Errors -fg("LspDiagnosticsSignError", red) -fg("LspDiagnosticsSignWarning", yellow) -fg("LspDiagnosticsVirtualTextError", red) -fg("LspDiagnosticsVirtualTextWarning", yellow) - --- Info -fg("LspDiagnosticsSignInformation", green) -fg("LspDiagnosticsVirtualTextInformation", green) - --- Hints -fg("LspDiagnosticsSignHint", purple) -fg("LspDiagnosticsVirtualTextHint", purple) - --- ]] +fg("DiagnosticHint", purple) +fg("DiagnosticError", red) +fg("DiagnosticWarn", yellow) +fg("DiagnosticInformation", green) -- NvimTree fg("NvimTreeEmptyFolderName", blue) From 97572ee1bb2459caaf539812969e5560cdeae5ac Mon Sep 17 00:00:00 2001 From: Deneir Uy Date: Tue, 7 Dec 2021 16:19:31 +0800 Subject: [PATCH 20/20] Fix LSP diagnostic icons --- lua/plugins/configs/others.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index 310118f..5a851cc 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -106,13 +106,14 @@ end M.lsp_handlers = function() local function lspSymbol(name, icon) - vim.fn.sign_define("LspDiagnosticsSign" .. name, { text = icon, numhl = "LspDiagnosticsDefault" .. name }) + local hl = "DiagnosticSign" .. name + vim.fn.sign_define(hl, { text = icon, numhl = hl, texthl = hl }) end lspSymbol("Error", "") - lspSymbol("Information", "") - lspSymbol("Hint", "") - lspSymbol("Warning", "") + lspSymbol("Info", "") + lspSymbol("Hint", "") + lspSymbol("Warn", "") vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = {