From 9ffddb6b524aaef2bc2b1b89f52875a452781908 Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Sun, 22 Aug 2021 13:19:15 +0530 Subject: [PATCH] Restructure config | Move some to a packer plugin | Lot of cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * move teleacope files, updater and related utils to https://github.com/NvChad/core * restructure config file and directory structure * expose mappings for better escape * allow multiple mappings for some * improve merge table function for the same * move autocommands to a seperate file * rearrange everything alphabetically where sanely possible * rearrange packer plugin list on the basis of trigerred state config structure now . ├── init.lua ├── LICENSE ├── lua │ ├── chadrc.lua │ ├── colors │ │ ├── highlights.lua │ │ ├── init.lua │ │ └── themes │ │ ├── chadracula.lua │ │ ├── everforest.lua │ │ ├── gruvchad.lua │ │ ├── javacafe.lua │ │ ├── mountain.lua │ │ ├── norchad.lua │ │ ├── one-light.lua │ │ ├── onedark.lua │ │ ├── tokyonight.lua │ │ └── tomorrow-night.lua │ ├── core │ │ ├── autocmds.lua │ │ ├── init.lua │ │ ├── mappings.lua │ │ ├── options.lua │ │ └── utils.lua │ ├── default_config.lua │ └── plugins │ ├── configs │ │ ├── autopairs.lua │ │ ├── autosave.lua │ │ ├── bufferline.lua │ │ ├── chadsheet.lua │ │ ├── compe.lua │ │ ├── dashboard.lua │ │ ├── gitsigns.lua │ │ ├── icons.lua │ │ ├── lspconfig.lua │ │ ├── luasnip.lua │ │ ├── nvimtree.lua │ │ ├── others.lua │ │ ├── statusline.lua │ │ ├── telescope.lua │ │ ├── treesitter.lua │ │ └── zenmode.lua │ ├── init.lua │ └── packerInit.lua └── README.md --- init.lua | 14 +- lua/chadrc.lua | 264 +++++----- lua/{ => colors}/highlights.lua | 152 +++--- lua/colors/init.lua | 36 ++ lua/{ => colors}/themes/chadracula.lua | 0 lua/{ => colors}/themes/everforest.lua | 0 lua/{ => colors}/themes/gruvchad.lua | 0 lua/{ => colors}/themes/javacafe.lua | 0 lua/{ => colors}/themes/mountain.lua | 0 lua/{ => colors}/themes/norchad.lua | 0 lua/{ => colors}/themes/one-light.lua | 0 lua/{ => colors}/themes/onedark.lua | 0 lua/{ => colors}/themes/tokyonight.lua | 0 lua/{ => colors}/themes/tomorrow-night.lua | 0 lua/core/autocmds.lua | 17 + lua/core/init.lua | 15 + lua/core/mappings.lua | 202 ++++++++ lua/{ => core}/options.lua | 86 ++-- lua/core/utils.lua | 265 ++++++++++ lua/default_config.lua | 266 ++++++----- lua/mappings.lua | 188 -------- lua/plugins/chadsheet.lua | 25 - lua/plugins/{ => configs}/autopairs.lua | 2 +- lua/plugins/{ => configs}/autosave.lua | 6 +- lua/plugins/{ => configs}/bufferline.lua | 110 ++--- lua/plugins/configs/chadsheet.lua | 44 ++ lua/plugins/{ => configs}/compe.lua | 11 +- lua/plugins/{ => configs}/dashboard.lua | 2 +- lua/plugins/{ => configs}/gitsigns.lua | 24 +- lua/plugins/{ => configs}/icons.lua | 121 +++-- lua/plugins/{ => configs}/lspconfig.lua | 12 +- lua/plugins/{ => configs}/luasnip.lua | 6 +- lua/plugins/{ => configs}/nvimtree.lua | 47 +- lua/plugins/{ => configs}/others.lua | 32 +- lua/plugins/{ => configs}/statusline.lua | 37 +- lua/plugins/{ => configs}/telescope.lua | 24 +- lua/plugins/{ => configs}/treesitter.lua | 0 lua/plugins/{ => configs}/zenmode.lua | 2 +- lua/{pluginList.lua => plugins/init.lua} | 330 ++++++------- lua/{ => plugins}/packerInit.lua | 4 +- lua/telescope/_extensions/terms.lua | 143 ------ lua/telescope/_extensions/themes.lua | 142 ------ lua/theme.lua | 12 - lua/utils.lua | 531 --------------------- 44 files changed, 1383 insertions(+), 1789 deletions(-) rename lua/{ => colors}/highlights.lua (79%) create mode 100644 lua/colors/init.lua rename lua/{ => colors}/themes/chadracula.lua (100%) rename lua/{ => colors}/themes/everforest.lua (100%) rename lua/{ => colors}/themes/gruvchad.lua (100%) rename lua/{ => colors}/themes/javacafe.lua (100%) rename lua/{ => colors}/themes/mountain.lua (100%) rename lua/{ => colors}/themes/norchad.lua (100%) rename lua/{ => colors}/themes/one-light.lua (100%) rename lua/{ => colors}/themes/onedark.lua (100%) rename lua/{ => colors}/themes/tokyonight.lua (100%) rename lua/{ => colors}/themes/tomorrow-night.lua (100%) create mode 100644 lua/core/autocmds.lua create mode 100644 lua/core/init.lua create mode 100644 lua/core/mappings.lua rename lua/{ => core}/options.lua (56%) create mode 100644 lua/core/utils.lua delete mode 100644 lua/mappings.lua delete mode 100644 lua/plugins/chadsheet.lua rename lua/plugins/{ => configs}/autopairs.lua (100%) rename lua/plugins/{ => configs}/autosave.lua (85%) rename lua/plugins/{ => configs}/bufferline.lua (97%) create mode 100644 lua/plugins/configs/chadsheet.lua rename lua/plugins/{ => configs}/compe.lua (99%) rename lua/plugins/{ => configs}/dashboard.lua (95%) rename lua/plugins/{ => configs}/gitsigns.lua (99%) rename lua/plugins/{ => configs}/icons.lua (96%) rename lua/plugins/{ => configs}/lspconfig.lua (100%) rename lua/plugins/{ => configs}/luasnip.lua (100%) rename lua/plugins/{ => configs}/nvimtree.lua (99%) rename lua/plugins/{ => configs}/others.lua (91%) rename lua/plugins/{ => configs}/statusline.lua (97%) rename lua/plugins/{ => configs}/telescope.lua (86%) rename lua/plugins/{ => configs}/treesitter.lua (100%) rename lua/plugins/{ => configs}/zenmode.lua (100%) rename lua/{pluginList.lua => plugins/init.lua} (66%) rename lua/{ => plugins}/packerInit.lua (97%) delete mode 100644 lua/telescope/_extensions/terms.lua delete mode 100644 lua/telescope/_extensions/themes.lua delete mode 100644 lua/theme.lua delete mode 100644 lua/utils.lua diff --git a/init.lua b/init.lua index 6353271..08b4f10 100644 --- a/init.lua +++ b/init.lua @@ -1,12 +1,10 @@ -local chad_modules = { - "options", - "mappings", +local init_modules = { + "core", } -for i = 1, #chad_modules, 1 do - if not pcall(require, chad_modules[i]) then - error("Error loading " .. chad_modules[i] .. "\n") +for _, module in ipairs(init_modules) do + local ok, err = pcall(require, module) + if not ok then + error("Error loading " .. module .. "\n\n" .. err) end end - -require("mappings").misc() diff --git a/lua/chadrc.lua b/lua/chadrc.lua index 522b9e8..8a35f0f 100644 --- a/lua/chadrc.lua +++ b/lua/chadrc.lua @@ -1,161 +1,191 @@ --- IMPORTANT NOTE : This is user config +-- IMPORTANT NOTE : This is the user config, can be edited. Will be preserved if updated with internal updater local M = {} M.ui = { + italic_comments = false, + + -- theme to be used, to see all available themes, open the theme switcher by + th theme = "onedark", - -- theme toggle - theme_toggler = false, - fav_themes = { - "onedark", - "gruvchad", + -- theme toggler, toggle between two themes, see theme_toggleer mappings + theme_toggler = { + enabled = false, + fav_themes = { + "onedark", + "gruvchad", + }, }, - italic_comments = false, -- 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, - -- 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 = { - -- "terminal" + -- plugin related ui options + 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 = { + -- "terminal" + }, + -- default, round , slant , block , arrow + style = "default", }, - style = "default", -- default, round , slant , block , arrow }, } M.options = { - permanent_undo = true, - ruler = false, + clipboard = "unnamedplus", + cmdheight = 1, + expandtab = true, hidden = true, ignorecase = true, + insert_nav = true, -- navigation in insertmode + mapleader = " ", mouse = "a", - cmdheight = 1, - updatetime = 250, - timeoutlen = 400, - clipboard = "unnamedplus", number = true, -- relative numbers in normal mode tool at the bottom of options.lua - relativenumber = false, numberwidth = 2, - expandtab = true, + permanent_undo = true, shiftwidth = 2, smartindent = true, - mapleader = " ", - autosave = false, - enable_insertNav = true, -- navigation in insertmode + 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 + 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 = { - -- UI - nvim_bufferline = true, - galaxyline = true, - nvim_colorizer = true, - dashboard_nvim = true, - blankline = true, - truezen_nvim = true, - better_esc = true, - -- lsp stuff - lspkind = true, - lspsignature = true, - -- git stuff - gitsigns = true, - vim_fugitive = true, - -- misc - neoformat = true, - vim_matchup = true, - autosave_nvim = true, - nvim_comment = true, - neoscroll_nvim = true, - telescope_media = true, - cheatsheet = true, + autosave = true, -- 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 = true, -- a nice looking dashboard + esc_insertmode = true, -- escape from insert mode using custom keys + galaxyline = true, -- statusline + gitsigns = true, -- gitsigns in statusline + lspkind = true, -- lsp enhancements + lspsignature = true, -- lsp enhancements + neoformat = true, -- universal formatter + neoscroll = true, -- smooth scroll + telescope_media = true, -- see media files in telescope picker + truezen = true, -- no distraction mode for nvim + vim_fugitive = true, -- git in nvim + vim_matchup = true, -- % magic, match it but improved } -- make sure you dont use same keys twice M.mappings = { - -- plugin specific - truezen = { - ataraxisMode = "zz", - minimalisticmode = "zm", - focusmode = "zf", - }, - comment_nvim = { - comment_toggle = "/", - }, - nvimtree = { - treetoggle = "", -- file manager - }, - 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", - buffers = "fb", - help_tags = "fh", - oldfiles = "fo", - themes = "th", - }, - telescope_media = { - media_files = "fp", - }, - chadsheet = { - default_keys = "dk", - user_keys = "uk", - }, - bufferline = { - new_buffer = "", - newtab = "b", - close = "", -- close a buffer with custom func in utils.lua - cycleNext = "", -- next buffer - cyclePrev = "", -- previous buffer - }, - fugitive = { - Git = "gs", - diffget_2 = "gh", - diffget_3 = "gl", - git_blame = "gb", - }, - terms = { -- below are NvChad mappings, not plugin mappings - esc_termmode = "jk", - esc_hide_termmode = "JK", - pick_term = "W", -- note: this is a telescope extension - new_wind = "w", - new_vert = "v", - new_hori = "h", - }, - -- navigation in insert mode + -- close current focused buffer + close_buffer = "x", + copy_whole_file = "", -- copy all contents of the current buffer + + -- navigation in insert mode, only if enabled in options insert_nav = { - forward = "", backward = "", - top_of_line = "", end_of_line = "", - prev_line = "", + forward = "", next_line = "", + prev_line = "", + top_of_line = "", }, - misc = { - copywhole_file = "", - toggle_linenr = "n", -- show or hide line number - theme_toggle = "x", - update_nvchad = "uu", + + 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 + + -- 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 = "W", + -- below three are for spawning terminals + new_horizontal = "h", + new_vertical = "v", + new_window = "w", + }, + + -- update nvchad from nvchad, chadness 101 + update_nvchad = "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 + plugin = { + bufferline = { + next_buffer = "", -- next buffer + prev_buffer = "", -- previous buffer + }, + chadsheet = { + default_keys = "dk", + user_keys = "uk", + }, + comment = { + toggle = "/", -- trigger comment on a single/selected lines/number prefix + }, + 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 + }, + -- note: this is an edditional mapping to escape, escape key will still work + better_escape = { + esc_insertmode = { "jk" }, -- multiple mappings allowed + }, + nvimtree = { + toggle = "", -- file manager + }, + neoformat = { + format = "fm", + }, + telescope = { + buffers = "fb", + find_files = "ff", + git_commits = "cm", + git_status = "gt", + help_tags = "fh", + live_grep = "fw", + oldfiles = "fo", + themes = "th", + }, + telescope_media = { + media_files = "fp", + }, + truezen = { -- distraction free modes mapping, hide statusline, tabline, line numbers + ataraxis_mode = "zz", -- center + focus_mode = "zf", + minimalistic_mode = "zm", -- as it is + }, + vim_fugitive = { + diff_get_2 = "gh", + diff_get_3 = "gl", + git = "gs", + git_blame = "gb", + }, }, } diff --git a/lua/highlights.lua b/lua/colors/highlights.lua similarity index 79% rename from lua/highlights.lua rename to lua/colors/highlights.lua index 99e0d03..74bd77e 100644 --- a/lua/highlights.lua +++ b/lua/colors/highlights.lua @@ -1,60 +1,55 @@ local cmd = vim.cmd -local global_theme = "themes/" .. vim.g.nvchad_theme -local colors = require(global_theme) +local colors = require("colors").get() -local white = colors.white -local darker_black = colors.darker_black local black = colors.black local black2 = colors.black2 -local one_bg = colors.one_bg -local one_bg2 = colors.one_bg2 +local blue = colors.blue +local darker_black = colors.darker_black +local folder_bg = colors.folder_bg +local green = colors.green local grey = colors.grey local grey_fg = colors.grey_fg -local red = colors.red local line = colors.line -local green = colors.green local nord_blue = colors.nord_blue -local blue = colors.blue -local yellow = colors.yellow -local purple = colors.purple +local one_bg = colors.one_bg +local one_bg2 = colors.one_bg2 local pmenu_bg = colors.pmenu_bg -local folder_bg = colors.folder_bg +local purple = colors.purple +local red = colors.red +local white = colors.white +local yellow = colors.yellow --- for guifg , bg - -local function fg(group, color) - cmd("hi " .. group .. " guifg=" .. color) -end +local ui = require("core.utils").load_config().ui local function bg(group, color) cmd("hi " .. group .. " guibg=" .. color) end +local function fg(group, color) + cmd("hi " .. group .. " guifg=" .. color) +end + local function fg_bg(group, fgcol, bgcol) cmd("hi " .. group .. " guifg=" .. fgcol .. " guibg=" .. bgcol) end --- blankline - -fg("IndentBlanklineChar", line) - --- misc -- -fg("LineNr", grey) - -- Comments -local ui = require("utils").load_config().ui - if ui.italic_comments then - cmd("hi Comment gui=italic guifg=" .. grey_fg) + fg("Comment", grey_fg .. " gui=italic") else fg("Comment", grey_fg) end -fg("NvimInternalError", red) -fg("VertSplit", line) +cmd "hi clear CursorLine" -- disable cusror line +fg("cursorlinenr", white) -- line number + +-- same it bg, so it doesn't appear fg("EndOfBuffer", black) --- fg_bg("Visual",light_grey, colors.lightbg) + +-- For floating windows +fg("FloatBorder", blue) +bg("NormalFloat", one_bg) -- Pmenu bg("Pmenu", one_bg) @@ -62,74 +57,79 @@ bg("PmenuSbar", one_bg2) bg("PmenuSel", pmenu_bg) bg("PmenuThumb", nord_blue) +-- misc +fg("LineNr", grey) + +fg("NvimInternalError", red) + -- inactive statuslines as thin splitlines -cmd("hi! StatusLineNC gui=underline guifg=" .. line) +fg("StatusLineNC", line .. " gui=underline") --- line n.o -cmd "hi clear CursorLine" -fg("cursorlinenr", white) +fg("VertSplit", line) +-- fg_bg("Visual",light_grey, colors.lightbg) --- git signs --- +if ui.transparency then + bg("Normal", "NONE") + bg("Folded", "NONE") + fg("Folded", "NONE") + fg("Comment", grey) +end + +----- plugin related highlights ----- + +-- dashboard -- +fg("DashboardCenter", grey_fg) +fg("DashboardFooter", grey_fg) +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") --- NvimTree -fg("NvimTreeFolderIcon", folder_bg) -fg("NvimTreeFolderName", folder_bg) -fg("NvimTreeGitDirty", red) -fg("NvimTreeOpenedFolderName", blue) -fg("NvimTreeEmptyFolderName", blue) -fg("NvimTreeIndentMarker", one_bg2) -fg("NvimTreeVertSplit", darker_black) -bg("NvimTreeVertSplit", darker_black) -fg("NvimTreeEndOfBuffer", darker_black) - -cmd("hi NvimTreeRootFolder gui=underline guifg=" .. red) -bg("NvimTreeNormal", darker_black) -fg_bg("NvimTreeStatuslineNc", darker_black, darker_black) -fg_bg("NvimTreeWindowPicker", red, black2) - --- telescope -fg("TelescopeBorder", line) -fg("TelescopePromptBorder", line) -fg("TelescopeResultsBorder", line) -fg("TelescopePreviewBorder", grey) - --- LspDiagnostics --- +-- indent blankline plugin -- +fg("IndentBlanklineChar", line) +-- LspDiagnostics -- -- error / warnings fg("LspDiagnosticsSignError", red) -fg("LspDiagnosticsVirtualTextError", red) fg("LspDiagnosticsSignWarning", yellow) +fg("LspDiagnosticsVirtualTextError", red) fg("LspDiagnosticsVirtualTextWarning", yellow) -- info fg("LspDiagnosticsSignInformation", green) fg("LspDiagnosticsVirtualTextInformation", green) --- hint +-- hints fg("LspDiagnosticsSignHint", purple) fg("LspDiagnosticsVirtualTextHint", purple) --- dashboard - -fg("DashboardHeader", grey_fg) -fg("DashboardCenter", grey_fg) -fg("DashboardShortcut", grey_fg) -fg("DashboardFooter", grey_fg) - -if require("utils").load_config().ui.transparency then - bg("Normal", "NONE") - bg("Folded", "NONE") - fg("Folded", "NONE") +-- NvimTree -- +fg("NvimTreeEmptyFolderName", blue) +fg("NvimTreeEndOfBuffer", darker_black) +fg("NvimTreeFolderIcon", folder_bg) +fg("NvimTreeFolderName", folder_bg) +fg("NvimTreeGitDirty", red) +fg("NvimTreeIndentMarker", one_bg2) +bg("NvimTreeNormal", darker_black) +fg("NvimTreeOpenedFolderName", blue) +fg("NvimTreeRootFolder", red .. " gui=underline") -- enable underline for root folder in nvim tree +fg_bg("NvimTreeStatuslineNc", darker_black, darker_black) +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) - bg("NvimTreeStatusLineNC", "NONE") - fg("Comment", grey) end --- For floating windows -bg("NormalFloat", one_bg) -fg("FloatBorder", blue) +-- telescope -- +fg("TelescopeBorder", line) +fg("TelescopePreviewBorder", grey) +fg("TelescopePromptBorder", line) +fg("TelescopeResultsBorder", line) diff --git a/lua/colors/init.lua b/lua/colors/init.lua new file mode 100644 index 0000000..a0d38d4 --- /dev/null +++ b/lua/colors/init.lua @@ -0,0 +1,36 @@ +local M = {} + +-- if theme given, load given theme if given, otherwise nvchad_theme +M.init = function(theme) + if not theme then + theme = require("core.utils").load_config().ui.theme + end + + -- set the global theme, used at various places like theme switcher, highlights + vim.g.nvchad_theme = theme + + local present, base16 = pcall(require, "base16") + + if present then + -- first load the base16 theme + base16(base16.themes(theme), true) + + -- unload to force reload + package.loaded["colors.highlights" or false] = nil + -- then load the highlights + require "colors.highlights" + else + return false + end +end + +-- returns a table of colors for givem or current theme +M.get = function(theme) + if not theme then + theme = vim.g.nvchad_theme + end + + return require("colors.themes." .. theme) +end + +return M diff --git a/lua/themes/chadracula.lua b/lua/colors/themes/chadracula.lua similarity index 100% rename from lua/themes/chadracula.lua rename to lua/colors/themes/chadracula.lua diff --git a/lua/themes/everforest.lua b/lua/colors/themes/everforest.lua similarity index 100% rename from lua/themes/everforest.lua rename to lua/colors/themes/everforest.lua diff --git a/lua/themes/gruvchad.lua b/lua/colors/themes/gruvchad.lua similarity index 100% rename from lua/themes/gruvchad.lua rename to lua/colors/themes/gruvchad.lua diff --git a/lua/themes/javacafe.lua b/lua/colors/themes/javacafe.lua similarity index 100% rename from lua/themes/javacafe.lua rename to lua/colors/themes/javacafe.lua diff --git a/lua/themes/mountain.lua b/lua/colors/themes/mountain.lua similarity index 100% rename from lua/themes/mountain.lua rename to lua/colors/themes/mountain.lua diff --git a/lua/themes/norchad.lua b/lua/colors/themes/norchad.lua similarity index 100% rename from lua/themes/norchad.lua rename to lua/colors/themes/norchad.lua diff --git a/lua/themes/one-light.lua b/lua/colors/themes/one-light.lua similarity index 100% rename from lua/themes/one-light.lua rename to lua/colors/themes/one-light.lua diff --git a/lua/themes/onedark.lua b/lua/colors/themes/onedark.lua similarity index 100% rename from lua/themes/onedark.lua rename to lua/colors/themes/onedark.lua diff --git a/lua/themes/tokyonight.lua b/lua/colors/themes/tokyonight.lua similarity index 100% rename from lua/themes/tokyonight.lua rename to lua/colors/themes/tokyonight.lua diff --git a/lua/themes/tomorrow-night.lua b/lua/colors/themes/tomorrow-night.lua similarity index 100% rename from lua/themes/tomorrow-night.lua rename to lua/colors/themes/tomorrow-night.lua diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua new file mode 100644 index 0000000..56306b8 --- /dev/null +++ b/lua/core/autocmds.lua @@ -0,0 +1,17 @@ +-- uncomment this if you want to open nvim with a dir +-- vim.cmd [[ autocmd BufEnter * if &buftype != "terminal" | lcd %:p:h | endif ]] + +-- Use relative & absolute line numbers in 'n' & 'i' modes respectively +-- vim.cmd[[ au InsertEnter * set norelativenumber ]] +-- vim.cmd[[ au InsertLeave * set relativenumber ]] + +-- Don't show any numbers inside terminals +vim.cmd [[ au TermOpen term://* setlocal nonumber norelativenumber | setfiletype terminal ]] + +-- Don't show status line on certain windows +vim.cmd [[ autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter,TermEnter * lua require("core.utils").hide_statusline() ]] + +-- Open a file from its last left off position +-- vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]] +-- File extension specific tabbing +-- vim.cmd [[ autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 ]] diff --git a/lua/core/init.lua b/lua/core/init.lua new file mode 100644 index 0000000..999576f --- /dev/null +++ b/lua/core/init.lua @@ -0,0 +1,15 @@ +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 + +-- set all the non plugin mappings +require("core.mappings").misc() diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua new file mode 100644 index 0000000..340fd94 --- /dev/null +++ b/lua/core/mappings.lua @@ -0,0 +1,202 @@ +local config = require("core.utils").load_config() +local maps = config.mappings +local plugin_maps = maps.plugin +local cmd = vim.cmd + +local function map(mode, lhs, rhs, opts) + local options = { noremap = true, silent = true } + if opts then + options = vim.tbl_extend("force", options, opts) + end + + -- if list of keys provided then run set for all of them + if type(lhs) == "table" then + for _, key in ipairs(lhs) do + vim.api.nvim_set_keymap(mode, key, rhs, options) + end + else + vim.api.nvim_set_keymap(mode, lhs, rhs, options) + end +end + +local opt, M = {}, {} + +-- these mappings will only be called during initialization +M.misc = function() + local function non_config_mappings() + -- dont copy any deleted text , this is disabled by default so uncomment the below mappings if you want them + -- map("n", "dd", [=[ "_dd ]=], opt) + -- map("v", "dd", [=[ "_dd ]=], opt) + -- map("v", "x", [=[ "_x ]=], opt) + -- todo: this should be configurable via chadrc + + -- Don't copy the replaced text after pasting in visual mode + map("v", "p", '"_dP', opt) + + -- Allow moving the cursor through wrapped lines with j, k, and + -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ + -- empty mode is same as using :map + map("", "j", 'v:count ? "j" : "gj"', { expr = true }) + map("", "k", 'v:count ? "k" : "gk"', { expr = true }) + map("", "", 'v:count ? "j" : "gj"', { expr = true }) + map("", "", 'v:count ? "k" : "gk"', { expr = true }) + + -- use ESC to turn off search highlighting + map("n", "", ":noh ", opt) + end + + local function optional_mappings() + -- navigation within insert mode + if config.options.insert_nav then + local inav = maps.insert_nav + + map("i", inav.backward, "", opt) + map("i", inav.end_of_line, "", opt) + map("i", inav.forward, "", opt) + map("i", inav.next_line, "", opt) + map("i", inav.prev_line, "", opt) + map("i", inav.top_of_line, "^i", opt) + end + + -- check the theme toggler + if config.ui.theme_toggler then + map( + "n", + maps.theme_toggler, + ":lua require('nvchad').toggle_theme(require('core.utils').load_config().ui.theme_toggler.fav_themes) ", + opt + ) + end + end + + local function required_mappings() + map("n", maps.close_buffer, ":lua require('core.utils').close_buffer() ", opt) -- close buffer + map("n", maps.copy_whole_file, ":%y+ ", opt) -- copy whole file content + map("n", maps.new_buffer, ":enew ", opt) -- new buffer + map("n", maps.new_tab, ":tabnew ", opt) -- new tabs + map("n", maps.line_number_toggle, ":set nu! ", opt) -- toggle numbers + map("n", maps.save_file, ":w ", opt) -- ctrl + s to save file + + -- terminal mappings -- + local term_maps = maps.terminal + -- get out of terminal mode + map("t", term_maps.esc_termmode, "", opt) + -- hide a term from within terminal mode + map("t", term_maps.esc_hide_termmode, " :lua require('core.utils').close_buffer() ", opt) + -- pick a hidden term + map("n", term_maps.pick_term, ":Telescope terms ", opt) + -- Open terminals + -- TODO this opens on top of an existing vert/hori term, fixme + map( + "n", + term_maps.new_horizontal, + ":execute 15 .. 'new +terminal' | let b:term_type = 'hori' | startinsert ", + opt + ) + map("n", term_maps.new_vertical, ":execute 'vnew +terminal' | let b:term_type = 'vert' | startinsert ", opt) + map("n", term_maps.new_window, ":execute 'terminal' | let b:term_type = 'wind' | startinsert ", opt) + -- terminal mappings end -- + + -- Add Packer commands because we are not loading it at startup + cmd "silent! command PackerCompile lua require 'plugins' require('packer').compile()" + cmd "silent! command PackerInstall lua require 'plugins' require('packer').install()" + cmd "silent! command PackerStatus lua require 'plugins' require('packer').status()" + cmd "silent! command PackerSync lua require 'plugins' require('packer').sync()" + cmd "silent! command PackerUpdate lua require 'plugins' require('packer').update()" + + -- add NvChadUpdate command and mapping + cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" + map("n", maps.update_nvchad, ":NvChadUpdate ", opt) + end + + non_config_mappings() + optional_mappings() + required_mappings() +end + +-- below are all plugin related mappinsg + +M.better_escape = function() + vim.g.better_escape_shortcut = plugin_maps.better_escape.esc_insertmode or { "" } +end + +M.bufferline = function() + local m = plugin_maps.bufferline + + map("n", m.next_buffer, ":BufferLineCycleNext ", opt) + map("n", m.prev_buffer, ":BufferLineCyclePrev ", opt) +end + +M.chadsheet = function() + local m = plugin_maps.chadsheet + + map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope() ", opt) + map( + "n", + m.user_keys, + ":lua require('cheatsheet').show_cheatsheet_telescope{bundled_cheatsheets = false, bundled_plugin_cheatsheets = false } ", + opt + ) +end + +M.comment = function() + local m = plugin_maps.comment.toggle + map("n", m, ":CommentToggle ", opt) + map("v", m, ":CommentToggle ", opt) +end + +M.dashboard = function() + local m = plugin_maps.dashboard + + map("n", m.bookmarks, ":DashboardJumpMarks ", opt) + map("n", m.new_file, ":DashboardNewFile ", opt) + map("n", m.open, ":Dashboard ", opt) + map("n", m.session_load, ":SessionLoad ", opt) + map("n", m.session_save, ":SessionSave ", opt) +end + +M.nvimtree = function() + map("n", plugin_maps.nvimtree.toggle, ":NvimTreeToggle ", opt) +end + +M.neoformat = function() + map("n", plugin_maps.neoformat.format, ":Neoformat ", opt) +end + +M.telescope = function() + local m = plugin_maps.telescope + + map("n", m.buffers, ":Telescope buffers ", opt) + map("n", m.find_files, ":Telescope find_files ", opt) + map("n", m.git_commits, ":Telescope git_commits ", opt) + map("n", m.git_status, ":Telescope git_status ", opt) + map("n", m.help_tags, ":Telescope help_tags ", opt) + map("n", m.live_grep, ":Telescope live_grep ", opt) + map("n", m.oldfiles, ":Telescope oldfiles ", opt) + map("n", m.themes, ":Telescope themes ", opt) +end + +M.telescope_media = function() + local m = plugin_maps.telescope_media + + map("n", m.media_files, ":Telescope media_files ", opt) +end + +M.truezen = function() + local m = plugin_maps.truezen + + map("n", m.ataraxis_mode, ":TZAtaraxis ", opt) + map("n", m.focus_mode, ":TZFocus ", opt) + map("n", m.minimalistic_mode, ":TZMinimalist ", opt) +end + +M.vim_fugitive = function() + local m = plugin_maps.vim_fugitive + + map("n", m.git, ":Git ", opt) + map("n", m.git_blame, ":Git blame ", opt) + map("n", m.diff_get_2, ":diffget //2 ", opt) + map("n", m.diff_get_3, ":diffget //3 ", opt) +end + +return M diff --git a/lua/options.lua b/lua/core/options.lua similarity index 56% rename from lua/options.lua rename to lua/core/options.lua index 2e603c4..5882103 100644 --- a/lua/options.lua +++ b/lua/core/options.lua @@ -4,87 +4,71 @@ local g = vim.g -- export user config as a global varibale g.nvchad_user_config = "chadrc" -local options = require("utils").load_config().options +local options = require("core.utils").load_config().options -opt.completeopt = { "menuone", "noselect" } -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 = options.mouse -opt.signcolumn = "yes" -opt.cmdheight = options.cmdheight -opt.updatetime = options.updatetime -- update interval for gitsigns -opt.timeoutlen = options.timeoutlen opt.clipboard = options.clipboard +opt.cmdheight = options.cmdheight +opt.completeopt = { "menuone", "noselect" } +opt.cul = true -- cursor line --- disable nvim intro -opt.shortmess:append "sI" +-- Indentline +opt.expandtab = options.expandtab +opt.shiftwidth = options.shiftwidth +opt.smartindent = options.smartindent -- disable tilde on end of buffer: https://github.com/ neovim/neovim/pull/8546#issuecomment-643643758 opt.fillchars = { eob = " " } +opt.hidden = options.hidden +opt.ignorecase = options.ignorecase +opt.mouse = options.mouse + -- Numbers opt.number = options.number opt.numberwidth = options.numberwidth opt.relativenumber = options.relativenumber +opt.ruler = options.ruler --- Indenline -opt.expandtab = options.expandtab -opt.shiftwidth = options.shiftwidth -opt.smartindent = options.smartindent +-- disable nvim intro +opt.shortmess:append "sI" +opt.signcolumn = "yes" +opt.splitbelow = true +opt.splitright = true +opt.termguicolors = true +opt.timeoutlen = options.timeoutlen +opt.undofile = options.permanent_undo + +-- interval for writing swap file to disk, also used by gitsigns +opt.updatetime = options.updatetime -- 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 = options.mapleader -g.auto_save = options.autosave --- disable builtin vim plugins +-- disable some builtin vim plugins local disabled_built_ins = { + "2html_plugin", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", "netrw", "netrwPlugin", "netrwSettings", "netrwFileHandlers", - "gzip", - "zip", - "zipPlugin", + "matchit", "tar", "tarPlugin", - "getscript", - "getscriptPlugin", - "vimball", - "vimballPlugin", - "2html_plugin", - "logipat", "rrhelper", "spellfile_plugin", - "matchit", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", } for _, plugin in pairs(disabled_built_ins) do g["loaded_" .. plugin] = 1 end - --- uncomment this if you want to open nvim with a dir --- vim.cmd [[ autocmd BufEnter * if &buftype != "terminal" | lcd %:p:h | endif ]] - --- Use relative & absolute line numbers in 'n' & 'i' modes respectively --- vim.cmd[[ au InsertEnter * set norelativenumber ]] --- vim.cmd[[ au InsertLeave * set relativenumber ]] - --- Don't show any numbers inside terminals -vim.cmd [[ au TermOpen term://* setlocal nonumber norelativenumber | setfiletype terminal ]] - --- Don't show status line on certain windows -vim.cmd [[ autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter,TermEnter * lua require("utils").hide_statusline() ]] - --- Open a file from its last left off position --- vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]] --- File extension specific tabbing --- vim.cmd [[ autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 ]] diff --git a/lua/core/utils.lua b/lua/core/utils.lua new file mode 100644 index 0000000..cafd1e3 --- /dev/null +++ b/lua/core/utils.lua @@ -0,0 +1,265 @@ +local M = {} + +M.close_buffer = function(bufexpr, force) + -- This is a modification of a NeoVim plugin from + -- Author: ojroques - Olivier Roques + -- Src: https://github.com/ojroques/nvim-bufdel + -- (Author has okayed copy-paste) + + -- Options + local opts = { + next = "cycle", -- how to retrieve the next buffer + quit = false, -- exit when last buffer is deleted + --TODO make this a chadrc flag/option + } + + -- ---------------- + -- Helper functions + -- ---------------- + + -- Switch to buffer 'buf' on each window from list 'windows' + local function switch_buffer(windows, buf) + local cur_win = vim.fn.winnr() + for _, winid in ipairs(windows) do + vim.cmd(string.format("%d wincmd w", vim.fn.win_id2win(winid))) + vim.cmd(string.format("buffer %d", buf)) + end + vim.cmd(string.format("%d wincmd w", cur_win)) -- return to original window + end + + -- Select the first buffer with a number greater than given buffer + local function get_next_buf(buf) + local next = vim.fn.bufnr "#" + if opts.next == "alternate" and vim.fn.buflisted(next) == 1 then + return next + end + for i = 0, vim.fn.bufnr "$" - 1 do + next = (buf + i) % vim.fn.bufnr "$" + 1 -- will loop back to 1 + if vim.fn.buflisted(next) == 1 then + return next + end + end + end + + -- ---------------- + -- End helper functions + -- ---------------- + + local buf = vim.fn.bufnr() + if vim.fn.buflisted(buf) == 0 then -- exit if buffer number is invalid + vim.cmd "close" + return + end + + if #vim.fn.getbufinfo { buflisted = 1 } < 2 then + if opts.quit then + -- exit when there is only one buffer left + if force then + vim.cmd "qall!" + else + vim.cmd "confirm qall" + end + return + end + + local chad_term, type = pcall(function() + return vim.api.nvim_buf_get_var(buf, "term_type") + end) + + if chad_term then + -- Must be a window type + vim.cmd(string.format("setlocal nobl", buf)) + vim.cmd "enew" + return + end + -- don't exit and create a new empty buffer + vim.cmd "enew" + vim.cmd "bp" + end + + local next_buf = get_next_buf(buf) + local windows = vim.fn.getbufinfo(buf)[1].windows + + -- force deletion of terminal buffers to avoid the prompt + if force or vim.fn.getbufvar(buf, "&buftype") == "terminal" then + local chad_term, type = pcall(function() + return vim.api.nvim_buf_get_var(buf, "term_type") + end) + + -- TODO this scope is error prone, make resilient + if chad_term then + if type == "wind" then + -- hide from bufferline + vim.cmd(string.format("%d bufdo setlocal nobl", buf)) + -- swtich to another buff + -- TODO switch to next bufffer, this works too + vim.cmd "BufferLineCycleNext" + else + local cur_win = vim.fn.winnr() + -- we can close this window + vim.cmd(string.format("%d wincmd c", cur_win)) + return + end + else + switch_buffer(windows, next_buf) + vim.cmd(string.format("bd! %d", buf)) + end + else + switch_buffer(windows, next_buf) + vim.cmd(string.format("silent! confirm bd %d", buf)) + end + -- revert buffer switches if user has canceled deletion + if vim.fn.buflisted(buf) == 1 then + switch_buffer(windows, buf) + end +end + +-- hide statusline +-- tables fetched from load_config function +M.hide_statusline = function() + local hidden = require("core.utils").load_config().ui.plugin.statusline.hidden + local shown = require("core.utils").load_config().ui.plugin.statusline.shown + local api = vim.api + local buftype = api.nvim_buf_get_option("%", "ft") + + -- shown table from config has the highest priority + if vim.tbl_contains(shown, buftype) then + api.nvim_set_option("laststatus", 2) + return + end + + if vim.tbl_contains(hidden, buftype) then + api.nvim_set_option("laststatus", 0) + return + else + api.nvim_set_option("laststatus", 2) + end +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, { ['plugin']['truezen']['mappings'] }) +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 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]] + for _, node in ipairs(nodes_to_replace) do + -- replace the _node in base_fn to actual given node value + local fn = base_fn:gsub("_node", node) + -- if the node if found, it is replaced, otherwise table 1 is returned + table1 = loadstring(fn)()(table1, table2) + 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 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 + + -- these are the table value which will be always prioritiezed to take user config value + local to_replace = { + "['mappings']['plugin']['esc_insertmode']", + "['mappings']['terminal']['esc_termmode']", + "['mappings']['terminal']['esc_hide_termmode']", + } + + local default_config = "default_config" + local config_name = vim.g.nvchad_user_config or "chadrc" + local config_file = vim.fn.stdpath "config" .. "/lua/" .. config_name .. ".lua" + + -- unload the modules if force reload + if reload then + package.loaded[default_config or false] = nil + package.loaded[config_name or false] = nil + 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.empty(vim.fn.glob(config_file)) < 1 then + local present, config = pcall(require, config_name) + 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: " .. config_name .. " 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 +end + +return M diff --git a/lua/default_config.lua b/lua/default_config.lua index ed79ab1..c744f8f 100644 --- a/lua/default_config.lua +++ b/lua/default_config.lua @@ -3,162 +3,190 @@ local M = {} M.ui = { + italic_comments = false, + + -- theme to be used, to see all available themes, open the theme switcher by + th theme = "onedark", - -- theme toggle - theme_toggler = false, - fav_themes = { - "onedark", - "gruvchad", + -- theme toggler, toggle between two themes, see theme_toggleer mappings + theme_toggler = { + enabled = false, + fav_themes = { + "onedark", + "gruvchad", + }, }, - italic_comments = false, -- 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, - -- 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 = { - "NvimTree", - "terminal", + -- plugin related ui options + 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 = { + "NvimTree", + "terminal", + }, + shown = {}, + -- default, round , slant , block , arrow + style = "default", }, - shown = {}, - style = "default", -- default, round , slant , block , arrow }, } M.options = { - permanent_undo = true, - ruler = false, + clipboard = "unnamedplus", + cmdheight = 1, + expandtab = true, hidden = true, ignorecase = true, + insert_nav = true, -- navigation in insertmode + mapleader = " ", mouse = "a", - cmdheight = 1, - updatetime = 250, - timeoutlen = 400, - clipboard = "unnamedplus", number = true, -- relative numbers in normal mode tool at the bottom of options.lua - relativenumber = false, numberwidth = 2, - expandtab = true, + permanent_undo = true, shiftwidth = 2, smartindent = true, - mapleader = " ", - autosave = false, - enable_insertNav = true, -- navigation in insertmode + 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 + 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 = { - -- UI - nvim_bufferline = true, - galaxyline = true, - nvim_colorizer = true, - dashboard_nvim = true, - blankline = true, - truezen_nvim = true, - better_esc = true, - -- lsp stuff - lspkind = true, - lspsignature = true, - -- git stuff - gitsigns = true, - vim_fugitive = true, - -- misc - neoformat = true, - vim_matchup = true, - autosave_nvim = true, - nvim_comment = true, - neoscroll_nvim = true, - telescope_media = true, - cheatsheet = true, + autosave = true, -- 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 = true, -- a nice looking dashboard + esc_insertmode = true, -- escape from insert mode using custom keys + galaxyline = true, -- statusline + gitsigns = true, -- gitsigns in statusline + lspkind = true, -- lsp enhancements + lspsignature = true, -- lsp enhancements + neoformat = true, -- universal formatter + neoscroll = true, -- smooth scroll + telescope_media = true, -- see media files in telescope picker + truezen = true, -- no distraction mode for nvim + vim_fugitive = true, -- git in nvim + vim_matchup = true, -- % magic, match it but improved } -- make sure you dont use same keys twice M.mappings = { - -- plugin specific - truezen = { - ataraxisMode = "zz", - minimalisticmode = "zm", - focusmode = "zf", - }, - comment_nvim = { - comment_toggle = "/", - }, - nvimtree = { - treetoggle = "", -- file manager - }, - 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", - buffers = "fb", - help_tags = "fh", - oldfiles = "fo", - themes = "th", - }, - telescope_media = { - media_files = "fp", - }, - chadsheet = { - default_keys = "dk", - user_keys = "uk", - }, - bufferline = { - new_buffer = "", - newtab = "b", - close = "", -- close a buffer with custom func in utils.lua - cycleNext = "", -- next buffer - cyclePrev = "", -- previous buffer - }, - fugitive = { - Git = "gs", - diffget_2 = "gh", - diffget_3 = "gl", - git_blame = "gb", - }, - terms = { -- below are NvChad mappings, not plugin mappings - esc_termmode = "jk", - esc_hide_termmode = "JK", - pick_term = "W", -- note: this is a telescope extension - new_wind = "w", - new_vert = "v", - new_hori = "h", - }, -- navigation in insert mode + -- close current focused buffer + close_buffer = "x", + copy_whole_file = "", -- copy all contents of the current buffer + + -- navigation in insert mode, only if enabled in options insert_nav = { - forward = "", backward = "", - top_of_line = "", end_of_line = "", - prev_line = "", + forward = "", next_line = "", + prev_line = "", + top_of_line = "", }, - -- non plugin - misc = { - esc_Termmode = "jk", -- get out of terminal mode - close_buffer = "x", -- close current focused buffer - copywhole_file = "", - toggle_linenr = "n", -- show or hide line number - theme_toggle = "tt", - update_nvchad = "uu", + + 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 + + -- 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 = "W", + -- below three are for spawning terminals + new_horizontal = "h", + new_vertical = "v", + new_window = "w", + }, + + -- update nvchad from nvchad, chadness 101 + update_nvchad = "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 + plugin = { + bufferline = { + next_buffer = "", -- next buffer + prev_buffer = "", -- previous buffer + }, + chadsheet = { + default_keys = "dk", + user_keys = "uk", + }, + comment = { + toggle = "/", -- trigger comment on a single/selected lines/number prefix + }, + 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 + }, + -- note: this is an edditional mapping to escape, escape key will still work + better_escape = { + esc_insertmode = { "jk" }, -- multiple mappings allowed + }, + nvimtree = { + toggle = "", -- file manager + }, + neoformat = { + format = "fm", + }, + telescope = { + buffers = "fb", + find_files = "ff", + git_commits = "cm", + git_status = "gt", + help_tags = "fh", + live_grep = "fw", + oldfiles = "fo", + themes = "th", + }, + telescope_media = { + media_files = "fp", + }, + truezen = { -- distraction free modes mapping, hide statusline, tabline, line numbers + ataraxis_mode = "zz", -- center + focus_mode = "zf", + minimalistic_mode = "zm", -- as it is + }, + vim_fugitive = { + diff_get_2 = "gh", + diff_get_3 = "gl", + git = "gs", + git_blame = "gb", + }, }, } diff --git a/lua/mappings.lua b/lua/mappings.lua deleted file mode 100644 index 9be5fde..0000000 --- a/lua/mappings.lua +++ /dev/null @@ -1,188 +0,0 @@ -local user_map = require("utils").load_config().mappings -local miscMap = user_map.misc - -local cmd = vim.cmd - -local function map(mode, lhs, rhs, opts) - local options = { noremap = true, silent = true } - if opts then - options = vim.tbl_extend("force", options, opts) - end - vim.api.nvim_set_keymap(mode, lhs, rhs, options) -end - -local M = {} -local opt = {} - --- these mappings will only be called during initialization -M.misc = function() - -- dont copy any deleted text , this is disabled by default so uncomment the below mappings if you want them - -- map("n", "dd", [=[ "_dd ]=], opt) - -- map("v", "dd", [=[ "_dd ]=], opt) - -- map("v", "x", [=[ "_x ]=], opt) - -- todo: this should be configurable via chadrc - - -- Don't copy the replaced text after pasting in visual mode - map("v", "p", '"_dP', opt) - - -- Allow moving the cursor through wrapped lines with j, k, and - -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ - -- empty mode is same as using :map - map("", "j", 'v:count ? "j" : "gj"', { expr = true }) - map("", "k", 'v:count ? "k" : "gk"', { expr = true }) - map("", "", 'v:count ? "j" : "gj"', { expr = true }) - map("", "", 'v:count ? "k" : "gk"', { expr = true }) - - -- copy whole file content - map("n", miscMap.copywhole_file, ":%y+", opt) - - -- toggle numbers - map("n", miscMap.toggle_linenr, ":set nu!", opt) - - -- terminals - local function terms() - local m = user_map.terms - - -- get out of terminal mode - map("t", m.esc_termmode, "", opt) - -- hide a term from within terminal mode - map("t", m.esc_hide_termmode, " :lua require('utils').close_buffer() ", opt) - -- pick a hidden term - map("n", m.pick_term, ":Telescope terms ", opt) - - -- Open terminals - -- TODO this opens on top of an existing vert/hori term, fixme - map("n", m.new_wind, ":execute 'terminal' | let b:term_type = 'wind' | startinsert ", opt) - map("n", m.new_vert, ":execute 'vnew +terminal' | let b:term_type = 'vert' | startinsert ", opt) - map("n", m.new_hori, ":execute 15 .. 'new +terminal' | let b:term_type = 'hori' | startinsert ", opt) - end - terms() - - -- ctrl + s to save file - map("n", "", ":w ", opt) - - -- use ESC to turn off search highlighting - map("n", "", ":noh", opt) - - -- navigation within insert mode - local check_insertNav = require("utils").load_config().options.enable_insertNav - - if check_insertNav == true then - local m = user_map.insert_nav - - map("i", m.forward, "", opt) - map("i", m.backward, "", opt) - map("i", m.top_of_line, "^i", opt) - map("i", m.end_of_line, "", opt) - map("i", m.next_line, "", opt) - map("i", m.prev_line, "", opt) - end - - -- check the theme toggler - local theme_toggler = require("utils").load_config().ui.theme_toggler - if theme_toggler == true then - local m = user_map.misc.theme_toggle - - map("n", m, ":lua require('utils').toggle_theme(require('utils').load_config().ui.fav_themes)", opt) - end - - -- Packer commands till because we are not loading it at startup - 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()" - - -- add NvChadUpdate command and mapping - cmd "silent! command! NvChadUpdate lua require('utils').update_nvchad()" - map("n", user_map.misc.update_nvchad, ":NvChadUpdate", 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, ":lua require('utils').close_buffer() ", opt) -- close buffer - - -- move between tabs - - map("n", m.cycleNext, ":BufferLineCycleNext", opt) - map("n", m.cyclePrev, ":BufferLineCyclePrev", opt) -end - -M.chadsheet = function() - local m = user_map.chadsheet - - map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope()", opt) - map( - "n", - m.user_keys, - ":lua require('cheatsheet').show_cheatsheet_telescope{bundled_cheatsheets = false, bundled_plugin_cheatsheets = false }", - opt - ) -end - -M.comment_nvim = function() - local m = user_map.comment_nvim.comment_toggle - map("n", m, ":CommentToggle", opt) - map("v", m, ":CommentToggle", opt) -end - -M.dashboard = function() - local m = user_map.dashboard - - 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 - -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 - -M.nvimtree = function() - local m = user_map.nvimtree.treetoggle - - map("n", m, ":NvimTreeToggle", opt) -end - -M.neoformat = function() - local m = user_map.neoformat.format - map("n", m, ":Neoformat", opt) -end - -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 - -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.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.telescope_media = function() - local m = user_map.telescope_media - map("n", m.media_files, ":Telescope media_files ", opt) -end - -return M diff --git a/lua/plugins/chadsheet.lua b/lua/plugins/chadsheet.lua deleted file mode 100644 index 21862c1..0000000 --- a/lua/plugins/chadsheet.lua +++ /dev/null @@ -1,25 +0,0 @@ -local present, chadsheet = pcall(require, "cheatsheet") - -if not present then - return -end - -local mappings = require("utils").load_config().mappings - --- add user mappings to the cheetsheet -for section, data in pairs(mappings) do - for description, keymap in pairs(data) do - chadsheet.add_cheat(description, keymap, section) - end -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/autopairs.lua b/lua/plugins/configs/autopairs.lua similarity index 100% rename from lua/plugins/autopairs.lua rename to lua/plugins/configs/autopairs.lua index 333a852..921307a 100644 --- a/lua/plugins/autopairs.lua +++ b/lua/plugins/configs/autopairs.lua @@ -7,6 +7,6 @@ end autopairs.setup() autopairs_completion.setup { - map_cr = true, map_complete = true, -- insert () func completion + map_cr = true, } diff --git a/lua/plugins/autosave.lua b/lua/plugins/configs/autosave.lua similarity index 85% rename from lua/plugins/autosave.lua rename to lua/plugins/configs/autosave.lua index 4041401..2f41ff7 100644 --- a/lua/plugins/autosave.lua +++ b/lua/plugins/configs/autosave.lua @@ -5,7 +5,7 @@ if not present then end autosave.setup { - enabled = vim.g.auto_save, -- takes boolean value from init.lua + enabled = vim.g.auto_save or false, -- takes boolean value from init.lua execution_message = "autosaved at : " .. vim.fn.strftime "%H:%M:%S", events = { "InsertLeave", "TextChanged" }, conditions = { @@ -13,7 +13,7 @@ autosave.setup { filetype_is_not = {}, modifiable = true, }, - write_all_buffers = false, - on_off_commands = true, clean_command_line_interval = 2500, + on_off_commands = true, + write_all_buffers = false, } diff --git a/lua/plugins/bufferline.lua b/lua/plugins/configs/bufferline.lua similarity index 97% rename from lua/plugins/bufferline.lua rename to lua/plugins/configs/bufferline.lua index 7ac865a..8441bf0 100644 --- a/lua/plugins/bufferline.lua +++ b/lua/plugins/configs/bufferline.lua @@ -1,5 +1,4 @@ -local global_theme = "themes/" .. vim.g.nvchad_theme -local colors = require(global_theme) +local colors = require("colors").get() local present, bufferline = pcall(require, "bufferline") if not present then @@ -43,24 +42,71 @@ bufferline.setup { end, }, highlights = { - fill = { - guifg = colors.grey_fg, - guibg = colors.black2, - }, background = { guifg = colors.grey_fg, guibg = colors.black2, }, + -- buffers - buffer_visible = { - guifg = colors.light_grey, - guibg = colors.black2, - }, buffer_selected = { guifg = colors.white, guibg = colors.black, gui = "bold", }, + buffer_visible = { + guifg = colors.light_grey, + guibg = colors.black2, + }, + + -- close buttons + close_button = { + guifg = colors.light_grey, + guibg = colors.black2, + }, + close_button_visible = { + guifg = colors.light_grey, + guibg = colors.black2, + }, + close_button_selected = { + guifg = colors.red, + guibg = colors.black, + }, + fill = { + guifg = colors.grey_fg, + guibg = colors.black2, + }, + indicator_selected = { + guifg = colors.black, + guibg = colors.black, + }, + + -- modified + modified = { + guifg = colors.red, + guibg = colors.black2, + }, + modified_visible = { + guifg = colors.red, + guibg = colors.black2, + }, + modified_selected = { + guifg = colors.green, + guibg = colors.black, + }, + + -- separators + separator = { + guifg = colors.black2, + guibg = colors.black2, + }, + separator_visible = { + guifg = colors.black2, + guibg = colors.black2, + }, + separator_selected = { + guifg = colors.black2, + guibg = colors.black2, + }, -- tabs tab = { guifg = colors.light_grey, @@ -74,49 +120,5 @@ bufferline.setup { guifg = colors.red, guibg = colors.black, }, - indicator_selected = { - guifg = colors.black, - guibg = colors.black, - }, - -- separators - separator = { - guifg = colors.black2, - guibg = colors.black2, - }, - separator_visible = { - guifg = colors.black2, - guibg = colors.black2, - }, - separator_selected = { - guifg = colors.black2, - guibg = colors.black2, - }, - -- modified - modified = { - guifg = colors.red, - guibg = colors.black2, - }, - modified_visible = { - guifg = colors.red, - guibg = colors.black2, - }, - modified_selected = { - guifg = colors.green, - guibg = colors.black, - }, - -- close buttons - - close_button = { - guifg = colors.light_grey, - guibg = colors.black2, - }, - close_button_visible = { - guifg = colors.light_grey, - guibg = colors.black2, - }, - close_button_selected = { - guifg = colors.red, - guibg = colors.black, - }, }, } diff --git a/lua/plugins/configs/chadsheet.lua b/lua/plugins/configs/chadsheet.lua new file mode 100644 index 0000000..0a6cc02 --- /dev/null +++ b/lua/plugins/configs/chadsheet.lua @@ -0,0 +1,44 @@ +local present, chadsheet = 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_chadsheet(section, keymap, desc) + if section == "plugin" then + for sec, key in pairs(mappings.plugin) do + add_to_chadsheet(sec, key, sec) + end + else + if type(keymap) == "table" then + for sec, key in pairs(keymap) do + if type(sec) == "number" then + add_to_chadsheet(section, key, desc or section) + else + add_to_chadsheet(sec, key, desc or section) + end + end + else + chadsheet.add_cheat(section, keymap, desc or "Misc") + end + end +end + +for section, keymap in pairs(mappings) do + add_to_chadsheet(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/compe.lua b/lua/plugins/configs/compe.lua similarity index 99% rename from lua/plugins/compe.lua rename to lua/plugins/configs/compe.lua index 0fa4d0f..d5c7a3d 100644 --- a/lua/plugins/compe.lua +++ b/lua/plugins/configs/compe.lua @@ -5,21 +5,22 @@ end compe.setup { enabled = true, + autocomplete = true, debug = false, - min_length = 1, - preselect = "enable", - throttle_time = 80, - source_timeout = 200, + documentation = true, incomplete_delay = 400, max_abbr_width = 100, max_kind_width = 100, max_menu_width = 100, - documentation = true, + min_length = 1, + preselect = "enable", + source_timeout = 200, source = { buffer = { kind = "﬘", true }, luasnip = { kind = "﬌", true }, nvim_lsp = true, nvim_lua = true, }, + throttle_time = 80, } diff --git a/lua/plugins/dashboard.lua b/lua/plugins/configs/dashboard.lua similarity index 95% rename from lua/plugins/dashboard.lua rename to lua/plugins/configs/dashboard.lua index 4158cac..63b26a3 100644 --- a/lua/plugins/dashboard.lua +++ b/lua/plugins/configs/dashboard.lua @@ -1,7 +1,7 @@ local g = vim.g local fn = vim.fn -local plugins_count = fn.len(fn.globpath("~/.local/share/nvim/site/pack/packer/start", "*", 0, 1)) +-- local plugins_count = fn.len(fn.globpath("~/.local/share/nvim/site/pack/packer/start", "*", 0, 1)) g.dashboard_disable_at_vimenter = 1 -- dashboard is disabled by default g.dashboard_disable_statusline = 1 diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/configs/gitsigns.lua similarity index 99% rename from lua/plugins/gitsigns.lua rename to lua/plugins/configs/gitsigns.lua index e1fa6c8..a33a46a 100644 --- a/lua/plugins/gitsigns.lua +++ b/lua/plugins/configs/gitsigns.lua @@ -4,18 +4,10 @@ if not present then end 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 = "DiffChange", text = "~", numhl = "GitSignsChangeNr" }, - }, - numhl = false, keymaps = { -- Default keymap options - noremap = true, 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()', @@ -24,9 +16,19 @@ gitsigns.setup { ["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_index = { interval = 100, }, - sign_priority = 5, - status_formatter = nil, -- Use default } diff --git a/lua/plugins/icons.lua b/lua/plugins/configs/icons.lua similarity index 96% rename from lua/plugins/icons.lua rename to lua/plugins/configs/icons.lua index e38e4fd..7fc28a3 100644 --- a/lua/plugins/icons.lua +++ b/lua/plugins/configs/icons.lua @@ -3,16 +3,10 @@ if not present then return end -local global_theme = "themes/" .. vim.g.nvchad_theme -local colors = require(global_theme) +local colors = require("colors").get() icons.setup { override = { - html = { - icon = "", - color = colors.baby_pink, - name = "html", - }, c = { icon = "", color = colors.blue, @@ -23,35 +17,50 @@ icons.setup { color = colors.blue, name = "css", }, - js = { - icon = "", - color = colors.sun, - name = "js", + deb = { + icon = "", + color = colors.cyan, + name = "deb", }, - ts = { - icon = "ﯤ", - color = colors.teal, - name = "ts", + Dockerfile = { + icon = "", + color = colors.cyan, + name = "Dockerfile", }, - kt = { - icon = "󱈙", - color = colors.orange, - name = "kt", + html = { + icon = "", + color = colors.baby_pink, + name = "html", }, - png = { + jpeg = { icon = "", color = colors.dark_purple, - name = "png", + name = "jpeg", }, jpg = { icon = "", color = colors.dark_purple, name = "jpg", }, - jpeg = { - icon = "", - color = colors.dark_purple, - name = "jpeg", + js = { + icon = "", + color = colors.sun, + name = "js", + }, + kt = { + icon = "󱈙", + color = colors.orange, + name = "kt", + }, + lock = { + icon = "", + color = colors.red, + name = "lock", + }, + lua = { + icon = "", + color = colors.blue, + name = "lua", }, mp3 = { icon = "", @@ -68,20 +77,10 @@ icons.setup { color = colors.white, name = "out", }, - Dockerfile = { - icon = "", - color = colors.cyan, - name = "Dockerfile", - }, - rb = { - icon = "", - color = colors.pink, - name = "rb", - }, - vue = { - icon = "﵂", - color = colors.vibrant_green, - name = "vue", + png = { + icon = "", + color = colors.dark_purple, + name = "png", }, py = { icon = "", @@ -93,35 +92,35 @@ icons.setup { color = colors.blue, name = "toml", }, - lock = { - icon = "", - color = colors.red, - name = "lock", + ts = { + icon = "ﯤ", + color = colors.teal, + name = "ts", }, - zip = { - icon = "", - color = colors.sun, - name = "zip", - }, - xz = { - icon = "", - color = colors.sun, - name = "xz", - }, - deb = { - icon = "", - color = colors.cyan, - name = "deb", + rb = { + icon = "", + color = colors.pink, + name = "rb", }, rpm = { icon = "", color = colors.orange, name = "rpm", }, - lua = { - icon = "", - color = colors.blue, - name = "lua", + vue = { + icon = "﵂", + color = colors.vibrant_green, + name = "vue", + }, + xz = { + icon = "", + color = colors.sun, + name = "xz", + }, + zip = { + icon = "", + color = colors.sun, + name = "zip", }, }, } diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/configs/lspconfig.lua similarity index 100% rename from lua/plugins/lspconfig.lua rename to lua/plugins/configs/lspconfig.lua index 4dc4f3f..19e7f99 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -10,13 +10,13 @@ local function on_attach(client, bufnr) local opts = { noremap = true, silent = true } -- lsp Mappings. + vim.api.nvim_buf_set_keymap(bufnr, "n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) vim.api.nvim_buf_set_keymap( bufnr, "n", @@ -24,13 +24,13 @@ local function on_attach(client, bufnr) "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts ) - vim.api.nvim_buf_set_keymap(bufnr, "n", "D", "lua vim.lsp.buf.type_definition()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "D", "lua vim.lsp.buf.type_definition()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) -- Set some keybinds conditional on server capabilities if client.resolved_capabilities.document_formatting then @@ -95,9 +95,9 @@ function lspSymbol(name, icon) end lspSymbol("Error", "") -lspSymbol("Warning", "") lspSymbol("Information", "") lspSymbol("Hint", "") +lspSymbol("Warning", "") vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = { diff --git a/lua/plugins/luasnip.lua b/lua/plugins/configs/luasnip.lua similarity index 100% rename from lua/plugins/luasnip.lua rename to lua/plugins/configs/luasnip.lua index ef67a1c..8b83cb7 100644 --- a/lua/plugins/luasnip.lua +++ b/lua/plugins/configs/luasnip.lua @@ -53,11 +53,11 @@ _G.completions = function() return npairs.check_break_line_char() end -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", { expr = true }) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) +vim.api.nvim_set_keymap("i", "", "v:lua.completions()", { expr = true }) vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) -vim.api.nvim_set_keymap("i", "", "v:lua.completions()", { expr = true }) +vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", { expr = true }) +vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) luasnip.config.set_config { history = true, diff --git a/lua/plugins/nvimtree.lua b/lua/plugins/configs/nvimtree.lua similarity index 99% rename from lua/plugins/nvimtree.lua rename to lua/plugins/configs/nvimtree.lua index cd5c735..fbfb4a8 100644 --- a/lua/plugins/nvimtree.lua +++ b/lua/plugins/configs/nvimtree.lua @@ -8,53 +8,54 @@ local g = vim.g vim.o.termguicolors = true -g.nvim_tree_side = "left" -g.nvim_tree_width = 25 -g.nvim_tree_ignore = { ".git", "node_modules", ".cache" } -g.nvim_tree_gitignore = 1 +g.nvim_tree_add_trailing = 0 -- append a trailing slash to folder names +g.nvim_tree_allow_resize = 1 +g.nvim_tree_auto_close = 0 -- closes tree when it's the last window g.nvim_tree_auto_ignore_ft = { "dashboard" } -- don't open tree on specific fiypes. g.nvim_tree_auto_open = 0 -g.nvim_tree_auto_close = 0 -- closes tree when it's the last window -g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened -g.nvim_tree_follow = 1 -g.nvim_tree_indent_markers = 1 -g.nvim_tree_hide_dotfiles = 1 -g.nvim_tree_git_hl = 1 -g.nvim_tree_highlight_opened_files = 0 -g.nvim_tree_root_folder_modifier = table.concat { ":t:gs?$?/..", string.rep(" ", 1000), "?:gs?^??" } -g.nvim_tree_tab_open = 0 -g.nvim_tree_allow_resize = 1 -g.nvim_tree_add_trailing = 0 -- append a trailing slash to folder names g.nvim_tree_disable_netrw = 1 +g.nvim_tree_follow = 1 +g.nvim_tree_git_hl = 1 +g.nvim_tree_gitignore = 1 +g.nvim_tree_hide_dotfiles = 1 +g.nvim_tree_highlight_opened_files = 0 g.nvim_tree_hijack_netrw = 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_side = "left" +g.nvim_tree_tab_open = 0 g.nvim_tree_update_cwd = 1 +g.nvim_tree_width = 25 g.nvim_tree_show_icons = { - git = 1, folders = 1, - files = 1, -- folder_arrows= 1 + files = 1, + git = 1, } + g.nvim_tree_icons = { default = "", symlink = "", git = { - unstaged = "✗", - staged = "✓", - unmerged = "", - renamed = "➜", - untracked = "★", deleted = "", ignored = "◌", + renamed = "➜", + staged = "✓", + unmerged = "", + unstaged = "✗", + 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 = "", - open = "", empty = "", --  empty_open = "", + open = "", symlink = "", symlink_open = "", }, diff --git a/lua/plugins/others.lua b/lua/plugins/configs/others.lua similarity index 91% rename from lua/plugins/others.lua rename to lua/plugins/configs/others.lua index 3236721..2363557 100644 --- a/lua/plugins/others.lua +++ b/lua/plugins/configs/others.lua @@ -1,5 +1,21 @@ local M = {} +M.better_escape = function() + local config = require("core.utils").load_config() + vim.g.better_escape_interval = config.options.plugin.esc_insertmode_timeout or 300 +end + +M.blankline = function() + vim.g.indentLine_enabled = 1 + vim.g.indent_blankline_char = "▏" + + vim.g.indent_blankline_filetype_exclude = { "help", "terminal", "dashboard", "packer" } + vim.g.indent_blankline_buftype_exclude = { "terminal" } + + vim.g.indent_blankline_show_trailing_blankline_indent = false + vim.g.indent_blankline_show_first_indent_level = false +end + M.colorizer = function() local present, colorizer = pcall(require, "colorizer") if present then @@ -15,11 +31,6 @@ M.comment = function() end end -M.escape = function() - vim.g.better_escape_interval = 300 - vim.g.better_escape_shortcut = { "jk" } -end - M.lspkind = function() local present, lspkind = pcall(require, "lspkind") if present then @@ -33,17 +44,6 @@ M.neoscroll = function() end) end -M.blankline = function() - vim.g.indentLine_enabled = 1 - vim.g.indent_blankline_char = "▏" - - vim.g.indent_blankline_filetype_exclude = { "help", "terminal", "dashboard", "packer" } - vim.g.indent_blankline_buftype_exclude = { "terminal" } - - vim.g.indent_blankline_show_trailing_blankline_indent = false - vim.g.indent_blankline_show_first_indent_level = false -end - M.signature = function() local present, lspsignature = pcall(require, "lsp_signature") if present then diff --git a/lua/plugins/statusline.lua b/lua/plugins/configs/statusline.lua similarity index 97% rename from lua/plugins/statusline.lua rename to lua/plugins/configs/statusline.lua index eb7ea23..06b94ac 100644 --- a/lua/plugins/statusline.lua +++ b/lua/plugins/configs/statusline.lua @@ -1,5 +1,4 @@ -local global_theme = "themes/" .. vim.g.nvchad_theme -local colors = require(global_theme) +local colors = require("colors").get() local present1, gl = pcall(require, "galaxyline") local present2, condition = pcall(require, "galaxyline.condition") @@ -20,6 +19,22 @@ local icon_styles = { position_icon = " ", }, + arrow = { + left = "", + right = "", + main_icon = "  ", + vi_mode_icon = " ", + position_icon = " ", + }, + + block = { + left = " ", + right = " ", + main_icon = "  ", + vi_mode_icon = "  ", + position_icon = "  ", + }, + round = { left = "", right = "", @@ -35,25 +50,9 @@ local icon_styles = { vi_mode_icon = " ", position_icon = " ", }, - - block = { - left = " ", - right = " ", - main_icon = "  ", - vi_mode_icon = "  ", - position_icon = "  ", - }, - - arrow = { - left = "", - right = "", - main_icon = "  ", - vi_mode_icon = " ", - position_icon = " ", - }, } -local user_statusline_style = require("utils").load_config().ui.statusline.style +local user_statusline_style = require("core.utils").load_config().ui.plugin.statusline.style local statusline_style = icon_styles[user_statusline_style] local left_separator = statusline_style.left diff --git a/lua/plugins/telescope.lua b/lua/plugins/configs/telescope.lua similarity index 86% rename from lua/plugins/telescope.lua rename to lua/plugins/configs/telescope.lua index 40b7383..9496667 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/configs/telescope.lua @@ -65,21 +65,23 @@ telescope.setup { }, } --- NvChad pickers --- load the theme_switcher extension -require("telescope").load_extension "themes" --- load the term_picker extension -require("telescope").load_extension "terms" +if + not pcall(function() + -- NvChad pickers + -- load the theme_switcher extension + telescope.load_extension "themes" + -- load the term_picker extension + telescope.load_extension "terms" -if not pcall(function() - telescope.load_extension "fzf" - telescope.load_extension "media_files" -end) then + telescope.load_extension "fzf" + telescope.load_extension "media_files" + end) +then -- This should only trigger when in need of PackerSync, so better do it print "After completion of PackerCompile, restart neovim." -- Trigger packer compile on PackerComplete, so it properly waits for PackerSync vim.cmd 'autocmd User PackerComplete ++once lua print "Waiting for PackerCompile.." require("packer").compile()' vim.cmd 'autocmd User PackerCompileDone ++once echo "Packer Compile done, restart neovim."' - require "pluginList" - require("packer").update("telescope-fzf-native.nvim", "telescope-media-files.nvim") + require "plugins" + require("packer").update("core", "telescope-fzf-native.nvim", "telescope-media-files.nvim") end diff --git a/lua/plugins/treesitter.lua b/lua/plugins/configs/treesitter.lua similarity index 100% rename from lua/plugins/treesitter.lua rename to lua/plugins/configs/treesitter.lua diff --git a/lua/plugins/zenmode.lua b/lua/plugins/configs/zenmode.lua similarity index 100% rename from lua/plugins/zenmode.lua rename to lua/plugins/configs/zenmode.lua index 16b5b62..695ddc9 100644 --- a/lua/plugins/zenmode.lua +++ b/lua/plugins/configs/zenmode.lua @@ -6,11 +6,11 @@ end true_zen.setup { ui = { bottom = { + cmdheight = 1, laststatus = 0, ruler = false, showmode = false, showcmd = false, - cmdheight = 1, }, top = { showtabline = 0, diff --git a/lua/pluginList.lua b/lua/plugins/init.lua similarity index 66% rename from lua/pluginList.lua rename to lua/plugins/init.lua index 90dfbcf..2068684 100644 --- a/lua/pluginList.lua +++ b/lua/plugins/init.lua @@ -1,28 +1,39 @@ -local plugin_status = require("utils").load_config().plugin_status +local present, packer = pcall(require, "plugins.packerInit") -local present, _ = pcall(require, "packerInit") -local packer - -if present then - packer = require "packer" -else +if not present then return false end local use = packer.use return packer.startup(function() + local plugin_status = require("core.utils").load_config().plugin_status + + -- 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/core", + } + use { "wbthomason/packer.nvim", event = "VimEnter", } use { - "jdhao/better-escape.vim", - disable = not plugin_status.better_esc, - event = "InsertEnter", + "NvChad/nvim-base16.lua", + after = "packer.nvim", config = function() - require("plugins.others").escape() + require("colors").init() + end, + } + + use { + "kyazdani42/nvim-web-devicons", + after = "nvim-base16.lua", + config = function() + require "plugins.configs.icons" end, } @@ -31,36 +42,99 @@ return packer.startup(function() disable = not plugin_status.galaxyline, after = "nvim-web-devicons", config = function() - require "plugins.statusline" - end, - } - use { - "akinsho/bufferline.nvim", - disable = not plugin_status.nvim_bufferline, - after = "galaxyline.nvim", - config = function() - require "plugins.bufferline" - end, - setup = function() - require("mappings").bufferline() + require "plugins.configs.statusline" end, } - -- color related stuff use { - "NvChad/nvim-base16.lua", - after = "packer.nvim", + "akinsho/bufferline.nvim", + disable = not plugin_status.bufferline, + after = "galaxyline.nvim", config = function() - require "theme" + require "plugins.configs.bufferline" + end, + setup = function() + require("core.mappings").bufferline() + end, + } + + use { + "nvim-lua/plenary.nvim", + after = "bufferline.nvim", + } + + -- git stuff + use { + "lewis6991/gitsigns.nvim", + disable = not plugin_status.gitsigns, + after = "plenary.nvim", + config = function() + require "plugins.configs.gitsigns" + end, + } + + use { + "nvim-telescope/telescope.nvim", + after = "plenary.nvim", + requires = { + { + "sudormrfbin/cheatsheet.nvim", + disable = not plugin_status.cheatsheet, + after = "telescope.nvim", + config = function() + require "plugins.configs.chadsheet" + end, + setup = function() + require("core.mappings").chadsheet() + end, + }, + { + "nvim-telescope/telescope-fzf-native.nvim", + run = "make", + }, + { + "nvim-telescope/telescope-media-files.nvim", + disable = not plugin_status.telescope_media, + setup = function() + require("core.mappings").telescope_media() + end, + }, + }, + config = function() + require "plugins.configs.telescope" + end, + setup = function() + require("core.mappings").telescope() + end, + } + + -- load autosave only if its globally enabled + use { + disable = not plugin_status.autosave, + "Pocco81/AutoSave.nvim", + config = function() + require "plugins.configs.autosave" + end, + cond = function() + return require("core.utils").load_config().options.plugin.autosave == true + end, + } + + use { + "lukas-reineke/indent-blankline.nvim", + disable = not plugin_status.blankline, + event = "BufRead", + config = function() + require("plugins.configs.others").blankline() end, } use { "norcalli/nvim-colorizer.lua", - disable = not plugin_status.nvim_colorizer, + disable = not plugin_status.colorizer, event = "BufRead", config = function() - require("plugins.others").colorizer() + require("plugins.configs.others").colorizer() end, } @@ -69,7 +143,7 @@ return packer.startup(function() "nvim-treesitter/nvim-treesitter", event = "BufRead", config = function() - require "plugins.treesitter" + require "plugins.configs.treesitter" end, } @@ -82,16 +156,7 @@ return packer.startup(function() "neovim/nvim-lspconfig", after = "nvim-lspinstall", config = function() - require "plugins.lspconfig" - end, - } - - use { - "onsails/lspkind-nvim", - disable = not plugin_status.lspkind, - event = "BufEnter", - config = function() - require("plugins.others").lspkind() + require "plugins.configs.lspconfig" end, } @@ -100,7 +165,28 @@ return packer.startup(function() disable = not plugin_status.lspsignature, after = "nvim-lspconfig", config = function() - require("plugins.others").signature() + require("plugins.configs.others").signature() + end, + } + + use { + "onsails/lspkind-nvim", + disable = not plugin_status.lspkind, + event = "BufEnter", + config = function() + require("plugins.configs.others").lspkind() + end, + } + + use { + "jdhao/better-escape.vim", + disable = not plugin_status.esc_insertmode, + event = "InsertEnter", + config = function() + require("plugins.configs.others").better_escape() + end, + setup = function() + require("core.mappings").better_escape() end, } @@ -109,7 +195,7 @@ return packer.startup(function() "hrsh7th/nvim-compe", event = "InsertEnter", config = function() - require "plugins.compe" + require "plugins.configs.compe" end, wants = "LuaSnip", requires = { @@ -118,7 +204,7 @@ return packer.startup(function() wants = "friendly-snippets", event = "InsertCharPre", config = function() - require "plugins.luasnip" + require "plugins.configs.luasnip" end, }, { @@ -128,91 +214,12 @@ return packer.startup(function() }, } - use { - "sbdchd/neoformat", - disable = not plugin_status.neoformat, - cmd = "Neoformat", - setup = function() - require("mappings").neoformat() - end, - } - - -- file managing , picker etc - use { - "kyazdani42/nvim-tree.lua", - cmd = "NvimTreeToggle", - config = function() - require "plugins.nvimtree" - end, - setup = function() - require("mappings").nvimtree() - end, - } - - use { - "kyazdani42/nvim-web-devicons", - after = "nvim-base16.lua", - config = function() - require "plugins.icons" - end, - } - - use { - "nvim-lua/plenary.nvim", - after = "bufferline.nvim", - } - - use { - "nvim-telescope/telescope.nvim", - after = "plenary.nvim", - requires = { - { - "nvim-telescope/telescope-fzf-native.nvim", - run = "make", - }, - { - "nvim-telescope/telescope-media-files.nvim", - disable = not plugin_status.telescope_media, - setup = function() - require("mappings").telescope_media() - end, - }, - { - "sudormrfbin/cheatsheet.nvim", - disable = not plugin_status.cheatsheet, - after = "telescope.nvim", - config = function() - require "plugins.chadsheet" - end, - setup = function() - require("mappings").chadsheet() - end, - }, - }, - config = function() - require "plugins.telescope" - end, - setup = function() - require("mappings").telescope() - end, - } - - -- git stuff - use { - "lewis6991/gitsigns.nvim", - disable = not plugin_status.gitsigns, - after = "plenary.nvim", - config = function() - require "plugins.gitsigns" - end, - } - -- misc plugins use { "windwp/nvim-autopairs", after = "nvim-compe", config = function() - require "plugins.autopairs" + require "plugins.configs.autopairs" end, } @@ -222,21 +229,19 @@ return packer.startup(function() event = "CursorMoved", } + -- smooth scroll use { - "terrortylor/nvim-comment", - disable = not plugin_status.nvim_comment, - cmd = "CommentToggle", + "karb94/neoscroll.nvim", + disable = not plugin_status.neoscroll, + event = "WinScrolled", config = function() - require("plugins.others").comment() - end, - setup = function() - require("mappings").comment_nvim() + require("plugins.configs.others").neoscroll() end, } use { "glepnir/dashboard-nvim", - disable = not plugin_status.dashboard_nvim, + disable = not plugin_status.dashboard, cmd = { "Dashboard", "DashboardNewFile", @@ -244,58 +249,61 @@ return packer.startup(function() "SessionLoad", "SessionSave", }, + config = function() + require "plugins.configs.dashboard" + end, setup = function() - require "plugins.dashboard" - require("mappings").dashboard() + require("core.mappings").dashboard() end, } - -- load autosave only if its globally enabled use { - disable = not plugin_status.autosave_nvim, - "Pocco81/AutoSave.nvim", - config = function() - require "plugins.autosave" - end, - cond = function() - return vim.g.auto_save == true + "sbdchd/neoformat", + disable = not plugin_status.neoformat, + cmd = "Neoformat", + setup = function() + require("core.mappings").neoformat() end, } - -- smooth scroll + -- use "alvan/vim-closetag" -- for html autoclosing tag use { - "karb94/neoscroll.nvim", - disable = not plugin_status.neoscroll_nvim, - event = "WinScrolled", + "terrortylor/nvim-comment", + disable = not plugin_status.comment, + cmd = "CommentToggle", config = function() - require("plugins.others").neoscroll() + require("plugins.configs.others").comment() + end, + setup = function() + require("core.mappings").comment() + end, + } + + -- file managing , picker etc + use { + "kyazdani42/nvim-tree.lua", + cmd = "NvimTreeToggle", + config = function() + require "plugins.configs.nvimtree" + end, + setup = function() + require("core.mappings").nvimtree() end, } use { "Pocco81/TrueZen.nvim", - disable = not plugin_status.truezen_nvim, + disable = not plugin_status.truezen, cmd = { "TZAtaraxis", "TZMinimalist", "TZFocus", }, config = function() - require "plugins.zenmode" + require "plugins.configs.zenmode" end, setup = function() - require("mappings").truezen() - end, - } - - -- use "alvan/vim-closetag" -- for html autoclosing tag - - use { - "lukas-reineke/indent-blankline.nvim", - disable = not plugin_status.blankline, - event = "BufRead", - setup = function() - require("plugins.others").blankline() + require("core.mappings").truezen() end, } @@ -306,7 +314,7 @@ return packer.startup(function() "Git", }, setup = function() - require("mappings").fugitive() + require("core.mappings").vim_fugitive() end, } end) diff --git a/lua/packerInit.lua b/lua/plugins/packerInit.lua similarity index 97% rename from lua/packerInit.lua rename to lua/plugins/packerInit.lua index 8b0561c..bd6505c 100644 --- a/lua/packerInit.lua +++ b/lua/plugins/packerInit.lua @@ -29,7 +29,7 @@ if not present then end end -return packer.init { +packer.init { display = { open_fn = function() return require("packer.util").float { border = "single" } @@ -43,3 +43,5 @@ return packer.init { compile_on_sync = true, -- auto_reload_compiled = true } + +return packer diff --git a/lua/telescope/_extensions/terms.lua b/lua/telescope/_extensions/terms.lua deleted file mode 100644 index 2acd08a..0000000 --- a/lua/telescope/_extensions/terms.lua +++ /dev/null @@ -1,143 +0,0 @@ --- This file can be loaded as a telescope extension -local M = {} - --- Custom theme picker --- Most of the code is copied from telescope buffer builtin --- Src: https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/builtin/internal.lua -M.term_picker = function(opts) - local pickers, finders, previewers, make_entry, actions, action_state, utils, conf - if pcall(require, "telescope") then - pickers = require "telescope.pickers" - finders = require "telescope.finders" - previewers = require "telescope.previewers" - - make_entry = require "telescope.make_entry" - actions = require "telescope.actions" - action_state = require "telescope.actions.state" - utils = require "telescope.utils" - conf = require("telescope.config").values - else - error "Cannot find telescope!" - end - - local filter = vim.tbl_filter - - local local_utils = require "utils" - - -- buffer number and name - local bufnr = vim.api.nvim_get_current_buf() - local bufname = vim.api.nvim_buf_get_name(bufnr) - - local bufnrs = filter(function(b) - local present_type, type = pcall(function() - return vim.api.nvim_buf_get_var(b, "term_type") - end) - - if not present_type then - -- let's only terms that we created - return false - end - - -- if 1 ~= vim.fn.buflisted(b) then - -- return false - -- end - -- only hide unloaded buffers if opts.show_all_buffers is false, keep them listed if true or nil - if opts.show_all_buffers == false and not vim.api.nvim_buf_is_loaded(b) then - return false - end - if opts.ignore_current_buffer and b == vim.api.nvim_get_current_buf() then - return false - end - return true - end, vim.api.nvim_list_bufs()) - if not next(bufnrs) then - return - end - if opts.sort_mru then - table.sort(bufnrs, function(a, b) - return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused - end) - end - - local buffers = {} - local default_selection_idx = 1 - for _, bufnr in ipairs(bufnrs) do - local flag = bufnr == vim.fn.bufnr "" and "%" or (bufnr == vim.fn.bufnr "#" and "#" or " ") - - if opts.sort_lastused and not opts.ignore_current_buffer and flag == "#" then - default_selection_idx = 2 - end - - local element = { - bufnr = bufnr, - flag = flag, - info = vim.fn.getbufinfo(bufnr)[1], - } - - if opts.sort_lastused and (flag == "#" or flag == "%") then - local idx = ((buffers[1] ~= nil and buffers[1].flag == "%") and 2 or 1) - table.insert(buffers, idx, element) - else - table.insert(buffers, element) - end - end - - if not opts.bufnr_width then - local max_bufnr = math.max(unpack(bufnrs)) - opts.bufnr_width = #tostring(max_bufnr) - end - - pickers.new(opts, { - prompt_title = "Terminal buffers", - finder = finders.new_table { - results = buffers, - entry_maker = opts.entry_maker or make_entry.gen_from_buffer(opts), - }, - previewer = conf.grep_previewer(opts), - sorter = conf.generic_sorter(opts), - default_selection_index = default_selection_idx, - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local entry = action_state.get_selected_entry() - actions.close(prompt_bufnr) - - local buf = entry.bufnr - - local chad_term, type = pcall(function() - return vim.api.nvim_buf_get_var(buf, "term_type") - end) - - -- TODO buffer checks/error detection (make sure we do get a buf) - - if chad_term then - if type == "wind" then - -- swtich to term buff & show in bufferline - vim.cmd(string.format("b %d | setlocal bl", buf)) - -- vim.cmd('startinsert') TODO fix this - elseif type == "vert" then - vim.cmd(string.format("vsp #%d", buf)) - -- vim.cmd('startinsert') TODO fix this - elseif type == "hori" then - -- TODO change 15 to a chad config var number - vim.cmd(string.format("15 sp #%d ", buf)) - -- vim.cmd('startinsert') TODO fix this - end - end - end) - - return true - end, - }):find() -end - --- register term picker as terms to telescope -local present, telescope = pcall(require, "telescope") -if present then - return telescope.register_extension { - exports = { - terms = M.term_picker, - }, - } -else - error "Cannot find telescope!" -end diff --git a/lua/telescope/_extensions/themes.lua b/lua/telescope/_extensions/themes.lua deleted file mode 100644 index e0aed13..0000000 --- a/lua/telescope/_extensions/themes.lua +++ /dev/null @@ -1,142 +0,0 @@ --- This file can be loaded as a telescope extension -local M = {} - --- Custom theme picker --- Most of the code is copied from telescope colorscheme plugin, mostly for preview creation -M.theme_switcher = function(opts) - local pickers, finders, previewers, actions, action_state, utils, conf - if pcall(require, "telescope") then - pickers = require "telescope.pickers" - finders = require "telescope.finders" - previewers = require "telescope.previewers" - - actions = require "telescope.actions" - action_state = require "telescope.actions.state" - utils = require "telescope.utils" - conf = require("telescope.config").values - else - error "Cannot find telescope!" - end - - local local_utils = require "utils" - local reload_theme = local_utils.reload_theme - - -- get a table of available themes - local themes = local_utils.list_themes() - if next(themes) ~= nil then - -- save this to use it for later to restore if theme not changed - local current_theme = vim.g.nvchad_theme - local new_theme = "" - local change = false - - -- buffer number and name - local bufnr = vim.api.nvim_get_current_buf() - local bufname = vim.api.nvim_buf_get_name(bufnr) - - local previewer - - -- in case its not a normal buffer - if vim.fn.buflisted(bufnr) ~= 1 then - local deleted = false - local function del_win(win_id) - if win_id and vim.api.nvim_win_is_valid(win_id) then - utils.buf_delete(vim.api.nvim_win_get_buf(win_id)) - pcall(vim.api.nvim_win_close, win_id, true) - end - end - - previewer = previewers.new { - preview_fn = function(_, entry, status) - if not deleted then - deleted = true - del_win(status.preview_win) - del_win(status.preview_border_win) - end - reload_theme(entry.value) - end, - } - else - -- show current buffer content in previewer - previewer = previewers.new_buffer_previewer { - get_buffer_by_name = function() - return bufname - end, - define_preview = function(self, entry) - if vim.loop.fs_stat(bufname) then - conf.buffer_previewer_maker(bufname, self.state.bufnr, { bufname = self.state.bufname }) - else - local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines) - end - reload_theme(entry.value) - end, - } - end - - local picker = pickers.new { - prompt_title = "Set NvChad color", - finder = finders.new_table(themes), - previewer = previewer, - sorter = conf.generic_sorter(opts), - attach_mappings = function() - actions.select_default:replace( - -- if a entry is selected, change current_theme to that - function(prompt_bufnr) - local selection = action_state.get_selected_entry() - new_theme = selection.value - change = true - actions.close(prompt_bufnr) - end - ) - return true - end, - } - - -- rewrite picker.close_windows - local close_windows = picker.close_windows - picker.close_windows = function(status) - close_windows(status) - -- now apply the theme, if success, then ask for default theme change - local final_theme - if change then - final_theme = new_theme - else - final_theme = current_theme - end - - if reload_theme(final_theme) then - if change then - -- ask for confirmation to set as default theme - local ans = string.lower(vim.fn.input("Set " .. new_theme .. " as default theme ? [y/N] ")) == "y" - local_utils.clear_cmdline() - if ans then - local_utils.change_theme(current_theme, final_theme) - else - -- will be used in restoring nvchad theme var - final_theme = current_theme - end - end - else - final_theme = current_theme - end - -- set nvchad_theme global var - vim.g.nvchad_theme = final_theme - end - -- launch the telescope picker - picker:find() - else - print("No themes found in " .. vim.fn.stdpath "config" .. "/lua/themes") - end -end - --- register theme swticher as themes to telescope -local present, telescope = pcall(require, "telescope") -if present then - return telescope.register_extension { - exports = { - themes = M.theme_switcher, - }, - } -else - error "Cannot find telescope!" -end diff --git a/lua/theme.lua b/lua/theme.lua deleted file mode 100644 index 3002ac2..0000000 --- a/lua/theme.lua +++ /dev/null @@ -1,12 +0,0 @@ -local chad_theme = require("utils").load_config().ui.theme -vim.g.nvchad_theme = chad_theme - -local present, base16 = pcall(require, "base16") - -if present then - base16(base16.themes(chad_theme), true) - require "highlights" - return true -else - return false -end diff --git a/lua/utils.lua b/lua/utils.lua deleted file mode 100644 index 96d5771..0000000 --- a/lua/utils.lua +++ /dev/null @@ -1,531 +0,0 @@ -local M = {} - --- 1st arg as current theme, 2nd as new theme -M.change_theme = function(current_theme, new_theme) - if current_theme == nil or new_theme == nil then - print "Error: Provide current and new theme name" - return false - end - if current_theme == new_theme then - return - end - - local user_config = vim.g.nvchad_user_config - local file = vim.fn.stdpath "config" .. "/lua/" .. user_config .. ".lua" - -- store in data variable - local data = assert(M.file("r", file)) - -- escape characters which can be parsed as magic chars - current_theme = current_theme:gsub("%p", "%%%0") - new_theme = new_theme:gsub("%p", "%%%0") - local find = "theme = .?" .. current_theme .. ".?" - local replace = 'theme = "' .. new_theme .. '"' - local content = string.gsub(data, find, replace) - -- see if the find string exists in file - if content == data then - print("Error: Cannot change default theme with " .. new_theme .. ", edit " .. file .. " manually") - return false - else - assert(M.file("w", file, content)) - end -end - -M.clear_cmdline = function() - vim.defer_fn(function() - vim.cmd "echo" - end, 0) -end - -M.close_buffer = function(bufexpr, force) - -- This is a modification of a NeoVim plugin from - -- Author: ojroques - Olivier Roques - -- Src: https://github.com/ojroques/nvim-bufdel - -- (Author has okayed copy-paste) - - -- Options - local opts = { - next = "cycle", -- how to retrieve the next buffer - quit = false, -- exit when last buffer is deleted - --TODO make this a chadrc flag/option - } - - -- ---------------- - -- Helper functions - -- ---------------- - - -- Switch to buffer 'buf' on each window from list 'windows' - local function switch_buffer(windows, buf) - local cur_win = vim.fn.winnr() - for _, winid in ipairs(windows) do - vim.cmd(string.format("%d wincmd w", vim.fn.win_id2win(winid))) - vim.cmd(string.format("buffer %d", buf)) - end - vim.cmd(string.format("%d wincmd w", cur_win)) -- return to original window - end - - -- Select the first buffer with a number greater than given buffer - local function get_next_buf(buf) - local next = vim.fn.bufnr "#" - if opts.next == "alternate" and vim.fn.buflisted(next) == 1 then - return next - end - for i = 0, vim.fn.bufnr "$" - 1 do - next = (buf + i) % vim.fn.bufnr "$" + 1 -- will loop back to 1 - if vim.fn.buflisted(next) == 1 then - return next - end - end - end - - -- ---------------- - -- End helper functions - -- ---------------- - - local buf = vim.fn.bufnr() - if vim.fn.buflisted(buf) == 0 then -- exit if buffer number is invalid - vim.cmd "close" - return - end - - if #vim.fn.getbufinfo { buflisted = 1 } < 2 then - if opts.quit then - -- exit when there is only one buffer left - if force then - vim.cmd "qall!" - else - vim.cmd "confirm qall" - end - return - end - - local chad_term, type = pcall(function() - return vim.api.nvim_buf_get_var(buf, "term_type") - end) - - if chad_term then - -- Must be a window type - vim.cmd(string.format("setlocal nobl", buf)) - vim.cmd "enew" - return - end - -- don't exit and create a new empty buffer - vim.cmd "enew" - vim.cmd "bp" - end - - local next_buf = get_next_buf(buf) - local windows = vim.fn.getbufinfo(buf)[1].windows - - -- force deletion of terminal buffers to avoid the prompt - if force or vim.fn.getbufvar(buf, "&buftype") == "terminal" then - local chad_term, type = pcall(function() - return vim.api.nvim_buf_get_var(buf, "term_type") - end) - - -- TODO this scope is error prone, make resilient - if chad_term then - if type == "wind" then - -- hide from bufferline - vim.cmd(string.format("%d bufdo setlocal nobl", buf)) - -- swtich to another buff - -- TODO switch to next bufffer, this works too - vim.cmd "BufferLineCycleNext" - else - local cur_win = vim.fn.winnr() - -- we can close this window - vim.cmd(string.format("%d wincmd c", cur_win)) - return - end - else - switch_buffer(windows, next_buf) - vim.cmd(string.format("bd! %d", buf)) - end - else - switch_buffer(windows, next_buf) - vim.cmd(string.format("silent! confirm bd %d", buf)) - end - -- revert buffer switches if user has canceled deletion - if vim.fn.buflisted(buf) == 1 then - switch_buffer(windows, buf) - end -end - --- wrapper to use vim.api.nvim_echo --- table of {string, highlight} --- e.g echo({{"Hello", "Title"}, {"World"}}) -M.echo = function(opts) - if opts == nil or type(opts) ~= "table" then - return - end - vim.api.nvim_echo(opts, false, {}) -end - --- 1st arg - r or w --- 2nd arg - file path --- 3rd arg - content if 1st arg is w --- return file data on read, nothing on write -M.file = function(mode, filepath, content) - local data - local fd = assert(vim.loop.fs_open(filepath, mode, 438)) - local stat = assert(vim.loop.fs_fstat(fd)) - if stat.type ~= "file" then - data = false - else - if mode == "r" then - data = assert(vim.loop.fs_read(fd, stat.size, 0)) - else - assert(vim.loop.fs_write(fd, content, 0)) - data = true - end - end - assert(vim.loop.fs_close(fd)) - return data -end - --- hide statusline --- tables fetched from load_config function -M.hide_statusline = function(values) - local hidden = require("utils").load_config().ui.statusline.hidden - local shown = require("utils").load_config().ui.statusline.shown - local api = vim.api - local buftype = api.nvim_buf_get_option("%", "ft") - - -- shown table from config has the highest priority - if vim.tbl_contains(shown, buftype) then - api.nvim_set_option("laststatus", 2) - return - end - - if vim.tbl_contains(hidden, buftype) then - api.nvim_set_option("laststatus", 0) - return - else - api.nvim_set_option("laststatus", 2) - end -end - --- return a table of available themes -M.list_themes = function(return_type) - local themes = {} - -- folder where theme files are stored - local themes_folder = vim.fn.stdpath "config" .. "/lua/themes" - -- list all the contents of the folder and filter out files with .lua extension, then append to themes table - local fd = vim.loop.fs_scandir(themes_folder) - if fd then - while true do - local name, typ = vim.loop.fs_scandir_next(fd) - if name == nil then - break - end - if typ ~= "directory" and string.find(name, ".lua") then - -- return the table values as keys if specified - if return_type == "keys_as_value" then - themes[vim.fn.fnamemodify(name, ":r")] = true - else - table.insert(themes, vim.fn.fnamemodify(name, ":r")) - end - end - end - end - return themes -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 -M.merge_table = function(into, from) - -- 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 - 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 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 default_config = "default_config" - local config_name = vim.g.nvchad_user_config or "chadrc" - local config_file = vim.fn.stdpath "config" .. "/lua/" .. config_name .. ".lua" - - -- unload the modules if force reload - if reload then - package.loaded[default_config or false] = nil - package.loaded[config_name or false] = nil - 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.empty(vim.fn.glob(config_file)) < 1 then - local present, config = pcall(require, config_name) - if present then - -- make sure the returned value is table - if type(config) == "table" then - -- data = require(config_name) - _G._NVCHAD_CONFIG_CONTENTS = require("utils").merge_table(_G._NVCHAD_CONFIG_CONTENTS, config) - else - print("Warning: " .. config_name .. " 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 -end - --- reload a plugin ( will try to load even if not loaded) --- can take a string or list ( table ) --- return true or false -M.reload_plugin = function(plugins) - local status = true - local function _reload_plugin(plugin) - local loaded = package.loaded[plugin] - if loaded then - package.loaded[plugin] = nil - end - if not pcall(require, plugin) then - print("Error: Cannot load " .. plugin .. " plugin!") - status = false - end - end - - if type(plugins) == "string" then - _reload_plugin(plugins) - elseif type(plugins) == "table" then - for _, plugin in ipairs(plugins) do - _reload_plugin(plugin) - end - end - return status -end - --- reload themes without restarting vim --- if no theme name given then reload the current theme -M.reload_theme = function(theme_name) - local reload_plugin = require("utils").reload_plugin - - -- if theme name is empty or nil, then reload the current theme - if theme_name == nil or theme_name == "" then - theme_name = vim.g.nvchad_theme - end - - if not pcall(require, "themes/" .. theme_name) then - print("No such theme ( " .. theme_name .. " )") - return false - end - - vim.g.nvchad_theme = theme_name - - -- reload the base16 theme - local ok, base16 = pcall(require, "base16") - if not ok then - print "Error: Cannot load base16 plugin!" - return false - end - base16(base16.themes(theme_name), true) - - if - not reload_plugin { - "highlights", - "plugins.bufferline", - "galaxyline", - "plugins.statusline", - } - then - print "Error: Not able to reload all plugins." - return false - end - - -- yes, this is very hacky, but due to new_async in - -- https://github.com/glepnir/galaxyline.nvim/blob/main/lua/galaxyline/provider.lua#L5-L36 - -- it doesn't work properly and some statusline stuff dissapears - local vcs = require "galaxyline.provider_vcs" - local fileinfo = require "galaxyline.provider_fileinfo" - local buffer = require "galaxyline.provider_buffer" - local extension = require "galaxyline.provider_extensions" - local whitespace = require "galaxyline.provider_whitespace" - local lspclient = require "galaxyline.provider_lsp" - _G.galaxyline_providers = { - BufferIcon = buffer.get_buffer_type_icon, - BufferNumber = buffer.get_buffer_number, - FileTypeName = buffer.get_buffer_filetype, - GitBranch = vcs.get_git_branch, - DiffAdd = vcs.diff_add, - DiffModified = vcs.diff_modified, - DiffRemove = vcs.diff_remove, - LineColumn = fileinfo.line_column, - FileFormat = fileinfo.get_file_format, - FileEncode = fileinfo.get_file_encode, - FileSize = fileinfo.get_file_size, - FileIcon = fileinfo.get_file_icon, - FileName = fileinfo.get_current_file_name, - SFileName = fileinfo.filename_in_special_buffer, - LinePercent = fileinfo.current_line_percent, - ScrollBar = extension.scrollbar_instance, - VistaPlugin = extension.vista_nearest, - WhiteSpace = whitespace.get_item, - GetLspClient = lspclient.get_lsp_client, - } - local diagnostic = require "galaxyline.provider_diagnostic" - _G.galaxyline_providers.DiagnosticError = diagnostic.get_diagnostic_error - _G.galaxyline_providers.DiagnosticWarn = diagnostic.get_diagnostic_warn - _G.galaxyline_providers.DiagnosticHint = diagnostic.get_diagnostic_hint - _G.galaxyline_providers.DiagnosticInfo = diagnostic.get_diagnostic_info - - return true -end - --- toggle between 2 themes --- argument should be a table with 2 theme names -M.toggle_theme = function(themes) - local current_theme = vim.g.current_nvchad_theme or vim.g.nvchad_theme - for _, name in ipairs(themes) do - if name ~= current_theme then - if require("utils").reload_theme(name) then - -- open a buffer and close it to reload the statusline - vim.cmd "new|bwipeout" - vim.g.current_nvchad_theme = name - if M.change_theme(vim.g.nvchad_theme, name) then - vim.g.nvchad_theme = name - end - end - end - end -end - --- update nvchad -M.update_nvchad = function() - -- in all the comments below, config means user config - local config_path = vim.fn.stdpath "config" - local config_name = vim.g.nvchad_user_config or "chadrc" - local config_file = config_path .. "/lua/" .. config_name .. ".lua" - -- generate a random file name - local config_file_backup = config_path .. "/" .. config_name .. ".lua.bak." .. math.random() - local utils = require "utils" - local echo = utils.echo - local current_config = utils.load_config() - local update_url = current_config.options.update_url or "https://github.com/NvChad/NvChad" - local update_branch = current_config.options.update_branch or "main" - - -- ask the user for confirmation to update because we are going to run git reset --hard - echo { { "Url: ", "Title" }, { update_url } } - echo { { "Branch: ", "Title" }, { update_branch } } - echo { - { "\nUpdater will run", "WarningMsg" }, - { " git reset --hard " }, - { - "in config folder, so changes to existing repo files except ", - "WarningMsg", - }, - - { config_name }, - { " will be lost!\n\nUpdate NvChad ? [y/N]", "WarningMsg" }, - } - - local ans = string.lower(vim.fn.input "-> ") == "y" - utils.clear_cmdline() - if not ans then - echo { { "Update cancelled!", "Title" } } - return - end - - -- first try to fetch contents of config, this will make sure it is readable and taking backup of its contents - local config_contents = utils.file("r", config_file) - -- also make a local backup in ~/.config/nvim, will be removed when config is succesfully restored - utils.file("w", config_file_backup, config_contents) - -- write original config file with its contents, will make sure charc is writable, this maybe overkill but a little precaution always helps - utils.file("w", config_file, config_contents) - - -- function that will executed when git commands are done - local function update_exit(_, code) - -- restore config file irrespective of whether git commands were succesfull or not - if pcall(function() - utils.file("w", config_file, config_contents) - end) then - -- config restored succesfully, remove backup file that was created - if not pcall(os.remove, config_file_backup) then - echo { { "Warning: Failed to remove backup chadrc, remove manually.", "WarningMsg" } } - echo { { "Path: ", "WarningMsg" }, { config_file_backup } } - end - else - echo { { "Error: Restoring " .. config_name .. " failed.\n", "ErrorMsg" } } - echo { { "Backed up " .. config_name .. " path: " .. config_file_backup .. "\n\n", "None" } } - end - - -- close the terminal buffer only if update was success, as in case of error, we need the error message - if code == 0 then - vim.cmd "bd!" - echo { { "NvChad succesfully updated.\n", "String" } } - else - echo { { "Error: NvChad Update failed.\n", "ErrorMsg" } } - end - end - - -- git commands that will executed, reset in case config was modfied - -- use --rebase, to not mess up if the local repo is outdated - local update_script = table.concat({ - "git reset --hard && git pull --set-upstream", - update_url, - update_branch, - "--rebase", - }, " ") - - -- open a new buffer - vim.cmd "new" - -- finally open the pseudo terminal buffer - vim.fn.termopen(update_script, { - -- change dir to config path so we don't need to move in script - cwd = config_path, - on_exit = update_exit, - }) -end - -return M