refactor: Cleaning chadrc, moved to custom & moved default_config to core

This commit is contained in:
Galen Rowell 2021-09-04 00:03:25 +10:00 committed by siduck76
parent 22f89cfeef
commit ca1ad15ad2
7 changed files with 53 additions and 241 deletions

View file

@ -1,224 +0,0 @@
-- IMPORTANT NOTE : This is the user config, can be edited. Will be preserved if updated with internal updater
local M = {}
M.ui, M.options, M.plugin_status, M.mappings, M.custom = {}, {}, {}, {}, {}
-- 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 = {},
shown = {},
-- default, round , slant , block , arrow
style = "default",
},
}
-- non plugin normal, available without any plugins
M.options = {
clipboard = "unnamedplus",
cmdheight = 1,
copy_cut = true, -- copy cut text ( x key ), visual and normal mode
copy_del = true, -- copy deleted text ( dd key ), visual and normal mode
expandtab = true,
hidden = true,
ignorecase = true,
insert_nav = true, -- navigation in insertmode
mapleader = " ",
mouse = "a",
number = true,
-- relative numbers in normal mode tool at the bottom of options.lua
numberwidth = 2,
permanent_undo = true,
shiftwidth = 2,
smartindent = true,
tabstop = 8, -- Number of spaces that a <Tab> in the file counts for
timeoutlen = 400,
relativenumber = false,
ruler = false,
updatetime = 250,
-- used for updater
update_url = "https://github.com/NvChad/NvChad",
update_branch = "main",
}
-- these are plugin related options
M.options.plugin = {
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,
}
-- enable and disable plugins (false for disable)
M.plugin_status = {
autosave = false, -- to autosave files
blankline = true, -- beautified blank lines
bufferline = true, -- buffer shown as tabs
cheatsheet = true, -- fuzzy search your commands/keymappings
colorizer = true,
comment = true, -- universal commentor
dashboard = false, -- a nice looking dashboard
esc_insertmode = true, -- escape from insert mode using custom keys
feline = true, -- statusline
gitsigns = true, -- gitsigns in statusline
lspsignature = true, -- lsp enhancements
neoformat = true, -- universal formatter
neoscroll = true, -- smooth scroll
telescope_media = false, -- see media files in telescope picker
truezen = false, -- no distraction mode for nvim
vim_fugitive = false, -- git in nvim
vim_matchup = true, -- % magic, match it but improved
}
-- mappings -- don't use a single keymap twice --
-- non plugin mappings
M.mappings = {
-- close current focused buffer
close_buffer = "<leader>x",
copy_whole_file = "<C-a>", -- copy all contents of the current buffer
-- navigation in insert mode, only if enabled in options
insert_nav = {
backward = "<C-h>",
end_of_line = "<C-e>",
forward = "<C-l>",
next_line = "<C-k>",
prev_line = "<C-j>",
top_of_line = "<C-a>",
},
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 = {
-- multiple mappings can be given for esc_termmode and esc_hide_termmode
-- get out of terminal mode
esc_termmode = { "jk" }, -- multiple mappings allowed
-- 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
-- show hidden terminal buffers in a telescope picker
pick_term = "<leader>W",
-- below three are for spawning terminals
new_horizontal = "<leader>h",
new_vertical = "<leader>v",
new_window = "<leader>w",
},
-- update nvchad from nvchad, chadness 101
update_nvchad = "<leader>uu",
}
-- 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.plugin = {
bufferline = {
next_buffer = "<TAB>", -- next buffer
prev_buffer = "<S-Tab>", -- previous buffer
--better window movement
moveLeft = "<C-h>",
moveRight = "<C-l>",
moveUp = "<C-k>",
moveDown = "<C-j>",
},
chadsheet = {
default_keys = "<leader>dk",
user_keys = "<leader>uk",
},
comment = {
toggle = "<leader>/", -- trigger comment on a single/selected lines/number prefix
},
dashboard = {
bookmarks = "<leader>bm",
new_file = "<leader>fn", -- basically create a new buffer
open = "<leader>db", -- open dashboard
session_load = "<leader>l", -- load a saved session
session_save = "<leader>s", -- save a session
},
-- note: this is an edditional mapping to escape, escape key will still work
better_escape = {
esc_insertmode = { "jk" }, -- multiple mappings allowed
},
nvimtree = {
toggle = "<C-n>", -- file manager
},
neoformat = {
format = "<leader>fm",
},
telescope = {
buffers = "<leader>fb",
find_files = "<leader>ff",
git_commits = "<leader>cm",
git_status = "<leader>gt",
help_tags = "<leader>fh",
live_grep = "<leader>fw",
oldfiles = "<leader>fo",
themes = "<leader>th",
},
telescope_media = {
media_files = "<leader>fp",
},
truezen = { -- distraction free modes mapping, hide statusline, tabline, line numbers
ataraxis_mode = "<leader>zz", -- center
focus_mode = "<leader>zf",
minimalistic_mode = "<leader>zm", -- as it is
},
vim_fugitive = {
diff_get_2 = "<leader>gh",
diff_get_3 = "<leader>gl",
git = "<leader>gs",
git_blame = "<leader>gb",
},
}
-- 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

