diff --git a/install.sh b/install.sh index 5cc3af5..1558e59 100755 --- a/install.sh +++ b/install.sh @@ -18,7 +18,7 @@ dependencies=( ) preserved_files=( "lua/mappings.lua" - "lua/user_config.lua" + "lua/chadrc.lua" ) # https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux diff --git a/lua/chadrc.lua b/lua/chadrc.lua new file mode 100644 index 0000000..e006e11 --- /dev/null +++ b/lua/chadrc.lua @@ -0,0 +1,100 @@ +local M = { + ui = { + theme = "onedark" + }, + options = { + permanent_undo = true, + ruler = false, + hidden = true, + ignorecase = true, + mouse = "a", + cmdheight = 1, + updatetime = 250, + timeoutlen = 400, + clipboard = "unnamedplus", + number = true, + numberwidth = 2, + expandtab = true, + shiftwidth = 2, + smartindent = true, + mapleader = " ", + autosave = false + }, + -- enable / disable plugins (true for disable) + plugin_status = { + better_esc = false, + nvim_bufferline = false, + galaxyline = false, + nvim_colorizer = false, + lspkind = false, + lspsignature = false, + neoformat = false, + gitsigns = false, + vim_matchup = false, + dashboard_nvim = false, + autosave_nvim = false, + truezen_nvim = false, + blankline = false, + vim_fugitive = false, + nvim_comment = false, + neoscroll_nvim = false + }, + -- make sure you dont use same keys twice + mappings = { + truezen = { + ataraxisMode = "zz", + minimalisticmode = "zm", + focusmode = "zf" + }, + comment_nvim = { + comment_toggle = "/" + }, + nvimtree = { + treetoggle = "" + }, + neoformat = { + format = "fm" + }, + dashboard = { + open = "db", + newfile = "fn", + bookmarks = "bm", + sessionload = "l", + sessionsave = "s" + }, + telescope = { + live_grep = "fw", + git_status = "gt", + git_commits = "cm", + find_files = "ff", + media_files = "fp", + buffers = "fb", + help_tags = "fh", + oldfiles = "fo", + themes = "th" + }, + bufferline = { + new_buffer = "", + newtab = "b", + close = "", + cycleNext = "", + cyclePrev = "" + }, + fugitive = { + Git = "gs", + diffget_2 = "gh", + diffget_3 = "gl", + git_blame = "gb" + }, + misc = { + openTerm_right = "", + openTerm_bottom = "", + openTerm_currentBuf = "t", + copywhole_file = "", + toggle_linenr = "n", + esc_Termmode = "jk" + } + } +} + +return M diff --git a/lua/highlights.lua b/lua/highlights.lua index 44a6d5b..dfea700 100644 --- a/lua/highlights.lua +++ b/lua/highlights.lua @@ -76,7 +76,7 @@ fg("NvimTreeVertSplit", darker_black) bg("NvimTreeVertSplit", darker_black) fg("NvimTreeEndOfBuffer", darker_black) -vim.cmd("hi NvimTreeRootFolder gui=underline guifg=" .. purple) +cmd("hi NvimTreeRootFolder gui=underline guifg=" .. purple) bg("NvimTreeNormal", darker_black) fg_bg("NvimTreeStatuslineNc", darker_black, darker_black) fg_bg("NvimTreeWindowPicker", red, black2) diff --git a/lua/mappings.lua b/lua/mappings.lua index 5562bb5..b1f16c9 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -1,3 +1,9 @@ +local user_map = require("chadrc").mappings +local miscMap = user_map.misc + +local M = {} +local cmd = vim.cmd + local function map(mode, lhs, rhs, opts) local options = {noremap = true, silent = true} if opts then @@ -30,26 +36,31 @@ map("", "", 'v:count ? "j" : "gj"', {expr = true}) map("", "", 'v:count ? "k" : "gk"', {expr = true}) -- OPEN TERMINALS -- -map("n", "", ":vnew +terminal | setlocal nobuflisted ", opt) -- term over right -map("n", "", ":10new +terminal | setlocal nobuflisted ", opt) -- term bottom -map("n", "t", ":terminal ", opt) -- term buffer +map("n", miscMap.openTerm_right, ":vnew +terminal | setlocal nobuflisted ", opt) -- term over right +map("n", miscMap.openTerm_bottom, ":10new +terminal | setlocal nobuflisted ", opt) -- term bottom +map("n", miscMap.openTerm_currentBuf, ":terminal ", opt) -- term buffer -- copy whole file content -map("n", "", ":%y+", opt) +map("n", miscMap.copywhole_file, ":%y+", opt) -- toggle numbers -map("n", "n", ":set nu!", opt) +map("n", miscMap.toggle_linenr, ":set nu!", opt) --- Truezen.nvim -map("n", "zz", ":TZAtaraxis", opt) -map("n", "zm", ":TZMinimalist", opt) -map("n", "zf", ":TZFocus", opt) +M.truezen = function() + local m = user_map.truezen + + map("n", m.ataraxisMode, ":TZAtaraxis", opt) + map("n", m.minimalisticmode, ":TZMinimalist", opt) + map("n", m.focusmode, ":TZFocus", opt) +end map("n", "", ":w ", opt) --- Commenter Keybinding -map("n", "/", ":CommentToggle", opt) -map("v", "/", ":CommentToggle", opt) +M.comment_nvim = function() + local m = user_map.comment_nvim.comment_toggle + map("n", m, ":CommentToggle", opt) + map("v", m, ":CommentToggle", opt) +end -- compe stuff local t = function(str) @@ -112,54 +123,74 @@ map("i", "", "v:lua.s_tab_complete()", {expr = true}) map("s", "", "v:lua.s_tab_complete()", {expr = true}) map("i", "", "v:lua.completions()", {expr = true}) --- nvimtree -map("n", "", ":NvimTreeToggle", opt) +M.nvimtree = function() + local m = user_map.nvimtree.treetoggle --- format code -map("n", "fm", ":Neoformat", opt) + map("n", m, ":NvimTreeToggle", opt) +end --- dashboard stuff -map("n", "db", ":Dashboard", opt) -map("n", "fn", ":DashboardNewFile", opt) -map("n", "bm", ":DashboardJumpMarks", opt) -map("n", "l", ":SessionLoad", opt) -map("n", "s", ":SessionSave", opt) +M.neoformat = function() + local m = user_map.neoformat.format + map("n", m, ":Neoformat", opt) +end --- Telescope -map("n", "fw", ":Telescope live_grep", opt) -map("n", "gt", ":Telescope git_status ", opt) -map("n", "cm", ":Telescope git_commits ", opt) -map("n", "ff", ":Telescope find_files ", opt) -map("n", "fp", ":Telescope media_files ", opt) -map("n", "fb", ":Telescope buffers", opt) -map("n", "fh", ":Telescope help_tags", opt) -map("n", "fo", ":Telescope oldfiles", opt) -map("n", "th", ":Telescope themes", opt) +M.dashboard = function() + local m = user_map.dashboard --- bufferline tab stuff -map("n", "", ":enew", opt) -- new buffer -map("n", "b", ":tabnew", opt) -- new tab -map("n", "", ":bd!", opt) -- close tab + map("n", m.open, ":Dashboard", opt) + map("n", m.newfile, ":DashboardNewFile", opt) + map("n", m.bookmarks, ":DashboardJumpMarks", opt) + map("n", m.sessionload, ":SessionLoad", opt) + map("n", m.sessionsave, ":SessionSave", opt) +end --- move between tabs -map("n", "", ":BufferLineCycleNext", opt) -map("n", "", ":BufferLineCyclePrev", opt) +M.telescope = function() + local m = user_map.telescope + + map("n", m.live_grep, ":Telescope live_grep", opt) + map("n", m.git_status, ":Telescope git_status ", opt) + map("n", m.git_commits, ":Telescope git_commits ", opt) + map("n", m.find_files, ":Telescope find_files ", opt) + map("n", m.media_files, ":Telescope media_files ", opt) + map("n", m.buffers, ":Telescope buffers", opt) + map("n", m.help_tags, ":Telescope help_tags", opt) + map("n", m.oldfiles, ":Telescope oldfiles", opt) + map("n", m.themes, ":Telescope themes", opt) +end + +M.bufferline = function() + local m = user_map.bufferline + + map("n", m.new_buffer, ":enew", opt) -- new buffer + map("n", m.newtab, ":tabnew", opt) -- new tab + map("n", m.close, ":bd!", opt) -- close buffer + + -- move between tabs + + map("n", m.cycleNext, ":BufferLineCycleNext", opt) + map("n", m.cyclePrev, ":BufferLineCyclePrev", opt) +end -- use ESC to turn off search highlighting map("n", "", ":noh", opt) -- get out of terminal with jk -map("t", "jk", "", opt) +map("t", miscMap.esc_Termmode, "", opt) -- Packer commands till because we are not loading it at startup -vim.cmd("silent! command PackerCompile lua require 'pluginList' require('packer').compile()") -vim.cmd("silent! command PackerInstall lua require 'pluginList' require('packer').install()") -vim.cmd("silent! command PackerStatus lua require 'pluginList' require('packer').status()") -vim.cmd("silent! command PackerSync lua require 'pluginList' require('packer').sync()") -vim.cmd("silent! command PackerUpdate lua require 'pluginList' require('packer').update()") +cmd("silent! command PackerCompile lua require 'pluginList' require('packer').compile()") +cmd("silent! command PackerInstall lua require 'pluginList' require('packer').install()") +cmd("silent! command PackerStatus lua require 'pluginList' require('packer').status()") +cmd("silent! command PackerSync lua require 'pluginList' require('packer').sync()") +cmd("silent! command PackerUpdate lua require 'pluginList' require('packer').update()") --- Vim Fugitive -map("n", "gs", ":Git", opt) -map("n", "gh", ":diffget //2", opt) -map("n", "gl", ":diffget //3", opt) -map("n", "gb", ":Git blame", opt) +M.fugitive = function() + local m = user_map.fugitive + + map("n", m.Git, ":Git", opt) + map("n", m.diffget_2, ":diffget //2", opt) + map("n", m.diffget_3, ":diffget //3", opt) + map("n", m.git_blame, ":Git blame", opt) +end + +return M diff --git a/lua/options.lua b/lua/options.lua index 50d63ba..15abb39 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,20 +1,21 @@ +local options = require("chadrc").options local opt = vim.opt local g = vim.g -opt.undofile = true -opt.ruler = false -opt.hidden = true -opt.ignorecase = true +opt.undofile = options.permanent_undo +opt.ruler = options.ruler +opt.hidden = options.hidden +opt.ignorecase = options.ignorecase opt.splitbelow = true opt.splitright = true opt.termguicolors = true opt.cul = true -opt.mouse = "a" +opt.mouse = options.mouse opt.signcolumn = "yes" -opt.cmdheight = 1 -opt.updatetime = 250 -- update interval for gitsigns -opt.timeoutlen = 400 -opt.clipboard = "unnamedplus" +opt.cmdheight = options.cmdheight +opt.updatetime = options.updatetime -- update interval for gitsigns +opt.timeoutlen = options.timeoutlen +opt.clipboard = options.clipboard -- disable nvim intro opt.shortmess:append("sI") @@ -23,21 +24,21 @@ opt.shortmess:append("sI") opt.fillchars = {eob = " "} -- Numbers -opt.number = true -opt.numberwidth = 2 +opt.number = options.number +opt.numberwidth = options.numberwidth -- opt.relativenumber = true -- Indenline -opt.expandtab = true -opt.shiftwidth = 2 -opt.smartindent = true +opt.expandtab = options.expandtab +opt.shiftwidth = options.shiftwidth +opt.smartindent = options.smartindent -- go to previous/next line with h,l,left arrow and right arrow -- when cursor reaches end/beginning of line opt.whichwrap:append("<>hl") -g.mapleader = " " -g.auto_save = false +g.mapleader = options.mapleader +g.auto_save = options.autosave -- disable builtin vim plugins local disabled_built_ins = { @@ -62,7 +63,7 @@ local disabled_built_ins = { } for _, plugin in pairs(disabled_built_ins) do - vim.g["loaded_" .. plugin] = 1 + g["loaded_" .. plugin] = 1 end -- Don't show status line on vim terminals diff --git a/lua/packerInit.lua b/lua/packerInit.lua index aa9101a..73975bb 100644 --- a/lua/packerInit.lua +++ b/lua/packerInit.lua @@ -1,4 +1,6 @@ -vim.cmd("packadd packer.nvim") +local cmd = vim.cmd + +cmd("packadd packer.nvim") local present, packer = pcall(require, "packer") @@ -19,7 +21,7 @@ if not present then } ) - vim.cmd("packadd packer.nvim") + cmd("packadd packer.nvim") present, packer = pcall(require, "packer") if present then @@ -33,9 +35,13 @@ return packer.init { display = { open_fn = function() return require("packer.util").float {border = "single"} - end + end, + prompt_border = "single" }, git = { clone_timeout = 600 -- Timeout, in seconds, for git clones - } + }, + auto_clean = true, + compile_on_sync = true + -- auto_reload_compiled = true } diff --git a/lua/pluginList.lua b/lua/pluginList.lua index 3701f1e..bf7c76b 100644 --- a/lua/pluginList.lua +++ b/lua/pluginList.lua @@ -1,3 +1,5 @@ +local plugin_status = require("chadrc").plugin_status + local present, _ = pcall(require, "packerInit") local packer @@ -18,6 +20,7 @@ return packer.startup( use { "jdhao/better-escape.vim", + disable = plugin_status.better_esc, event = "InsertEnter", config = function() require "plugins.others".escape() @@ -26,14 +29,19 @@ return packer.startup( use { "akinsho/nvim-bufferline.lua", + disable = plugin_status.nvim_bufferline, after = "nvim-base16.lua", config = function() require "plugins.bufferline" + end, + setup = function() + require "mappings".bufferline() end } use { "glepnir/galaxyline.nvim", + disable = plugin_status.galaxyline, after = "nvim-base16.lua", config = function() require "plugins.statusline" @@ -51,6 +59,7 @@ return packer.startup( use { "norcalli/nvim-colorizer.lua", + disable = plugin_status.nvim_colorizer, event = "BufRead", config = function() require("plugins.others").colorizer() @@ -81,6 +90,7 @@ return packer.startup( use { "onsails/lspkind-nvim", + disable = plugin_status.lspkind, event = "BufEnter", config = function() require("plugins.others").lspkind() @@ -89,6 +99,7 @@ return packer.startup( use { "ray-x/lsp_signature.nvim", + disable = plugin_status.lspsignature, after = "nvim-lspconfig", config = function() require("plugins.others").signature() @@ -121,7 +132,11 @@ return packer.startup( use { "sbdchd/neoformat", - cmd = "Neoformat" + disable = plugin_status.neoformat, + cmd = "Neoformat", + setup = function() + require "mappings".neoformat() + end } -- file managing , picker etc @@ -130,6 +145,9 @@ return packer.startup( cmd = "NvimTreeToggle", config = function() require "plugins.nvimtree" + end, + setup = function() + require "mappings".nvimtree() end } @@ -155,6 +173,9 @@ return packer.startup( cmd = "Telescope", config = function() require "plugins.telescope" + end, + setup = function() + require "mappings".telescope() end } @@ -171,6 +192,7 @@ return packer.startup( -- git stuff use { "lewis6991/gitsigns.nvim", + disable = plugin_status.gitsigns, after = "plenary.nvim", config = function() require "plugins.gitsigns" @@ -188,19 +210,23 @@ return packer.startup( use { "andymass/vim-matchup", + disable = plugin_status.vim_matchup, event = "CursorMoved" } use { "terrortylor/nvim-comment", + disable = plugin_status.nvim_comment, cmd = "CommentToggle", config = function() require("plugins.others").comment() + require "mappings".comment_nvim() end } use { "glepnir/dashboard-nvim", + disable = plugin_status.dashboard_nvim, cmd = { "Dashboard", "DashboardNewFile", @@ -210,11 +236,13 @@ return packer.startup( }, setup = function() require "plugins.dashboard" + require "mappings".dashboard() end } -- load autosave only if its globally enabled use { + disable = plugin_status.autosave_nvim, "Pocco81/AutoSave.nvim", config = function() require "plugins.autosave" @@ -227,6 +255,7 @@ return packer.startup( -- smooth scroll use { "karb94/neoscroll.nvim", + disable = plugin_status.neoscroll_nvim, event = "WinScrolled", config = function() require("plugins.others").neoscroll() @@ -235,6 +264,7 @@ return packer.startup( use { "Pocco81/TrueZen.nvim", + disable = plugin_status.truezen_nvim, cmd = { "TZAtaraxis", "TZMinimalist", @@ -242,6 +272,9 @@ return packer.startup( }, config = function() require "plugins.zenmode" + end, + setup = function() + require "mappings".truezen() end } @@ -249,6 +282,7 @@ return packer.startup( use { "lukas-reineke/indent-blankline.nvim", + disable = plugin_status.blankline, event = "BufRead", setup = function() require("plugins.others").blankline() @@ -257,9 +291,13 @@ return packer.startup( use { "tpope/vim-fugitive", + disable = plugin_status.vim_fugitive, cmd = { "Git" - } + }, + setup = function() + require "mappings".fugitive() + end } end ) diff --git a/lua/theme.lua b/lua/theme.lua index 2de9294..1e0d36b 100644 --- a/lua/theme.lua +++ b/lua/theme.lua @@ -1,4 +1,4 @@ -local chad_theme = require("user_config").ui.theme +local chad_theme = require("chadrc").ui.theme vim.g.nvchad_theme = chad_theme local present, base16 = pcall(require, "base16") diff --git a/lua/user_config.lua b/lua/user_config.lua deleted file mode 100644 index bd0f741..0000000 --- a/lua/user_config.lua +++ /dev/null @@ -1,7 +0,0 @@ -local M = { - ui = { - theme = "onedark" - } -} - -return M diff --git a/lua/utils.lua b/lua/utils.lua index 87e1e48..ced2dc7 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -84,7 +84,7 @@ M.change_theme = function(current_theme, new_theme) return end - local file = vim.fn.stdpath("config") .. "/lua/user_config.lua" + local file = vim.fn.stdpath("config") .. "/lua/chadrc.lua" -- store in data variable local data = assert(M.file("r", file)) local find = "theme = .?" .. current_theme .. ".?"