refactor: clean & re-organise default_config + chadrc

this completely overhauls the design of the two configuration files,
aiming to move options & various tables into a more sensible table structure

BREAKING CHANGE: this will break any user modificiations to the current
config
This commit is contained in:
Galen Rowell 2021-09-19 18:11:28 +10:00 committed by siduck76
parent 80c8bf4243
commit 9961cc0113
9 changed files with 154 additions and 158 deletions

View File

@ -2,107 +2,116 @@
-- use custom/chadrc.lua instead -- use custom/chadrc.lua instead
local M = {} local M = {}
M.ui, M.options, M.plugin_status, M.mappings, M.custom = {}, {}, {}, {}, {} M.options, M.ui, M.mappings, M.plugin = {}, {}, {}, {}
-- non plugin ui configs, available without any plugins
M.ui = {
italic_comments = false,
-- theme to be used, to see all available themes, open the theme switcher by <leader> + th
theme = "onedark",
-- theme toggler, toggle between two themes, see theme_toggleer mappings
theme_toggler = {
enabled = false,
fav_themes = {
"onedark",
"one-light",
},
},
-- Enable this only if your terminal has the colorscheme set which nvchad uses
-- For Ex : if you have onedark set in nvchad , set onedark's bg color on your terminal
transparency = false,
}
-- plugin related ui options
M.ui.plugin = {
-- statusline related options
statusline = {
-- these are filetypes, not pattern matched
-- if a filetype is present in shown, it will always show the statusline, irrespective of filetypes in hidden
hidden = {
"help",
"dashboard",
"NvimTree",
"terminal",
},
shown = {},
-- default, round , slant , block , arrow
style = "default",
},
}
-- non plugin normal, available without any plugins -- non plugin normal, available without any plugins
M.options = { M.options = {
-- NeoVim/Vim options
clipboard = "unnamedplus", clipboard = "unnamedplus",
cmdheight = 1, cmdheight = 1,
copy_cut = true, -- copy cut text ( x key ), visual and normal mode ruler = false,
copy_del = true, -- copy deleted text ( dd key ), visual and normal mode
expandtab = true,
hidden = true, hidden = true,
ignorecase = true, ignorecase = true,
insert_nav = true, -- navigation in insertmode
window_nav = true,
mapleader = " ", mapleader = " ",
mouse = "a", mouse = "a",
number = true, number = true,
-- relative numbers in normal mode tool at the bottom of options.lua -- relative numbers in normal mode tool at the bottom of options.lua
numberwidth = 2, numberwidth = 2,
permanent_undo = true, relativenumber = false,
expandtab = true,
shiftwidth = 2, shiftwidth = 2,
smartindent = true, smartindent = true,
tabstop = 8, -- Number of spaces that a <Tab> in the file counts for tabstop = 8, -- Number of spaces that a <Tab> in the file counts for
timeoutlen = 400, timeoutlen = 400,
relativenumber = false, -- interval for writing swap file to disk, also used by gitsigns
ruler = false,
updatetime = 250, updatetime = 250,
-- used for updater undofile = true, -- keep a permanent undo (across restarts)
update_url = "https://github.com/NvChad/NvChad", -- NvChad options
update_branch = "main", 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,
theme_toggler = false,
-- used for updater
update_url = "https://github.com/NvChad/NvChad",
update_branch = "main",
},
}
-- ui configs
M.ui = {
italic_comments = false,
-- theme to be used, check available themes with `<leader> + t + h`
theme = "onedark",
-- 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
-- For Ex : if you have onedark set in nvchad, set onedark's bg color on your terminal
transparency = false,
} }
-- these are plugin related options -- these are plugin related options
M.options.plugin = { M.plugins = {
autosave = false, -- autosave on changed text or insert mode leave -- enable and disable plugins (false for disable)
-- timeout to be used for using escape with a key combination, see mappings.plugin.better_escape plugin_status = {
esc_insertmode_timeout = 300, autosave = false, -- to autosave files
} blankline = true, -- show code scope with symbols
bufferline = true, -- list open buffers up the top, easy switching too
-- enable and disable plugins (false for disable) cheatsheet = true, -- search your commands/keymappings
M.plugin_status = { colorizer = true, -- color RGB, HEX, CSS, NAME color codes
autosave = false, -- to autosave files comment = true, -- easily (un)comment code, language aware
blankline = true, -- beautified blank lines dashboard = false, -- NeoVim 'home screen' on open
bufferline = true, -- buffer shown as tabs esc_insertmode = true, -- map to <ESC> with no lag
cheatsheet = true, -- fuzzy search your commands/keymappings feline = true, -- statusline
colorizer = true, gitsigns = true, -- gitsigns in statusline
comment = true, -- universal commentor lspsignature = true, -- lsp enhancements
dashboard = false, -- a nice looking dashboard neoformat = true, -- universal code formatter
esc_insertmode = true, -- escape from insert mode using custom keys neoscroll = true, -- smooth scroll
feline = true, -- statusline telescope_media = false, -- media previews within telescope finders
gitsigns = true, -- gitsigns in statusline truezen = false, -- distraction free & minimalist UI mode
lspsignature = true, -- lsp enhancements vim_fugitive = false, -- git integration & tooling
neoformat = true, -- universal formatter vim_matchup = true, -- % operator enhancements
neoscroll = true, -- smooth scroll },
telescope_media = false, -- see media files in telescope picker options = {
truezen = false, -- no distraction mode for nvim lspconfig = {
vim_fugitive = false, -- git in nvim servers = {} -- eg: "HTML"
vim_matchup = true, -- % magic, match it but improved },
statusline = { -- statusline related options
-- these are filetypes, not pattern matched
-- shown filetypes will overrule hidden filetypes
hidden = {
"help",
"dashboard",
"NvimTree",
"terminal",
},
shown = {},
-- default, round , slant , block , arrow
style = "default",
},
autosave = false, -- autosave on changed text or insert mode leave
-- timeout to be used for using escape with a key combination, see mappings.plugin.better_escape
esc_insertmode_timeout = 300,
},
default_plugin_config_replace = {},
} }
-- mappings -- don't use a single keymap twice -- -- mappings -- don't use a single keymap twice --
-- non plugin mappings -- non plugin mappings
M.mappings = { M.mappings = {
-- custom = {}, -- all custom user mappings
-- close current focused buffer -- close current focused buffer
close_buffer = "<leader>x", close_buffer = "<leader>x",
copy_whole_file = "<C-a>", -- copy all contents of the current buffer copy_whole_file = "<C-a>", -- copy all contents of the current buffer
line_number_toggle = "<leader>n", -- show or hide line number
new_buffer = "<S-t>", -- open a new buffer
new_tab = "<C-t>b", -- open a new vim tab
save_file = "<C-s>", -- save file using :w
theme_toggler = "<leader>tt", -- for theme toggler, see in ui.theme_toggler
-- navigation in insert mode, only if enabled in options -- navigation in insert mode, only if enabled in options
insert_nav = { insert_nav = {
backward = "<C-h>", backward = "<C-h>",
@ -112,27 +121,21 @@ M.mappings = {
prev_line = "<C-j>", prev_line = "<C-j>",
top_of_line = "<C-a>", top_of_line = "<C-a>",
}, },
--better window movement
window_nav = { window_nav = {
--better window movement
moveLeft = "<C-h>", moveLeft = "<C-h>",
moveRight = "<C-l>", moveRight = "<C-l>",
moveUp = "<C-k>", moveUp = "<C-k>",
moveDown = "<C-j>", moveDown = "<C-j>",
}, },
line_number_toggle = "<leader>n", -- show or hide line number
new_buffer = "<S-t>", -- open a new buffer
new_tab = "<C-t>b", -- open a new vim tab
save_file = "<C-s>", -- save file using :w
theme_toggler = "<leader>tt", -- for theme toggler, see in ui.theme_toggler
-- terminal related mappings -- terminal related mappings
terminal = { terminal = {
-- multiple mappings can be given for esc_termmode and esc_hide_termmode -- multiple mappings can be given for esc_termmode and esc_hide_termmode
-- get out of terminal mode -- get out of terminal mode
esc_termmode = { "jk" }, -- multiple mappings allowed esc_termmode = { "jk" }, -- multiple mappings allowed
-- get out of terminal mode and hide it -- get out of terminal mode and hide it
-- it does not close it, see pick_term mapping to see hidden terminals
esc_hide_termmode = { "JK" }, -- multiple mappings allowed esc_hide_termmode = { "JK" }, -- multiple mappings allowed
-- show hidden terminal buffers in a telescope picker -- show & recover hidden terminal buffers in a telescope picker
pick_term = "<leader>W", pick_term = "<leader>W",
-- below three are for spawning terminals -- below three are for spawning terminals
new_horizontal = "<leader>h", new_horizontal = "<leader>h",
@ -144,19 +147,22 @@ M.mappings = {
} }
-- all plugins related mappings -- all plugins related mappings
-- to get short info about a plugin, see the respective string in plugin_status, if not present, then info here M.mappings.plugins = {
M.mappings.plugin = { -- list open buffers up the top, easy switching too
bufferline = { bufferline = {
next_buffer = "<TAB>", -- next buffer next_buffer = "<TAB>", -- next buffer
prev_buffer = "<S-Tab>", -- previous buffer prev_buffer = "<S-Tab>", -- previous buffer
}, },
-- search your commands/keymappings
cheatsheet = { cheatsheet = {
default_keys = "<leader>dk", default_keys = "<leader>dk",
user_keys = "<leader>uk", user_keys = "<leader>uk",
}, },
-- easily (un)comment code, language aware
comment = { comment = {
toggle = "<leader>/", -- trigger comment on a single/selected lines/number prefix toggle = "<leader>/", -- toggle comment (works on multiple lines)
}, },
-- NeoVim 'home screen' on open
dashboard = { dashboard = {
bookmarks = "<leader>bm", bookmarks = "<leader>bm",
new_file = "<leader>fn", -- basically create a new buffer new_file = "<leader>fn", -- basically create a new buffer
@ -164,18 +170,20 @@ M.mappings.plugin = {
session_load = "<leader>l", -- load a saved session session_load = "<leader>l", -- load a saved session
session_save = "<leader>s", -- save a session session_save = "<leader>s", -- save a session
}, },
-- note: this is an edditional mapping to escape, escape key will still work -- map to <ESC> with no lag
better_escape = { better_escape = { -- <ESC> will still work
esc_insertmode = { "jk" }, -- multiple mappings allowed esc_insertmode = { "jk" }, -- multiple mappings allowed
}, },
-- file explorer/tree
nvimtree = { nvimtree = {
-- file tree
toggle = "<C-n>", toggle = "<C-n>",
focus = "<leader>e", focus = "<leader>e",
}, },
-- universal code formatter
neoformat = { neoformat = {
format = "<leader>fm", format = "<leader>fm",
}, },
-- multitool for finding & picking things
telescope = { telescope = {
buffers = "<leader>fb", buffers = "<leader>fb",
find_files = "<leader>ff", find_files = "<leader>ff",
@ -185,16 +193,19 @@ M.mappings.plugin = {
help_tags = "<leader>fh", help_tags = "<leader>fh",
live_grep = "<leader>fw", live_grep = "<leader>fw",
oldfiles = "<leader>fo", oldfiles = "<leader>fo",
themes = "<leader>th", themes = "<leader>th", -- NvChad theme picker
-- media previews within telescope finders
telescope_media = {
media_files = "<leader>fp",
},
}, },
telescope_media = { -- distraction free & minimalist UI mode
media_files = "<leader>fp", truezen = {
},
truezen = { -- distraction free modes mapping, hide statusline, tabline, line numbers
ataraxis_mode = "<leader>zz", -- center ataraxis_mode = "<leader>zz", -- center
focus_mode = "<leader>zf", focus_mode = "<leader>zf",
minimalistic_mode = "<leader>zm", -- as it is minimalistic_mode = "<leader>zm", -- as it is
}, },
-- git integration & tooling
vim_fugitive = { vim_fugitive = {
diff_get_2 = "<leader>gh", diff_get_2 = "<leader>gh",
diff_get_3 = "<leader>gl", diff_get_3 = "<leader>gl",
@ -203,26 +214,5 @@ M.mappings.plugin = {
}, },
} }
-- user custom mappings
-- e.g: name = { "mode" , "keys" , "cmd" , "options"}
-- name: can be empty or something unique with repect to other custom mappings
-- { mode, key, cmd } or name = { mode, key, cmd }
-- mode: usage: mode or { mode1, mode2 }, multiple modes allowed, available modes => :h map-modes,
-- keys: multiple keys allowed, same synxtax as modes
-- cmd: for vim commands, must use ':' at start and add <CR> at the end if want to execute
-- options: see :h nvim_set_keymap() opts section
M.custom.mappings = {
-- clear_all = {
-- "n",
-- "<leader>cc",
-- "gg0vG$d",
-- },
}
M.plugins = {
lspconfig = {
-- servers = {"html", "cssls"}
servers = {},
},
}
return M return M

View File

@ -5,7 +5,8 @@ local config = utils.load_config()
local map = utils.map local map = utils.map
local maps = config.mappings local maps = config.mappings
local plugin_maps = maps.plugin local plugin_maps = maps.plugins
local nvChad_options = config.options.nvChad
local cmd = vim.cmd local cmd = vim.cmd
@ -32,17 +33,17 @@ M.misc = function()
local function optional_mappings() local function optional_mappings()
-- don't yank text on cut ( x ) -- don't yank text on cut ( x )
if not config.options.copy_cut then if not nvChad_options.copy_cut then
map({ "n", "v" }, "x", '"_x') map({ "n", "v" }, "x", '"_x')
end end
-- don't yank text on delete ( dd ) -- don't yank text on delete ( dd )
if not config.options.copy_del then if not nvChad_options.copy_del then
map({ "n", "v" }, "dd", '"_dd') map({ "n", "v" }, "dd", '"_dd')
end end
-- navigation within insert mode -- navigation within insert mode
if config.options.insert_nav then if nvChad_options.insert_nav then
local inav = maps.insert_nav local inav = maps.insert_nav
map("i", inav.backward, "<Left>") map("i", inav.backward, "<Left>")
@ -54,7 +55,7 @@ M.misc = function()
end end
-- easier navigation between windows -- easier navigation between windows
if config.options.window_nav then if nvChad_options.window_nav then
local wnav = maps.window_nav local wnav = maps.window_nav
map("n", wnav.moveLeft, "<C-w>h") map("n", wnav.moveLeft, "<C-w>h")
@ -64,11 +65,11 @@ M.misc = function()
end end
-- check the theme toggler -- check the theme toggler
if config.ui.theme_toggler.enabled then if nvChad_options.theme_toggler then
map( map(
"n", "n",
maps.theme_toggler, maps.theme_toggler,
":lua require('nvchad').toggle_theme(require('core.utils').load_config().ui.theme_toggler.fav_themes) <CR>" ":lua require('nvchad').toggle_theme(require('core.utils').load_config().ui.theme_toggler) <CR>"
) )
end end
end end
@ -113,7 +114,7 @@ M.misc = function()
end end
local function user_config_mappings() local function user_config_mappings()
local custom_maps = config.custom.mappings or "" local custom_maps = config.mappings.custom or ""
if type(custom_maps) ~= "table" then if type(custom_maps) ~= "table" then
return return
end end
@ -190,7 +191,7 @@ M.telescope = function()
end end
M.telescope_media = function() M.telescope_media = function()
local m = plugin_maps.telescope_media local m = plugin_maps.telescope.telescope_media
map("n", m.media_files, ":Telescope media_files <CR>") map("n", m.media_files, ":Telescope media_files <CR>")
end end

View File

@ -15,7 +15,7 @@ opt.expandtab = options.expandtab
opt.shiftwidth = options.shiftwidth opt.shiftwidth = options.shiftwidth
opt.smartindent = options.smartindent opt.smartindent = options.smartindent
-- disable tilde on end of buffer: https://github.com/ neovim/neovim/pull/8546#issuecomment-643643758 -- disable tilde on end of buffer: https://github.com/neovim/neovim/pull/8546#issuecomment-643643758
opt.fillchars = { eob = " " } opt.fillchars = { eob = " " }
opt.hidden = options.hidden opt.hidden = options.hidden
@ -37,7 +37,7 @@ opt.splitright = true
opt.tabstop = options.tabstop opt.tabstop = options.tabstop
opt.termguicolors = true opt.termguicolors = true
opt.timeoutlen = options.timeoutlen opt.timeoutlen = options.timeoutlen
opt.undofile = options.permanent_undo opt.undofile = options.undofile
-- interval for writing swap file to disk, also used by gitsigns -- interval for writing swap file to disk, also used by gitsigns
opt.updatetime = options.updatetime opt.updatetime = options.updatetime

View File

@ -117,8 +117,8 @@ end
-- hide statusline -- hide statusline
-- tables fetched from load_config function -- tables fetched from load_config function
M.hide_statusline = function() M.hide_statusline = function()
local hidden = require("core.utils").load_config().ui.plugin.statusline.hidden local hidden = require("core.utils").load_config().plugins.options.statusline.hidden
local shown = require("core.utils").load_config().ui.plugin.statusline.shown local shown = require("core.utils").load_config().plugins.options.statusline.shown
local api = vim.api local api = vim.api
local buftype = api.nvim_buf_get_option("%", "ft") local buftype = api.nvim_buf_get_option("%", "ft")

View File

@ -1,7 +1,7 @@
-- IMPORTANT NOTE : This is the user config, can be edited. Will be preserved if updated with internal updater -- IMPORTANT NOTE : This is the user config, can be edited. Will be preserved if updated with internal updater
local M = {} local M = {}
M.ui, M.options, M.plugin_status, M.mappings, M.custom = {}, {}, {}, {}, {} M.options, M.ui, M.mappings, M.plugins = {}, {}, {}, {}
-- To use this file, copy the strucutre of `core/default_config.lua`, -- To use this file, copy the strucutre of `core/default_config.lua`,
-- then define your new var, an example of setting relative number: -- then define your new var, an example of setting relative number:
@ -11,25 +11,15 @@ M.ui, M.options, M.plugin_status, M.mappings, M.custom = {}, {}, {}, {}, {}
-- } -- }
-- 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
M.custom.default_plugin_overrides = {
-- indent_blankline = "custom.blankline",
}
-- user custom mappings -- user custom mappings
-- e.g: name = { "mode" , "keys" , "cmd" , "options"} -- format: name = { "mode" , "keys" , "cmd" , "options"}
-- name: can be empty or something unique with repect to other custom mappings -- name: can be empty or something unique with repect to other custom mappings
-- { mode, key, cmd } or name = { mode, key, cmd } -- { mode, key, cmd } or name = { mode, key, cmd }
-- mode: usage: mode or { mode1, mode2 }, multiple modes allowed, available modes => :h map-modes, -- mode: usage: mode or { mode1, mode2 }, multiple modes allowed, available modes => :h map-modes,
-- keys: multiple keys allowed, same synxtax as modes -- keys: multiple keys allowed, same synxtax as modes
-- cmd: for vim commands, must use ':' at start and add <CR> at the end if want to execute -- cmd: for vim commands, must use ':' at start and add <CR> at the end if want to execute
-- options: see :h nvim_set_keymap() opts section -- options: see :h nvim_set_keymap() opts section
M.custom.mappings = { M.mappings.custom = {
-- clear_all = { -- clear_all = {
-- "n", -- "n",
-- "<leader>cc", -- "<leader>cc",
@ -37,4 +27,23 @@ M.custom.mappings = {
-- }, -- },
} }
-- NvChad included plugin options & overrides
M.plugins = {
options = {
-- lspconfig = {
-- -- servers = {"html", "cssls"}
-- servers = {},
-- },
},
-- 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 = {
},
}
return M return M

View File

@ -57,7 +57,7 @@ capabilities.textDocument.completion.completionItem.resolveSupport = {
}, },
} }
local servers = require("core.utils").load_config().plugins.lspconfig.servers local servers = require("core.utils").load_config().plugins.options.lspconfig.servers
for _, lsp in ipairs(servers) do for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup { nvim_lsp[lsp].setup {

View File

@ -1,7 +1,5 @@
local M = {} local M = {}
local config = require("core.utils").load_config()
M.autopairs = function() M.autopairs = function()
local present1, autopairs = pcall(require, "nvim-autopairs") local present1, autopairs = pcall(require, "nvim-autopairs")
local present2, autopairs_completion = pcall(require, "nvim-autopairs.completion.cmp") local present2, autopairs_completion = pcall(require, "nvim-autopairs.completion.cmp")
@ -25,7 +23,7 @@ M.autosave = function()
end end
autosave.setup { autosave.setup {
enabled = config.options.plugin.autosave, -- takes boolean value from chadrc.lua enabled = config.plugins.options.autosave, -- takes boolean value from init.lua
execution_message = "autosaved at : " .. vim.fn.strftime "%H:%M:%S", execution_message = "autosaved at : " .. vim.fn.strftime "%H:%M:%S",
events = { "InsertLeave", "TextChanged" }, events = { "InsertLeave", "TextChanged" },
conditions = { conditions = {
@ -40,10 +38,10 @@ M.autosave = function()
end end
M.better_escape = function() M.better_escape = function()
local m = require("core.utils").load_config().mappings.plugin.better_escape.esc_insertmode local config = require("core.utils").load_config()
require("better_escape").setup { require("better_escape").setup {
mapping = m, mapping = config.mappings.plugins.better_escape.esc_insertmode,
timeout = config.options.plugin.esc_insertmode_timeout or 300, timeout = config.plugins.options.esc_insertmode_timeout,
} }
end end

View File

@ -42,7 +42,7 @@ local icon_styles = {
}, },
} }
local user_statusline_style = require("core.utils").load_config().ui.plugin.statusline.style local user_statusline_style = require("core.utils").load_config().plugins.options.statusline.style
local statusline_style = icon_styles[user_statusline_style] local statusline_style = icon_styles[user_statusline_style]
-- Initialize the components table -- Initialize the components table

View File

@ -7,16 +7,14 @@ end
local use = packer.use local use = packer.use
return packer.startup(function() return packer.startup(function()
local plugin_status = require("core.utils").load_config().plugin_status local plugin_status = require("core.utils").load_config().plugins.plugin_status
-- local plugin_overrides = require("core.utils").load_config().custom.plugin_overrides
-- FUNCTION: override_req, use `chadrc` plugin config override if present -- FUNCTION: override_req, use `chadrc` plugin config override if present
-- name = name inside `default_config` / `chadrc` -- name = name inside `default_config` / `chadrc`
-- default_req = run this if 'name' does not exist in `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 -- 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_req = function(name, default_req)
local override = require("core.utils").load_config().custom.default_plugin_overrides[name] local override = require("core.utils").load_config().plugins.default_plugin_config_replace[name]
local result local result
if override == nil then if override == nil then
@ -166,7 +164,7 @@ return packer.startup(function()
"Pocco81/AutoSave.nvim", "Pocco81/AutoSave.nvim",
config = override_req("autosave", "(plugins.configs.others).autosave()"), config = override_req("autosave", "(plugins.configs.others).autosave()"),
cond = function() cond = function()
return require("core.utils").load_config().options.plugin.autosave == true return require("core.utils").load_config().plugins.options.autosave == true
end, end,
} }