View file

@ -1,4 +1,5 @@
-- IMPORTANT NOTE : This is default config, so dont change anything here. (check chadrc.lua instead) -- IMPORTANT NOTE : This is default config, so dont change anything here.
-- use custom/chadrc.lua instead
local M = {} local M = {}
M.ui, M.options, M.plugin_status, M.mappings, M.custom = {}, {}, {}, {}, {} M.ui, M.options, M.plugin_status, M.mappings, M.custom = {}, {}, {}, {}, {}
@ -147,8 +148,14 @@ M.mappings.plugin = {
bufferline = { bufferline = {
next_buffer = "<TAB>", -- next buffer next_buffer = "<TAB>", -- next buffer
prev_buffer = "<S-Tab>", -- previous buffer prev_buffer = "<S-Tab>", -- previous buffer
--TODO move out of bufferline
--better window movement
moveLeft = "<C-h>",
moveRight = "<C-l>",
moveUp = "<C-k>",
moveDown = "<C-j>",
}, },
chadsheet = { cheatsheet = {
default_keys = "<leader>dk", default_keys = "<leader>dk",
user_keys = "<leader>uk", user_keys = "<leader>uk",
}, },
@ -160,7 +167,7 @@ M.mappings.plugin = {
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", -- load a saved session
session_save = "<leader>s", session_save = "<leader>s", -- save a session
}, },
-- note: this is an edditional mapping to escape, escape key will still work -- note: this is an edditional mapping to escape, escape key will still work
better_escape = { better_escape = {

View file

@ -131,8 +131,8 @@ M.bufferline = function()
map("n", m.moveDown, "<C-w>j") map("n", m.moveDown, "<C-w>j")
end end
M.chadsheet = function() M.cheatsheet = function()
local m = plugin_maps.chadsheet local m = plugin_maps.cheatsheet
map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope() <CR>") map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope() <CR>")
map( map(

View file

@ -152,9 +152,9 @@ M.load_config = function(reload)
"['mappings']['terminal']['esc_hide_termmode']", "['mappings']['terminal']['esc_hide_termmode']",
} }
local default_config = "default_config" local default_config = "core.default_config"
local config_name = vim.g.nvchad_user_config or "chadrc" local config_name = vim.g.nvchad_user_config or "chadrc"
local config_file = vim.fn.stdpath "config" .. "/lua/" .. config_name .. ".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
@ -170,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, config_name) local present, config = pcall(require, "custom/" .. config_name)
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

29
lua/custom/chadrc.lua Normal file
View file

@ -0,0 +1,29 @@
-- IMPORTANT NOTE : This is the user config, can be edited. Will be preserved if updated with internal updater
local M = {}
M.ui, M.options, M.plugin_status, M.mappings, M.custom = {}, {}, {}, {}, {}
-- To use this file, copy the strucutre of `core/default_config.lua`,
-- then define your new var, an example of setting relative number:
-- M.options = {
-- relativenumber = true,
-- }
-- 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",
-- },
}
return M

View file

@ -1,4 +1,4 @@
local present, chadsheet = pcall(require, "cheatsheet") local present, cheatsheet = pcall(require, "cheatsheet")
if not present then if not present then
return return
@ -8,28 +8,28 @@ local mappings = require("core.utils").load_config().mappings
-- add user mappings to the cheetsheet -- add user mappings to the cheetsheet
-- improve this function to not hardcode plugin -- improve this function to not hardcode plugin
local function add_to_chadsheet(section, keymap, desc) local function add_to_cheatsheet(section, keymap, desc)
if section == "plugin" then if section == "plugin" then
for sec, key in pairs(mappings.plugin) do for sec, key in pairs(mappings.plugin) do
add_to_chadsheet(sec, key, sec) add_to_cheatsheet(sec, key, sec)
end end
else else
if type(keymap) == "table" then if type(keymap) == "table" then
for sec, key in pairs(keymap) do for sec, key in pairs(keymap) do
if type(sec) == "number" then if type(sec) == "number" then
add_to_chadsheet(section, key, desc or section) add_to_cheatsheet(section, key, desc or section)
else else
add_to_chadsheet(sec, key, desc or section) add_to_cheatsheet(sec, key, desc or section)
end end
end end
else else
chadsheet.add_cheat(section, keymap, desc or "Misc") cheatsheet.add_cheat(section, keymap, desc or "Misc")
end end
end end
end end
for section, keymap in pairs(mappings) do for section, keymap in pairs(mappings) do
add_to_chadsheet(section, keymap) add_to_cheatsheet(section, keymap)
end end
require("cheatsheet").setup { require("cheatsheet").setup {

View file

@ -280,10 +280,10 @@ return packer.startup(function()
disable = not plugin_status.cheatsheet, disable = not plugin_status.cheatsheet,
after = "telescope.nvim", after = "telescope.nvim",
config = function() config = function()
require "plugins.configs.chadsheet" require "plugins.configs.cheatsheet"
end, end,
setup = function() setup = function()
require("core.mappings").chadsheet() require("core.mappings").cheatsheet()
end, end,
}, },
{ {