restructure | clean default_config

This commit is contained in:
siduck 2021-11-14 12:43:36 +05:30
parent 5db36d44fb
commit bdd6dc12c2
4 changed files with 83 additions and 70 deletions

View File

@ -4,9 +4,10 @@
local M = {} local M = {}
M.options, M.ui, M.mappings, M.plugins = {}, {}, {}, {} M.options, M.ui, M.mappings, M.plugins = {}, {}, {}, {}
-- non plugin normal, available without any plugins
M.options = { M.options = {
-- NeoVim/Vim options -- custom = {}
-- general nvim/vim options , check :h optionname to know more about an option
clipboard = "unnamedplus", clipboard = "unnamedplus",
cmdheight = 1, cmdheight = 1,
ruler = false, ruler = false,
@ -16,17 +17,16 @@ M.options = {
mapleader = " ", mapleader = " ",
mouse = "a", mouse = "a",
number = true, number = true,
-- relative numbers in normal mode tool at the bottom of options.lua
numberwidth = 2, numberwidth = 2,
relativenumber = false, relativenumber = false,
expandtab = true, 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,
timeoutlen = 400, timeoutlen = 400,
-- interval for writing swap file to disk, also used by gitsigns
updatetime = 250, updatetime = 250,
undofile = true, -- keep a permanent undo (across restarts) undofile = true,
-- NvChad options -- NvChad options
nvChad = { nvChad = {
copy_cut = true, -- copy cut text ( x key ), visual and normal mode copy_cut = true, -- copy cut text ( x key ), visual and normal mode
@ -34,43 +34,46 @@ M.options = {
insert_nav = true, -- navigation in insertmode insert_nav = true, -- navigation in insertmode
window_nav = true, window_nav = true,
theme_toggler = false, theme_toggler = false,
-- used for updater
-- updater
update_url = "https://github.com/NvChad/NvChad", update_url = "https://github.com/NvChad/NvChad",
update_branch = "main", update_branch = "main",
}, },
} }
-- ui configs ---- UI -----
M.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, italic_comments = false,
-- theme to be used, check available themes with `<leader> + t + h` theme = "onedark", -- default theme
theme = "onedark",
-- toggle between two themes, see theme_toggler mappings -- toggle between two themes, see theme_toggler mappings
theme_toggler = { theme_toggler = {
"onedark", "onedark",
"gruvchad", "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 -- For Ex : if you have onedark set in nvchad, set onedark's bg color on your terminal
transparency = false, transparency = false,
} }
-- these are plugin related options ---- PLUGIN OPTIONS ----
M.plugins = { M.plugins = {
-- enable and disable plugins (false for disable) -- enable/disable plugins (false for disable)
status = { status = {
blankline = true, -- show code scope with symbols blankline = true, -- indentline stuff
bufferline = true, -- list open buffers up the top, easy switching too bufferline = true, -- manage and preview opened buffers
colorizer = false, -- color RGB, HEX, CSS, NAME color codes colorizer = false, -- color RGB, HEX, CSS, NAME color codes
comment = true, -- easily (un)comment code, language aware comment = true, -- easily (un)comment code, language aware
dashboard = false, -- NeoVim 'home screen' on open dashboard = false,
esc_insertmode = true, -- map to <ESC> with no lag esc_insertmode = true, -- map to <ESC> with no lag
feline = true, -- statusline feline = true, -- statusline
gitsigns = true, -- gitsigns in statusline gitsigns = true,
lspsignature = true, -- lsp enhancements lspsignature = true, -- lsp enhancements
telescope_media = false, -- media previews within telescope finders telescope_media = false,
vim_matchup = true, -- % operator enhancements vim_matchup = true, -- improved matchit
cmp = true, cmp = true,
nvimtree = true, nvimtree = true,
autopairs = true, autopairs = true,
@ -86,39 +89,46 @@ M.plugins = {
luasnip = { luasnip = {
snippet_path = {}, snippet_path = {},
}, },
statusline = { -- statusline related options statusline = {
-- these are filetypes, not pattern matched -- hide, show on specific filetypes
-- shown filetypes will overrule hidden filetypes
hidden = { hidden = {
"help", "help",
"dashboard", "dashboard",
"NvimTree", "NvimTree",
"terminal", "terminal",
}, },
-- show short statusline on small screens
shortline = true,
shown = {}, 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, esc_insertmode_timeout = 300,
}, },
default_plugin_config_replace = {}, default_plugin_config_replace = {},
} }
-- mappings -- don't use a single keymap twice -- -- Don't use a single keymap twice
-- non plugin mappings
--- MAPPINGS ----
-- non plugin
M.mappings = { M.mappings = {
-- custom = {}, -- all custom user mappings -- custom = {}, -- custom user mappings
-- close current focused buffer
misc = {
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 current buffer
line_number_toggle = "<leader>n", -- show or hide line number line_number_toggle = "<leader>n", -- toggle line number
new_buffer = "<S-t>", -- open a new buffer update_nvchad = "<leader>uu",
new_tab = "<C-t>b", -- open a new vim tab new_buffer = "<S-t>",
new_tab = "<C-t>b",
save_file = "<C-s>", -- save file using :w save_file = "<C-s>", -- save file using :w
theme_toggler = "<leader>tt", -- for theme toggler, see in ui.theme_toggler theme_toggler = "<leader>tt", -- 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>",
end_of_line = "<C-e>", end_of_line = "<C-e>",
@ -127,60 +137,63 @@ M.mappings = {
prev_line = "<C-j>", prev_line = "<C-j>",
beginning_of_line = "<C-a>", beginning_of_line = "<C-a>",
}, },
--better window movement
-- better window movement
window_nav = { window_nav = {
moveLeft = "<C-h>", moveLeft = "<C-h>",
moveRight = "<C-l>", moveRight = "<C-l>",
moveUp = "<C-k>", moveUp = "<C-k>",
moveDown = "<C-j>", moveDown = "<C-j>",
}, },
-- 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, esc_hide_termmode
-- get out of terminal mode -- get out of terminal mode
esc_termmode = { "jk" }, -- multiple mappings allowed esc_termmode = { "jk" },
-- get out of terminal mode and hide it -- 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 -- show & recover hidden terminal buffers in a telescope picker
pick_term = "<leader>W", pick_term = "<leader>W",
-- below three are for spawning terminals
-- spawn terminals
new_horizontal = "<leader>h", new_horizontal = "<leader>h",
new_vertical = "<leader>v", new_vertical = "<leader>v",
new_window = "<leader>w", new_window = "<leader>w",
}, },
-- update nvchad from nvchad, chadness 101
update_nvchad = "<leader>uu",
} }
-- all plugins related mappings -- plugins related mappings
M.mappings.plugins = { M.mappings.plugins = {
-- list open buffers up the top, easy switching too
bufferline = { bufferline = {
next_buffer = "<TAB>", -- next buffer next_buffer = "<TAB>",
prev_buffer = "<S-Tab>", -- previous buffer prev_buffer = "<S-Tab>",
}, },
-- easily (un)comment code, language aware
comment = { comment = {
toggle = "<leader>/", -- toggle comment (works on multiple lines) toggle = "<leader>/",
}, },
-- 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
open = "<leader>db", -- open dashboard open = "<leader>db", -- open dashboard
session_load = "<leader>l", -- load a saved session session_load = "<leader>l",
session_save = "<leader>s", -- save a session session_save = "<leader>s",
}, },
-- map to <ESC> with no lag -- map to <ESC> with no lag
better_escape = { -- <ESC> will still work better_escape = { -- <ESC> will still work
esc_insertmode = { "jk" }, -- multiple mappings allowed esc_insertmode = { "jk" }, -- multiple mappings allowed
}, },
-- file explorer/tree
nvimtree = { nvimtree = {
toggle = "<C-n>", toggle = "<C-n>",
focus = "<leader>e", focus = "<leader>e",
}, },
-- multitool for finding & picking things
telescope = { telescope = {
buffers = "<leader>fb", buffers = "<leader>fb",
find_files = "<leader>ff", find_files = "<leader>ff",
@ -191,7 +204,7 @@ M.mappings.plugins = {
live_grep = "<leader>fw", live_grep = "<leader>fw",
oldfiles = "<leader>fo", oldfiles = "<leader>fo",
themes = "<leader>th", -- NvChad theme picker themes = "<leader>th", -- NvChad theme picker
-- media previews within telescope finders
telescope_media = { telescope_media = {
media_files = "<leader>fp", media_files = "<leader>fp",
}, },

View File

@ -1,4 +1,5 @@
local hooks, M = {}, {} local hooks, M = {}, {}
local allowed_hooks = { local allowed_hooks = {
"install_plugins", "install_plugins",
"setup_mappings", "setup_mappings",

View File

@ -68,19 +68,19 @@ M.misc = function()
if nvChad_options.theme_toggler then if nvChad_options.theme_toggler then
map( map(
"n", "n",
maps.theme_toggler, maps.misc.theme_toggler,
":lua require('nvchad').toggle_theme(require('core.utils').load_config().ui.theme_toggler) <CR>" ":lua require('nvchad').toggle_theme(require('core.utils').load_config().ui.theme_toggler) <CR>"
) )
end end
end end
local function required_mappings() local function required_mappings()
map("n", maps.close_buffer, ":lua require('core.utils').close_buffer() <CR>") -- close buffer map("n", maps.misc.close_buffer, ":lua require('core.utils').close_buffer() <CR>") -- close buffer
map("n", maps.copy_whole_file, ":%y+ <CR>") -- copy whole file content map("n", maps.misc.copy_whole_file, ":%y+ <CR>") -- copy whole file content
map("n", maps.new_buffer, ":enew <CR>") -- new buffer map("n", maps.misc.new_buffer, ":enew <CR>") -- new buffer
map("n", maps.new_tab, ":tabnew <CR>") -- new tabs map("n", maps.misc.new_tab, ":tabnew <CR>") -- new tabs
map("n", maps.line_number_toggle, ":set nu! <CR>") -- toggle numbers map("n", maps.misc.line_number_toggle, ":set nu! <CR>") -- toggle numbers
map("n", maps.save_file, ":w <CR>") -- ctrl + s to save file map("n", maps.misc.save_file, ":w <CR>") -- ctrl + s to save file
-- terminal mappings -- -- terminal mappings --
local term_maps = maps.terminal local term_maps = maps.terminal
@ -107,7 +107,7 @@ M.misc = function()
-- add NvChadUpdate command and mapping -- add NvChadUpdate command and mapping
cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()"
map("n", maps.update_nvchad, ":NvChadUpdate <CR>") map("n", maps.misc.update_nvchad, ":NvChadUpdate <CR>")
-- add ChadReload command and maping -- add ChadReload command and maping
-- cmd "silent! command! NvChadReload lua require('nvchad').reload_config()" -- cmd "silent! command! NvChadReload lua require('nvchad').reload_config()"

View File

@ -154,13 +154,12 @@ M.load_config = function(reload)
} }
local default_config = "core.default_config" local default_config = "core.default_config"
local config_name = "chadrc" local config_file = vim.fn.stdpath "config" .. "/lua/custom/" .. "chadrc.lua"
local config_file = vim.fn.stdpath "config" .. "/lua/custom/" .. config_name .. ".lua"
-- unload the modules if force reload -- unload the modules if force reload
if reload then if reload then
package.loaded[default_config or false] = nil package.loaded[default_config or false] = nil
package.loaded[config_name or false] = nil package.loaded["chadrc" or false] = nil
end end
-- don't enclose in pcall, it better break when default config is faulty -- 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 -- print warning texts if user config file is present
-- check if the user config is present -- check if the user config is present
if vim.fn.filereadable(vim.fn.glob(config_file)) == 1 then 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 if present then
-- make sure the returned value is table -- make sure the returned value is table
if type(config) == "table" then if type(config) == "table" then
@ -182,7 +181,7 @@ M.load_config = function(reload)
to_replace to_replace
) )
else 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 end
else else
print("Warning: " .. config_file .. " is present but sourcing failed.") print("Warning: " .. config_file .. " is present but sourcing failed.")