From 42bf581337edabea18677085ecd96651aaf57daf Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Wed, 14 Jul 2021 10:27:33 +0530 Subject: [PATCH 1/7] Disable nvim intro and tilde chars on end of buffer This avoids the situation when the initial screen looks out of place because there is some pre rendered text https://github.com/neovim/neovim/pull/8546 --- lua/options.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/options.lua b/lua/options.lua index 611acd6..c83e6ae 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -14,6 +14,12 @@ opt.updatetime = 250 -- update interval for gitsigns opt.timeoutlen = 400 opt.clipboard = "unnamedplus" +-- disable nvim intro +opt.shortmess:append("sI") + +-- disable tilde on end of buffer: https://github.com/ neovim/neovim/pull/8546#issuecomment-643643758 +vim.cmd [[let &fcs='eob: ']] + -- Numbers opt.number = true opt.numberwidth = 2 From 0d7345bc44f04225bdd3df0ab57e0a48b08aa83a Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Wed, 14 Jul 2021 10:54:09 +0530 Subject: [PATCH 2/7] Move options from init.lua => options.lua use a local g = vim.g --- init.lua | 8 +------- lua/options.lua | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/init.lua b/init.lua index ececd85..58a90da 100644 --- a/init.lua +++ b/init.lua @@ -2,14 +2,8 @@ require "pluginList" require "options" -local g = vim.g - -g.mapleader = " " -g.auto_save = false - -- colorscheme related stuff - -g.nvchad_theme = "onedark" +vim.g.nvchad_theme = "onedark" local base16 = require "base16" base16(base16.themes["onedark"], true) diff --git a/lua/options.lua b/lua/options.lua index c83e6ae..3d2d2dd 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,4 +1,5 @@ local opt = vim.opt +local g = vim.g opt.ruler = false opt.hidden = true @@ -30,17 +31,20 @@ opt.expandtab = true opt.shiftwidth = 2 opt.smartindent = true +g.mapleader = " " +g.auto_save = false + -- disable builtin vim plugins -vim.g.loaded_gzip = 0 -vim.g.loaded_tar = 0 -vim.g.loaded_tarPlugin = 0 -vim.g.loaded_zipPlugin = 0 -vim.g.loaded_2html_plugin = 0 -vim.g.loaded_netrw = 0 -vim.g.loaded_netrwPlugin = 0 -vim.g.loaded_matchit = 0 -vim.g.loaded_matchparen = 0 -vim.g.loaded_spec = 0 +g.loaded_gzip = 0 +g.loaded_tar = 0 +g.loaded_tarPlugin = 0 +g.loaded_zipPlugin = 0 +g.loaded_2html_plugin = 0 +g.loaded_netrw = 0 +g.loaded_netrwPlugin = 0 +g.loaded_matchit = 0 +g.loaded_matchparen = 0 +g.loaded_spec = 0 local M = {} From d16ffabcfdd14ccfdcf779104c09f408786b1da8 Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Thu, 15 Jul 2021 21:13:17 +0530 Subject: [PATCH 3/7] [1/4] Refactor: plugins: Add seperate config for each plugins first commit of Refactor handle require errors move config from other places to proper files don't create a pseudo config function for no reason https://github.com/siduck76/NvChad/pull/156#issuecomment-881453546 --- lua/plugins/autopairs.lua | 19 ++ lua/plugins/autosave.lua | 27 +++ lua/plugins/blankline.lua | 9 + lua/plugins/bufferline.lua | 13 +- lua/plugins/colorizer.lua | 13 ++ lua/plugins/comment.lua | 5 + lua/plugins/compe.lua | 63 +++--- lua/plugins/dashboard.lua | 78 ++++--- lua/plugins/gitsigns.lua | 67 +++--- lua/plugins/icons.lua | 247 ++++++++++----------- lua/plugins/lspconfig.lua | 166 ++++++++------- lua/plugins/lspkind.lua | 5 + lua/plugins/luasnip.lua | 18 ++ lua/plugins/neoscroll.lua | 5 + lua/plugins/nvimtree.lua | 193 ++++++++--------- lua/plugins/statusline.lua | 425 +++++++++++++++++++------------------ lua/plugins/telescope.lua | 42 ++-- lua/plugins/treesitter.lua | 49 +++-- lua/plugins/zenmode.lua | 128 +++++------ 19 files changed, 847 insertions(+), 725 deletions(-) create mode 100644 lua/plugins/autopairs.lua create mode 100644 lua/plugins/autosave.lua create mode 100644 lua/plugins/blankline.lua create mode 100644 lua/plugins/colorizer.lua create mode 100644 lua/plugins/comment.lua create mode 100644 lua/plugins/lspkind.lua create mode 100644 lua/plugins/luasnip.lua create mode 100644 lua/plugins/neoscroll.lua diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua new file mode 100644 index 0000000..9399571 --- /dev/null +++ b/lua/plugins/autopairs.lua @@ -0,0 +1,19 @@ +local autopairs, autopairs_completion +if + not pcall( + function() + autopairs = require "nvim-autopairs" + autopairs_completion = require "nvim-autopairs.completion.compe" + end + ) + then + return +end + +autopairs.setup() +autopairs_completion.setup( + { + map_cr = true, + map_complete = true -- insert () func completion + } +) diff --git a/lua/plugins/autosave.lua b/lua/plugins/autosave.lua new file mode 100644 index 0000000..6ddcd82 --- /dev/null +++ b/lua/plugins/autosave.lua @@ -0,0 +1,27 @@ +-- autosave.nvim plugin disabled by default +local autosave +if + not pcall( + function() + func = require "autosave" + end + ) + then + return +end + +autosave.setup( + { + enabled = vim.g.auto_save, -- takes boolean value from init.lua + execution_message = "autosaved at : " .. vim.fn.strftime("%H:%M:%S"), + events = {"InsertLeave", "TextChanged"}, + conditions = { + exists = true, + filetype_is_not = {}, + modifiable = true + }, + write_all_buffers = true, + on_off_commands = true, + clean_command_line_interval = 2500 + } +) diff --git a/lua/plugins/blankline.lua b/lua/plugins/blankline.lua new file mode 100644 index 0000000..6a1bd4a --- /dev/null +++ b/lua/plugins/blankline.lua @@ -0,0 +1,9 @@ +-- blankline config +vim.g.indentLine_enabled = 1 +vim.g.indent_blankline_char = "▏" + +vim.g.indent_blankline_filetype_exclude = {"help", "terminal", "dashboard"} +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 diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua index 342e687..c34b771 100644 --- a/lua/plugins/bufferline.lua +++ b/lua/plugins/bufferline.lua @@ -1,7 +1,18 @@ local global_theme = "themes/" .. vim.g.nvchad_theme local colors = require(global_theme) -require "bufferline".setup { +local bufferline +if + not pcall( + function() + bufferline = require "bufferline" + end + ) + then + return +end + +bufferline.setup { options = { offsets = {{filetype = "NvimTree", text = "", padding = 1}}, buffer_close_icon = "", diff --git a/lua/plugins/colorizer.lua b/lua/plugins/colorizer.lua new file mode 100644 index 0000000..d3e1d9d --- /dev/null +++ b/lua/plugins/colorizer.lua @@ -0,0 +1,13 @@ +local colorizer +if + not pcall( + function() + colorizer = require("colorizer") + end + ) + then + return +end + +colorizer.setup() +vim.cmd("ColorizerReloadAllBuffers") diff --git a/lua/plugins/comment.lua b/lua/plugins/comment.lua new file mode 100644 index 0000000..2a41f8a --- /dev/null +++ b/lua/plugins/comment.lua @@ -0,0 +1,5 @@ +pcall( + function() + require("nvim_comment").setup() + end +) diff --git a/lua/plugins/compe.lua b/lua/plugins/compe.lua index cdf0235..c41139a 100644 --- a/lua/plugins/compe.lua +++ b/lua/plugins/compe.lua @@ -1,38 +1,31 @@ -local M = {} - -M.config = function() - require "compe".setup { - enabled = true, - autocomplete = true, - debug = false, - min_length = 1, - preselect = "enable", - throttle_time = 80, - source_timeout = 200, - incomplete_delay = 400, - max_abbr_width = 100, - max_kind_width = 100, - max_menu_width = 100, - documentation = true, - source = { - buffer = {kind = "﬘", true}, - luasnip = {kind = "﬌", true}, - nvim_lsp = true, - nvim_lua = true - } - } -end - -M.snippets = function() - local ls = require("luasnip") - - ls.config.set_config( - { - history = true, - updateevents = "TextChanged,TextChangedI" - } +local compe +if + not pcall( + function() + compe = require "compe" + end ) - require("luasnip/loaders/from_vscode").load() + then + return end -return M +compe.setup { + enabled = true, + autocomplete = true, + debug = false, + min_length = 1, + preselect = "enable", + throttle_time = 80, + source_timeout = 200, + incomplete_delay = 400, + max_abbr_width = 100, + max_kind_width = 100, + max_menu_width = 100, + documentation = true, + source = { + buffer = {kind = "﬘", true}, + luasnip = {kind = "﬌", true}, + nvim_lsp = true, + nvim_lua = true + } +} diff --git a/lua/plugins/dashboard.lua b/lua/plugins/dashboard.lua index 1e4ea0c..54d317e 100644 --- a/lua/plugins/dashboard.lua +++ b/lua/plugins/dashboard.lua @@ -1,46 +1,40 @@ -local M = {} +local g = vim.g +local fn = vim.fn -M.config = function() - 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 +g.dashboard_default_executive = "telescope" +g.dashboard_custom_header = { + " ", + " ", + " ", + " ⣴⣶⣤⡤⠦⣤⣀⣤⠆ ⣈⣭⣿⣶⣿⣦⣼⣆ ", + " ⠉⠻⢿⣿⠿⣿⣿⣶⣦⠤⠄⡠⢾⣿⣿⡿⠋⠉⠉⠻⣿⣿⡛⣦ ", + " ⠈⢿⣿⣟⠦ ⣾⣿⣿⣷ ⠻⠿⢿⣿⣧⣄ ", + " ⣸⣿⣿⢧ ⢻⠻⣿⣿⣷⣄⣀⠄⠢⣀⡀⠈⠙⠿⠄ ", + " ⢠⣿⣿⣿⠈ ⣻⣿⣿⣿⣿⣿⣿⣿⣛⣳⣤⣀⣀ ", + " ⢠⣧⣶⣥⡤⢄ ⣸⣿⣿⠘ ⢀⣴⣿⣿⡿⠛⣿⣿⣧⠈⢿⠿⠟⠛⠻⠿⠄ ", + " ⣰⣿⣿⠛⠻⣿⣿⡦⢹⣿⣷ ⢊⣿⣿⡏ ⢸⣿⣿⡇ ⢀⣠⣄⣾⠄ ", + " ⣠⣿⠿⠛ ⢀⣿⣿⣷⠘⢿⣿⣦⡀ ⢸⢿⣿⣿⣄ ⣸⣿⣿⡇⣪⣿⡿⠿⣿⣷⡄ ", + " ⠙⠃ ⣼⣿⡟ ⠈⠻⣿⣿⣦⣌⡇⠻⣿⣿⣷⣿⣿⣿ ⣿⣿⡇ ⠛⠻⢷⣄ ", + " ⢻⣿⣿⣄ ⠈⠻⣿⣿⣿⣷⣿⣿⣿⣿⣿⡟ ⠫⢿⣿⡆ ", + " ⠻⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣀⣤⣾⡿⠃ ", + " " +} - g.dashboard_disable_at_vimenter = 1 -- dashboard is disabled by default - g.dashboard_disable_statusline = 1 - g.dashboard_default_executive = "telescope" - g.dashboard_custom_header = { - " ", - " ", - " ", - " ⣴⣶⣤⡤⠦⣤⣀⣤⠆ ⣈⣭⣿⣶⣿⣦⣼⣆ ", - " ⠉⠻⢿⣿⠿⣿⣿⣶⣦⠤⠄⡠⢾⣿⣿⡿⠋⠉⠉⠻⣿⣿⡛⣦ ", - " ⠈⢿⣿⣟⠦ ⣾⣿⣿⣷ ⠻⠿⢿⣿⣧⣄ ", - " ⣸⣿⣿⢧ ⢻⠻⣿⣿⣷⣄⣀⠄⠢⣀⡀⠈⠙⠿⠄ ", - " ⢠⣿⣿⣿⠈ ⣻⣿⣿⣿⣿⣿⣿⣿⣛⣳⣤⣀⣀ ", - " ⢠⣧⣶⣥⡤⢄ ⣸⣿⣿⠘ ⢀⣴⣿⣿⡿⠛⣿⣿⣧⠈⢿⠿⠟⠛⠻⠿⠄ ", - " ⣰⣿⣿⠛⠻⣿⣿⡦⢹⣿⣷ ⢊⣿⣿⡏ ⢸⣿⣿⡇ ⢀⣠⣄⣾⠄ ", - " ⣠⣿⠿⠛ ⢀⣿⣿⣷⠘⢿⣿⣦⡀ ⢸⢿⣿⣿⣄ ⣸⣿⣿⡇⣪⣿⡿⠿⣿⣷⡄ ", - " ⠙⠃ ⣼⣿⡟ ⠈⠻⣿⣿⣦⣌⡇⠻⣿⣿⣷⣿⣿⣿ ⣿⣿⡇ ⠛⠻⢷⣄ ", - " ⢻⣿⣿⣄ ⠈⠻⣿⣿⣿⣷⣿⣿⣿⣿⣿⡟ ⠫⢿⣿⡆ ", - " ⠻⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣀⣤⣾⡿⠃ ", - " " - } +g.dashboard_custom_section = { + a = {description = {" Find File SPC f f"}, command = "Telescope find_files"}, + b = {description = {" Recents SPC f o"}, command = "Telescope oldfiles"}, + c = {description = {" Find Word SPC f w"}, command = "Telescope live_grep"}, + d = {description = {"洛 New File SPC f n"}, command = "DashboardNewFile"}, + e = {description = {" Bookmarks SPC b m"}, command = "Telescope marks"}, + f = {description = {" Load Last Session SPC s l"}, command = "SessionLoad"} +} - g.dashboard_custom_section = { - a = {description = {" Find File SPC f f"}, command = "Telescope find_files"}, - b = {description = {" Recents SPC f o"}, command = "Telescope oldfiles"}, - c = {description = {" Find Word SPC f w"}, command = "Telescope live_grep"}, - d = {description = {"洛 New File SPC f n"}, command = "DashboardNewFile"}, - e = {description = {" Bookmarks SPC b m"}, command = "Telescope marks"}, - f = {description = {" Load Last Session SPC s l"}, command = "SessionLoad"} - } - - g.dashboard_custom_footer = { - " ", - -- "NvChad Loaded " .. plugins_count .. " plugins", - "NvChad v0.5" - } -end - -return M +g.dashboard_custom_footer = { + " ", + -- "NvChad Loaded " .. plugins_count .. " plugins", + "NvChad v0.5" +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua index 32c2c3c..d42758a 100644 --- a/lua/plugins/gitsigns.lua +++ b/lua/plugins/gitsigns.lua @@ -1,33 +1,38 @@ -local M = {} - -M.config = function() - require("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, - ["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()', - ["n hu"] = 'lua require"gitsigns".undo_stage_hunk()', - ["n hr"] = 'lua require"gitsigns".reset_hunk()', - ["n hp"] = 'lua require"gitsigns".preview_hunk()', - ["n hb"] = 'lua require"gitsigns".blame_line()' - }, - watch_index = { - interval = 100 - }, - sign_priority = 5, - status_formatter = nil -- Use default - } +local gitsigns +if + not pcall( + function() + gitsigns = require "gitsigns" + end + ) + then + return end -return M +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, + ["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()', + ["n hu"] = 'lua require"gitsigns".undo_stage_hunk()', + ["n hr"] = 'lua require"gitsigns".reset_hunk()', + ["n hp"] = 'lua require"gitsigns".preview_hunk()', + ["n hb"] = 'lua require"gitsigns".blame_line()' + }, + watch_index = { + interval = 100 + }, + sign_priority = 5, + status_formatter = nil -- Use default +} diff --git a/lua/plugins/icons.lua b/lua/plugins/icons.lua index 90d8e32..03e5f59 100644 --- a/lua/plugins/icons.lua +++ b/lua/plugins/icons.lua @@ -1,123 +1,128 @@ -local M = {} - -M.config = function() - local global_theme = "themes/" .. vim.g.nvchad_theme - local colors = require(global_theme) - - require "nvim-web-devicons".setup { - override = { - html = { - icon = "", - color = colors.baby_pink, - name = "html" - }, - css = { - icon = "", - color = colors.blue, - name = "css" - }, - js = { - icon = "", - color = colors.sun, - name = "js" - }, - ts = { - icon = "ﯤ", - color = colors.teal, - name = "ts" - }, - kt = { - icon = "󱈙", - color = colors.orange, - name = "kt" - }, - png = { - icon = "", - color = colors.dark_purple, - name = "png" - }, - jpg = { - icon = "", - color = colors.dark_purple, - name = "jpg" - }, - jpeg = { - icon = "", - color = colors.dark_purple, - name = "jpeg" - }, - mp3 = { - icon = "", - color = colors.white, - name = "mp3" - }, - mp4 = { - icon = "", - color = colors.white, - name = "mp4" - }, - out = { - icon = "", - 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" - }, - py = { - icon = "", - color = colors.cyan, - name = "py" - }, - toml = { - icon = "", - color = colors.blue, - name = "toml" - }, - lock = { - icon = "", - color = colors.red, - name = "lock" - }, - zip = { - icon = "", - color = colors.sun, - name = "zip" - }, - xz = { - icon = "", - color = colors.sun, - name = "xz" - }, - deb = { - icon = "", - color = colors.cyan, - name = "deb" - }, - rpm = { - icon = "", - color = colors.orange, - name = "rpm" - }, - lua = { - icon = "", - color = colors.blue, - name = "lua" - } - } - } +local icons +if + not pcall( + function() + icons = require "nvim-web-devicons" + end + ) + then + return end -return M +local global_theme = "themes/" .. vim.g.nvchad_theme +local colors = require(global_theme) + +icons.setup { + override = { + html = { + icon = "", + color = colors.baby_pink, + name = "html" + }, + css = { + icon = "", + color = colors.blue, + name = "css" + }, + js = { + icon = "", + color = colors.sun, + name = "js" + }, + ts = { + icon = "ﯤ", + color = colors.teal, + name = "ts" + }, + kt = { + icon = "󱈙", + color = colors.orange, + name = "kt" + }, + png = { + icon = "", + color = colors.dark_purple, + name = "png" + }, + jpg = { + icon = "", + color = colors.dark_purple, + name = "jpg" + }, + jpeg = { + icon = "", + color = colors.dark_purple, + name = "jpeg" + }, + mp3 = { + icon = "", + color = colors.white, + name = "mp3" + }, + mp4 = { + icon = "", + color = colors.white, + name = "mp4" + }, + out = { + icon = "", + 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" + }, + py = { + icon = "", + color = colors.cyan, + name = "py" + }, + toml = { + icon = "", + color = colors.blue, + name = "toml" + }, + lock = { + icon = "", + color = colors.red, + name = "lock" + }, + zip = { + icon = "", + color = colors.sun, + name = "zip" + }, + xz = { + icon = "", + color = colors.sun, + name = "xz" + }, + deb = { + icon = "", + color = colors.cyan, + name = "deb" + }, + rpm = { + icon = "", + color = colors.orange, + name = "rpm" + }, + lua = { + icon = "", + color = colors.blue, + name = "lua" + } + } +} diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index a8dcc12..58681ee 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -1,98 +1,102 @@ -local M = {} - -M.config = function() - local lspconf = require("lspconfig") - - local function on_attach(client, bufnr) - vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") - - local opts = {noremap = true, silent = true} - - local function buf_set_keymap(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) +local lspconfig, lspinstall +if + not pcall( + function() + lspconfig = require "lspconfig" + lspinstall = require "lspinstall" end + ) + then + return +end - -- Mappings. +local function on_attach(client, bufnr) + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") - buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) - buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) - buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) - buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) - buf_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) - buf_set_keymap("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) - buf_set_keymap("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) - buf_set_keymap("n", "wl", "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) - buf_set_keymap("n", "D", "lua vim.lsp.buf.type_definition()", opts) - buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) - buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) - buf_set_keymap("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) - buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) - buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) - buf_set_keymap("n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) + local opts = {noremap = true, silent = true} - -- Set some keybinds conditional on server capabilities - if client.resolved_capabilities.document_formatting then - buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) - elseif client.resolved_capabilities.document_range_formatting then - buf_set_keymap("n", "f", "lua vim.lsp.buf.range_formatting()", opts) - end + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) end - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities.textDocument.completion.completionItem.snippetSupport = true + -- Mappings. - -- lspInstall + lspconfig stuff + buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) + buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) + buf_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) + buf_set_keymap("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) + buf_set_keymap("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) + buf_set_keymap("n", "wl", "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) + buf_set_keymap("n", "D", "lua vim.lsp.buf.type_definition()", opts) + buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) + buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) + buf_set_keymap("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) + buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) + buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) + buf_set_keymap("n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) - local function setup_servers() - require "lspinstall".setup() - local servers = require "lspinstall".installed_servers() + -- Set some keybinds conditional on server capabilities + if client.resolved_capabilities.document_formatting then + buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) + elseif client.resolved_capabilities.document_range_formatting then + buf_set_keymap("n", "f", "lua vim.lsp.buf.range_formatting()", opts) + end +end - for _, lang in pairs(servers) do - if lang ~= "lua" then - lspconf[lang].setup { - on_attach = on_attach, - capabilities = capabilities, - root_dir = vim.loop.cwd - } - elseif lang == "lua" then - lspconf[lang].setup { - root_dir = vim.loop.cwd, - settings = { - Lua = { - diagnostics = { - globals = {"vim"} +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true + +-- lspInstall + lspconfig stuff + +local function setup_servers() + lspinstall.setup() + local servers = lspinstall.installed_servers() + + for _, lang in pairs(servers) do + if lang ~= "lua" then + lspconfig[lang].setup { + on_attach = on_attach, + capabilities = capabilities, + root_dir = vim.loop.cwd + } + elseif lang == "lua" then + lspconfig[lang].setup { + root_dir = vim.loop.cwd, + settings = { + Lua = { + diagnostics = { + globals = {"vim"} + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true }, - workspace = { - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true - }, - maxPreload = 100000, - preloadFileSize = 10000 - }, - telemetry = { - enable = false - } + maxPreload = 100000, + preloadFileSize = 10000 + }, + telemetry = { + enable = false } } } - end + } end end - - setup_servers() - - -- Automatically reload after `:LspInstall ` so we don't have to restart neovim - require "lspinstall".post_install_hook = function() - setup_servers() -- reload installed servers - vim.cmd("bufdo e") -- triggers FileType autocmd that starts the server - end - - -- replace the default lsp diagnostic letters with prettier symbols - vim.fn.sign_define("LspDiagnosticsSignError", {text = "", numhl = "LspDiagnosticsDefaultError"}) - vim.fn.sign_define("LspDiagnosticsSignWarning", {text = "", numhl = "LspDiagnosticsDefaultWarning"}) - vim.fn.sign_define("LspDiagnosticsSignInformation", {text = "", numhl = "LspDiagnosticsDefaultInformation"}) - vim.fn.sign_define("LspDiagnosticsSignHint", {text = "", numhl = "LspDiagnosticsDefaultHint"}) end -return M +setup_servers() + +-- Automatically reload after `:LspInstall ` so we don't have to restart neovim +lspinstall.post_install_hook = function() + setup_servers() -- reload installed servers + vim.cmd("bufdo e") -- triggers FileType autocmd that starts the server +end + +-- replace the default lsp diagnostic letters with prettier symbols +vim.fn.sign_define("LspDiagnosticsSignError", {text = "", numhl = "LspDiagnosticsDefaultError"}) +vim.fn.sign_define("LspDiagnosticsSignWarning", {text = "", numhl = "LspDiagnosticsDefaultWarning"}) +vim.fn.sign_define("LspDiagnosticsSignInformation", {text = "", numhl = "LspDiagnosticsDefaultInformation"}) +vim.fn.sign_define("LspDiagnosticsSignHint", {text = "", numhl = "LspDiagnosticsDefaultHint"}) diff --git a/lua/plugins/lspkind.lua b/lua/plugins/lspkind.lua new file mode 100644 index 0000000..f9159d6 --- /dev/null +++ b/lua/plugins/lspkind.lua @@ -0,0 +1,5 @@ +pcall( + function() + require("lspkind").init() + end +) diff --git a/lua/plugins/luasnip.lua b/lua/plugins/luasnip.lua new file mode 100644 index 0000000..825c957 --- /dev/null +++ b/lua/plugins/luasnip.lua @@ -0,0 +1,18 @@ +local luasnip +if + not pcall( + function() + luasnip = require "luasnip" + end + ) + then + return +end + +luasnip.config.set_config( + { + history = true, + updateevents = "TextChanged,TextChangedI" + } +) +require("luasnip/loaders/from_vscode").load() diff --git a/lua/plugins/neoscroll.lua b/lua/plugins/neoscroll.lua new file mode 100644 index 0000000..bc95671 --- /dev/null +++ b/lua/plugins/neoscroll.lua @@ -0,0 +1,5 @@ +pcall( + function() + require("neoscroll").setup() + end +) diff --git a/lua/plugins/nvimtree.lua b/lua/plugins/nvimtree.lua index a866cb6..8450b88 100644 --- a/lua/plugins/nvimtree.lua +++ b/lua/plugins/nvimtree.lua @@ -1,97 +1,100 @@ -local M = {} - -M.config = function() - 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_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 = ":t" - 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_hijack_netrw = 0 - g.nvim_tree_update_cwd = 1 - - g.nvim_tree_show_icons = { - git = 1, - folders = 1, - files = 1 - -- folder_arrows= 1 - } - g.nvim_tree_icons = { - default = "", - symlink = "", - git = { - unstaged = "✗", - staged = "✓", - unmerged = "", - renamed = "➜", - untracked = "★", - deleted = "", - ignored = "◌" - }, - 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 = "", - symlink = "", - symlink_open = "" - } - } - - local tree_cb = require "nvim-tree.config".nvim_tree_callback - - g.nvim_tree_bindings = { - {key = {"", "o", "<2-LeftMouse>"}, cb = tree_cb("edit")}, - {key = {"<2-RightMouse>", ""}, cb = tree_cb("cd")}, - {key = "", cb = tree_cb("vsplit")}, - {key = "", cb = tree_cb("split")}, - {key = "", cb = tree_cb("tabnew")}, - {key = "<", cb = tree_cb("prev_sibling")}, - {key = ">", cb = tree_cb("next_sibling")}, - {key = "P", cb = tree_cb("parent_node")}, - {key = "", cb = tree_cb("close_node")}, - {key = "", cb = tree_cb("close_node")}, - {key = "", cb = tree_cb("preview")}, - {key = "K", cb = tree_cb("first_sibling")}, - {key = "J", cb = tree_cb("last_sibling")}, - {key = "I", cb = tree_cb("toggle_ignored")}, - {key = "H", cb = tree_cb("toggle_dotfiles")}, - {key = "R", cb = tree_cb("refresh")}, - {key = "a", cb = tree_cb("create")}, - {key = "d", cb = tree_cb("remove")}, - {key = "r", cb = tree_cb("rename")}, - {key = "", cb = tree_cb("full_rename")}, - {key = "x", cb = tree_cb("cut")}, - {key = "c", cb = tree_cb("copy")}, - {key = "p", cb = tree_cb("paste")}, - {key = "y", cb = tree_cb("copy_name")}, - {key = "Y", cb = tree_cb("copy_path")}, - {key = "gy", cb = tree_cb("copy_absolute_path")}, - {key = "[c", cb = tree_cb("prev_git_item")}, - {key = "}c", cb = tree_cb("next_git_item")}, - {key = "-", cb = tree_cb("dir_up")}, - {key = "q", cb = tree_cb("close")}, - {key = "g?", cb = tree_cb("toggle_help")} - } +local tree_cb +if + not pcall( + function() + tree_cb = require "nvim-tree.config".nvim_tree_callback + end + ) + then + return end -return M +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_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 = ":t" +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_hijack_netrw = 0 +g.nvim_tree_update_cwd = 1 + +g.nvim_tree_show_icons = { + git = 1, + folders = 1, + files = 1 + -- folder_arrows= 1 +} +g.nvim_tree_icons = { + default = "", + symlink = "", + git = { + unstaged = "✗", + staged = "✓", + unmerged = "", + renamed = "➜", + untracked = "★", + deleted = "", + ignored = "◌" + }, + 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 = "", + symlink = "", + symlink_open = "" + } +} + +g.nvim_tree_bindings = { + {key = {"", "o", "<2-LeftMouse>"}, cb = tree_cb("edit")}, + {key = {"<2-RightMouse>", ""}, cb = tree_cb("cd")}, + {key = "", cb = tree_cb("vsplit")}, + {key = "", cb = tree_cb("split")}, + {key = "", cb = tree_cb("tabnew")}, + {key = "<", cb = tree_cb("prev_sibling")}, + {key = ">", cb = tree_cb("next_sibling")}, + {key = "P", cb = tree_cb("parent_node")}, + {key = "", cb = tree_cb("close_node")}, + {key = "", cb = tree_cb("close_node")}, + {key = "", cb = tree_cb("preview")}, + {key = "K", cb = tree_cb("first_sibling")}, + {key = "J", cb = tree_cb("last_sibling")}, + {key = "I", cb = tree_cb("toggle_ignored")}, + {key = "H", cb = tree_cb("toggle_dotfiles")}, + {key = "R", cb = tree_cb("refresh")}, + {key = "a", cb = tree_cb("create")}, + {key = "d", cb = tree_cb("remove")}, + {key = "r", cb = tree_cb("rename")}, + {key = "", cb = tree_cb("full_rename")}, + {key = "x", cb = tree_cb("cut")}, + {key = "c", cb = tree_cb("copy")}, + {key = "p", cb = tree_cb("paste")}, + {key = "y", cb = tree_cb("copy_name")}, + {key = "Y", cb = tree_cb("copy_path")}, + {key = "gy", cb = tree_cb("copy_absolute_path")}, + {key = "[c", cb = tree_cb("prev_git_item")}, + {key = "}c", cb = tree_cb("next_git_item")}, + {key = "-", cb = tree_cb("dir_up")}, + {key = "q", cb = tree_cb("close")}, + {key = "g?", cb = tree_cb("toggle_help")} +} diff --git a/lua/plugins/statusline.lua b/lua/plugins/statusline.lua index eb675d5..b49cdaf 100644 --- a/lua/plugins/statusline.lua +++ b/lua/plugins/statusline.lua @@ -1,212 +1,217 @@ -local M = {} - -M.config = function() - local gl = require("galaxyline") - local gls = gl.section - local condition = require("galaxyline.condition") - - gl.short_line_list = {" "} - - local global_theme = "themes/" .. vim.g.nvchad_theme - local colors = require(global_theme) - - gls.left[1] = { - FirstElement = { - provider = function() - return "▋" - end, - highlight = {colors.nord_blue, colors.nord_blue} - } - } - - gls.left[2] = { - statusIcon = { - provider = function() - return "  " - end, - highlight = {colors.statusline_bg, colors.nord_blue}, - separator = " ", - separator_highlight = {colors.nord_blue, colors.lightbg} - } - } - - gls.left[3] = { - FileIcon = { - provider = "FileIcon", - condition = condition.buffer_not_empty, - highlight = {colors.white, colors.lightbg} - } - } - - gls.left[4] = { - FileName = { - provider = {"FileName"}, - condition = condition.buffer_not_empty, - highlight = {colors.white, colors.lightbg}, - separator = " ", - separator_highlight = {colors.lightbg, colors.lightbg2} - } - } - - gls.left[5] = { - current_dir = { - provider = function() - local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t") - return "  " .. dir_name .. " " - end, - highlight = {colors.grey_fg2, colors.lightbg2}, - separator = " ", - separator_highlight = {colors.lightbg2, colors.statusline_bg} - } - } - - local checkwidth = function() - local squeeze_width = vim.fn.winwidth(0) / 2 - if squeeze_width > 30 then - return true +local gl, condition +if + not pcall( + function() + gl = require "galaxyline" + condition = require "galaxyline.condition" end - return false - end - - gls.left[6] = { - DiffAdd = { - provider = "DiffAdd", - condition = checkwidth, - icon = "  ", - highlight = {colors.white, colors.statusline_bg} - } - } - - gls.left[7] = { - DiffModified = { - provider = "DiffModified", - condition = checkwidth, - icon = "  ", - highlight = {colors.grey_fg2, colors.statusline_bg} - } - } - - gls.left[8] = { - DiffRemove = { - provider = "DiffRemove", - condition = checkwidth, - icon = "  ", - highlight = {colors.grey_fg2, colors.statusline_bg} - } - } - - gls.left[9] = { - DiagnosticError = { - provider = "DiagnosticError", - icon = "  ", - highlight = {colors.red, colors.statusline_bg} - } - } - - gls.left[10] = { - DiagnosticWarn = { - provider = "DiagnosticWarn", - icon = "  ", - highlight = {colors.yellow, colors.statusline_bg} - } - } - - gls.right[1] = { - lsp_status = { - provider = function() - local clients = vim.lsp.get_active_clients() - if next(clients) ~= nil then - return " " .. "  " .. " LSP " - else - return "" - end - end, - highlight = {colors.grey_fg2, colors.statusline_bg} - } - } - - gls.right[2] = { - GitIcon = { - provider = function() - return " " - end, - condition = require("galaxyline.condition").check_git_workspace, - highlight = {colors.grey_fg2, colors.statusline_bg}, - separator = " ", - separator_highlight = {colors.statusline_bg, colors.statusline_bg} - } - } - - gls.right[3] = { - GitBranch = { - provider = "GitBranch", - condition = require("galaxyline.condition").check_git_workspace, - highlight = {colors.grey_fg2, colors.statusline_bg} - } - } - - gls.right[4] = { - viMode_icon = { - provider = function() - return " " - end, - highlight = {colors.statusline_bg, colors.red}, - separator = " ", - separator_highlight = {colors.red, colors.statusline_bg} - } - } - - gls.right[5] = { - ViMode = { - provider = function() - local alias = { - n = "Normal", - i = "Insert", - c = "Command", - V = "Visual", - [""] = "Visual", - v = "Visual", - R = "Replace" - } - local current_Mode = alias[vim.fn.mode()] - - if current_Mode == nil then - return " Terminal " - else - return " " .. current_Mode .. " " - end - end, - highlight = {colors.red, colors.lightbg} - } - } - - gls.right[6] = { - some_icon = { - provider = function() - return " " - end, - separator = "", - separator_highlight = {colors.green, colors.lightbg}, - highlight = {colors.lightbg, colors.green} - } - } - - gls.right[7] = { - line_percentage = { - provider = function() - local current_line = vim.fn.line(".") - local total_line = vim.fn.line("$") - - if current_line == 1 then - return " Top " - elseif current_line == vim.fn.line("$") then - return " Bot " - end - local result, _ = math.modf((current_line / total_line) * 100) - return " " .. result .. "% " - end, - highlight = {colors.green, colors.lightbg} - } - } + ) + then + return end -return M + +local gls = gl.section + +gl.short_line_list = {" "} + +local global_theme = "themes/" .. vim.g.nvchad_theme +local colors = require(global_theme) + +gls.left[1] = { + FirstElement = { + provider = function() + return "▋" + end, + highlight = {colors.nord_blue, colors.nord_blue} + } +} + +gls.left[2] = { + statusIcon = { + provider = function() + return "  " + end, + highlight = {colors.statusline_bg, colors.nord_blue}, + separator = " ", + separator_highlight = {colors.nord_blue, colors.lightbg} + } +} + +gls.left[3] = { + FileIcon = { + provider = "FileIcon", + condition = condition.buffer_not_empty, + highlight = {colors.white, colors.lightbg} + } +} + +gls.left[4] = { + FileName = { + provider = {"FileName"}, + condition = condition.buffer_not_empty, + highlight = {colors.white, colors.lightbg}, + separator = " ", + separator_highlight = {colors.lightbg, colors.lightbg2} + } +} + +gls.left[5] = { + current_dir = { + provider = function() + local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t") + return "  " .. dir_name .. " " + end, + highlight = {colors.grey_fg2, colors.lightbg2}, + separator = " ", + separator_highlight = {colors.lightbg2, colors.statusline_bg} + } +} + +local checkwidth = function() + local squeeze_width = vim.fn.winwidth(0) / 2 + if squeeze_width > 30 then + return true + end + return false +end + +gls.left[6] = { + DiffAdd = { + provider = "DiffAdd", + condition = checkwidth, + icon = "  ", + highlight = {colors.white, colors.statusline_bg} + } +} + +gls.left[7] = { + DiffModified = { + provider = "DiffModified", + condition = checkwidth, + icon = "  ", + highlight = {colors.grey_fg2, colors.statusline_bg} + } +} + +gls.left[8] = { + DiffRemove = { + provider = "DiffRemove", + condition = checkwidth, + icon = "  ", + highlight = {colors.grey_fg2, colors.statusline_bg} + } +} + +gls.left[9] = { + DiagnosticError = { + provider = "DiagnosticError", + icon = "  ", + highlight = {colors.red, colors.statusline_bg} + } +} + +gls.left[10] = { + DiagnosticWarn = { + provider = "DiagnosticWarn", + icon = "  ", + highlight = {colors.yellow, colors.statusline_bg} + } +} + +gls.right[1] = { + lsp_status = { + provider = function() + local clients = vim.lsp.get_active_clients() + if next(clients) ~= nil then + return " " .. "  " .. " LSP " + else + return "" + end + end, + highlight = {colors.grey_fg2, colors.statusline_bg} + } +} + +gls.right[2] = { + GitIcon = { + provider = function() + return " " + end, + condition = require("galaxyline.condition").check_git_workspace, + highlight = {colors.grey_fg2, colors.statusline_bg}, + separator = " ", + separator_highlight = {colors.statusline_bg, colors.statusline_bg} + } +} + +gls.right[3] = { + GitBranch = { + provider = "GitBranch", + condition = require("galaxyline.condition").check_git_workspace, + highlight = {colors.grey_fg2, colors.statusline_bg} + } +} + +gls.right[4] = { + viMode_icon = { + provider = function() + return " " + end, + highlight = {colors.statusline_bg, colors.red}, + separator = " ", + separator_highlight = {colors.red, colors.statusline_bg} + } +} + +gls.right[5] = { + ViMode = { + provider = function() + local alias = { + n = "Normal", + i = "Insert", + c = "Command", + V = "Visual", + [""] = "Visual", + v = "Visual", + R = "Replace" + } + local current_Mode = alias[vim.fn.mode()] + + if current_Mode == nil then + return " Terminal " + else + return " " .. current_Mode .. " " + end + end, + highlight = {colors.red, colors.lightbg} + } +} + +gls.right[6] = { + some_icon = { + provider = function() + return " " + end, + separator = "", + separator_highlight = {colors.green, colors.lightbg}, + highlight = {colors.lightbg, colors.green} + } +} + +gls.right[7] = { + line_percentage = { + provider = function() + local current_line = vim.fn.line(".") + local total_line = vim.fn.line("$") + + if current_line == 1 then + return " Top " + elseif current_line == vim.fn.line("$") then + return " Bot " + end + local result, _ = math.modf((current_line / total_line) * 100) + return " " .. result .. "% " + end, + highlight = {colors.green, colors.lightbg} + } +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 151733b..4fea957 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -1,7 +1,16 @@ -local M = {} +local telescope +if + not pcall( + function() + telescope = require("telescope") + end + ) + then + return +end -M.config = function() - require("telescope").setup { +telescope.setup( + { defaults = { vimgrep_arguments = { "rg", @@ -32,9 +41,9 @@ M.config = function() height = 0.80, preview_cutoff = 120 }, - file_sorter = require "telescope.sorters".get_fuzzy_file, + file_sorter = require("telescope.sorters").get_fuzzy_file, file_ignore_patterns = {}, - generic_sorter = require "telescope.sorters".get_generic_fuzzy_sorter, + generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, path_display = shorten, winblend = 0, border = {}, @@ -42,11 +51,11 @@ M.config = function() color_devicons = true, use_less = true, set_env = {["COLORTERM"] = "truecolor"}, -- default = nil, - file_previewer = require "telescope.previewers".vim_buffer_cat.new, - grep_previewer = require "telescope.previewers".vim_buffer_vimgrep.new, - qflist_previewer = require "telescope.previewers".vim_buffer_qflist.new, + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, -- Developer configurations: Not meant for general override - buffer_previewer_maker = require "telescope.previewers".buffer_previewer_maker + buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker }, extensions = { fzf = { @@ -62,9 +71,16 @@ M.config = function() } } } +) - require("telescope").load_extension("fzf") - require("telescope").load_extension("media_files") +if + not pcall( + function() + telescope.load_extension("fzf") + telescope.load_extension("media_files") + end + ) + then + -- This should only trigger when in need of PackerSync, so better do it + vim.cmd("PackerSync") end - -return M diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index 234f490..c47b5a7 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -1,25 +1,28 @@ -local M = {} - -M.config = function() - local ts_config = require("nvim-treesitter.configs") - - ts_config.setup { - ensure_installed = { - "javascript", - "html", - "css", - "bash", - "lua", - "json", - "python" - -- "rust", - -- "go" - }, - highlight = { - enable = true, - use_languagetree = true - } - } +local ts_config +if + not pcall( + function() + ts_config = require "nvim-treesitter.configs" + end + ) + then + return end -return M +ts_config.setup { + ensure_installed = { + "javascript", + "html", + "css", + "bash", + "lua", + "json", + "python" + -- "rust", + -- "go" + }, + highlight = { + enable = true, + use_languagetree = true + } +} diff --git a/lua/plugins/zenmode.lua b/lua/plugins/zenmode.lua index eb8455c..4d99b98 100644 --- a/lua/plugins/zenmode.lua +++ b/lua/plugins/zenmode.lua @@ -1,81 +1,63 @@ -- plugins made by @Pocco81 =) -local M = {} +local true_zen +if + not pcall( + function() + true_zen = require "true-zen" + end + ) + then + return +end -M.config = function() - local true_zen = require("true-zen") - - true_zen.setup( - { - misc = { - on_off_commands = false, - ui_elements_commands = false, - cursor_by_mode = false, - before_minimalist_mode_shown = true, - before_minimalist_mode_hidden = true, - after_minimalist_mode_shown = true, - after_minimalist_mode_hidden = true +true_zen.setup( + { + misc = { + on_off_commands = false, + ui_elements_commands = false, + cursor_by_mode = false, + before_minimalist_mode_shown = true, + before_minimalist_mode_hidden = true, + after_minimalist_mode_shown = true, + after_minimalist_mode_hidden = true + }, + ui = { + bottom = { + laststatus = 0, + ruler = false, + showmode = false, + showcmd = false, + cmdheight = 1 }, - ui = { - bottom = { - laststatus = 0, - ruler = false, - showmode = false, - showcmd = false, - cmdheight = 1 - }, - top = { - showtabline = 0 - }, - left = { - number = false, - relativenumber = false, - signcolumn = "no" - } + top = { + showtabline = 0 }, - modes = { - ataraxis = { - left_padding = 37, - right_padding = 37, - top_padding = 2, - bottom_padding = 2, - just_do_it_for_me = false, - ideal_writing_area_width = 0, - keep_default_fold_fillchars = true, - custome_bg = "#1e222a" - }, - focus = { - margin_of_error = 5, - focus_method = "experimental" - } - }, - integrations = { - galaxyline = true, - nvim_bufferline = true + left = { + number = false, + relativenumber = false, + signcolumn = "no" } - } - ) -end - --- autosave.nvim plugin disabled by default -M.autoSave = function() - local autosave = require("autosave") - - autosave.setup( - { - enabled = vim.g.auto_save, -- takes boolean value from init.lua - execution_message = "autosaved at : " .. vim.fn.strftime("%H:%M:%S"), - events = {"InsertLeave", "TextChanged"}, - conditions = { - exists = true, - filetype_is_not = {}, - modifiable = true + }, + modes = { + ataraxis = { + left_padding = 37, + right_padding = 37, + top_padding = 2, + bottom_padding = 2, + just_do_it_for_me = false, + ideal_writing_area_width = 0, + keep_default_fold_fillchars = true, + custome_bg = "#1e222a" }, - write_all_buffers = true, - on_off_commands = true, - clean_command_line_interval = 2500 + focus = { + margin_of_error = 5, + focus_method = "experimental" + } + }, + integrations = { + galaxyline = true, + nvim_bufferline = true } - ) -end - -return M + } +) From 3e83ec53147241df3a559c52428ba1347ddd53ac Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Thu, 15 Jul 2021 21:16:45 +0530 Subject: [PATCH 4/7] [2/4] Refactor: plugins: Handle packer seperatly | Changes for configs eg: require "plugins.neoscroll" instead of require "plugins.neoscroll".config() second commit of refactor handle require errors handle cloning of packer --- lua/packerInit.lua | 45 ++++++++++++++++++++++++++++++ lua/pluginList.lua | 68 +++++++++++++++++++++------------------------- 2 files changed, 76 insertions(+), 37 deletions(-) create mode 100644 lua/packerInit.lua diff --git a/lua/packerInit.lua b/lua/packerInit.lua new file mode 100644 index 0000000..d6b6c93 --- /dev/null +++ b/lua/packerInit.lua @@ -0,0 +1,45 @@ +local packer +if + not pcall( + function() + packer = require "packer" + end + ) + then + local packer_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" + + print("Cloning packer..") + -- remove the dir before cloning + vim.fn.delete(packer_path, "rf") + vim.fn.system( + { + "git", + "clone", + "https://github.com/wbthomason/packer.nvim", + "--depth", + "20", + packer_path + } + ) + if pcall( + function() + packer = require "packer" + end + ) + then + print("Packer cloned successfully.") + else + error("Couldn't clone packer !\nPacker path: " .. packer_path) + end +end + +return packer.init { + display = { + open_fn = function() + return require("packer.util").float {border = "single"} + end + }, + git = { + clone_timeout = 600 -- Timeout, in seconds, for git clones + } +} diff --git a/lua/pluginList.lua b/lua/pluginList.lua index c881247..4289f02 100644 --- a/lua/pluginList.lua +++ b/lua/pluginList.lua @@ -1,16 +1,17 @@ -local packer = require("packer") -local use = packer.use - -packer.init { - display = { - open_fn = function() - return require("packer.util").float {border = "single"} +local packer +if + pcall( + function() + require "packerInit" end - }, - git = { - clone_timeout = 600 -- Timeout, in seconds, for git clones - } -} + ) + then + packer = require "packer" +else + return false +end + +local use = packer.use return packer.startup( function() @@ -21,7 +22,7 @@ return packer.startup( use { "glepnir/galaxyline.nvim", config = function() - require("plugins.statusline").config() + require "plugins.statusline" end } @@ -32,8 +33,7 @@ return packer.startup( "norcalli/nvim-colorizer.lua", event = "BufRead", config = function() - require("colorizer").setup() - vim.cmd("ColorizerReloadAllBuffers") + require "plugins.colorizer" end } @@ -42,7 +42,7 @@ return packer.startup( "nvim-treesitter/nvim-treesitter", event = "BufRead", config = function() - require("plugins.treesitter").config() + require "plugins.treesitter" end } @@ -55,7 +55,7 @@ return packer.startup( "neovim/nvim-lspconfig", after = "nvim-lspinstall", config = function() - require("plugins.lspconfig").config() + require "plugins.lspconfig" end } @@ -63,7 +63,7 @@ return packer.startup( "onsails/lspkind-nvim", event = "BufRead", config = function() - require("lspkind").init() + require "plugins.lspkind" end } @@ -72,7 +72,7 @@ return packer.startup( "hrsh7th/nvim-compe", event = "InsertEnter", config = function() - require("plugins.compe").config() + require "plugins.compe" end, wants = {"LuaSnip"}, requires = { @@ -81,7 +81,7 @@ return packer.startup( wants = "friendly-snippets", event = "InsertCharPre", config = function() - require("plugins.compe").snippets() + require "plugins.luasnip" end }, { @@ -98,14 +98,14 @@ return packer.startup( "kyazdani42/nvim-tree.lua", cmd = "NvimTreeToggle", config = function() - require("plugins.nvimtree").config() + require "plugins.nvimtree" end } use { "kyazdani42/nvim-web-devicons", config = function() - require("plugins.icons").config() + require "plugins.icons" end } @@ -117,7 +117,7 @@ return packer.startup( }, cmd = "Telescope", config = function() - require("plugins.telescope").config() + require "plugins.telescope" end } @@ -133,7 +133,7 @@ return packer.startup( "lewis6991/gitsigns.nvim", event = "BufRead", config = function() - require("plugins.gitsigns").config() + require "plugins.gitsigns" end } @@ -142,13 +142,7 @@ return packer.startup( "windwp/nvim-autopairs", after = "nvim-compe", config = function() - require("nvim-autopairs").setup() - require("nvim-autopairs.completion.compe").setup( - { - map_cr = true, - map_complete = true -- insert () func completion - } - ) + require "plugins.autopairs" end } @@ -158,7 +152,7 @@ return packer.startup( "terrortylor/nvim-comment", cmd = "CommentToggle", config = function() - require("nvim_comment").setup() + require "plugins.comment" end } @@ -172,7 +166,7 @@ return packer.startup( "SessionSave" }, setup = function() - require("plugins.dashboard").config() + require "plugins.dashboard" end } @@ -182,7 +176,7 @@ return packer.startup( use { "Pocco81/AutoSave.nvim", config = function() - require("plugins.zenmode").autoSave() + require "plugins.autosave" end, cond = function() return vim.g.auto_save == true @@ -194,7 +188,7 @@ return packer.startup( "karb94/neoscroll.nvim", event = "WinScrolled", config = function() - require("neoscroll").setup() + require "plugins.neoscroll" end } @@ -202,7 +196,7 @@ return packer.startup( "Pocco81/TrueZen.nvim", cmd = {"TZAtaraxis", "TZMinimalist", "TZFocus"}, config = function() - require("plugins.zenmode").config() + require "plugins.zenmode" end } @@ -212,7 +206,7 @@ return packer.startup( "lukas-reineke/indent-blankline.nvim", event = "BufRead", setup = function() - require("utils").blankline() + require "plugins.blankline" end } end From 643d1bd7d8f9fafebea05dbc0f85498d08088fe3 Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Thu, 15 Jul 2021 21:17:47 +0530 Subject: [PATCH 5/7] [3/4] Refactor: init: Use async | Move theme stuff to theme.lua third commit of refactor perf improvements due to async run packer sync if base16 not found this is not perfect error handling for initial run, but something handle require errors --- init.lua | 36 +++++++++++++++++++++++++----------- lua/mappings.lua | 12 +++++++++++- lua/theme.lua | 21 +++++++++++++++++++++ lua/utils.lua | 12 ------------ 4 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 lua/theme.lua diff --git a/init.lua b/init.lua index 58a90da..c9df36f 100644 --- a/init.lua +++ b/init.lua @@ -1,14 +1,28 @@ --- load all plugins -require "pluginList" +-- load all options require "options" --- colorscheme related stuff -vim.g.nvchad_theme = "onedark" -local base16 = require "base16" -base16(base16.themes["onedark"], true) +-- only try to load stuff if atleast base16 is initialized +-- TODO: Find a better way to trigger PackerSync +if require "theme" then + local async + async = + vim.loop.new_async( + vim.schedule_wrap( + function() + require "pluginList" + require "plugins.bufferline" + require "highlights" + require "mappings" + require("utils").hideStuff() -require "highlights" -require "mappings" -require "plugins.bufferline" - -require("utils").hideStuff() + async:close() + end + ) + ) + async:send() +else + -- otherwise run packer sync + require "pluginList" + print("Now PackerSync will be executed, after completion, restart neovim.\n") + vim.cmd("PackerSync") +end diff --git a/lua/mappings.lua b/lua/mappings.lua index cd1cd1a..c9ae584 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -76,7 +76,17 @@ _G.s_tab_complete = function() end function _G.completions() - local npairs = require("nvim-autopairs") + local npairs + if + not pcall( + function() + npairs = require "nvim-autopairs" + end + ) + then + return + end + if vim.fn.pumvisible() == 1 then if vim.fn.complete_info()["selected"] ~= -1 then return vim.fn["compe#confirm"]("") diff --git a/lua/theme.lua b/lua/theme.lua new file mode 100644 index 0000000..8727eaf --- /dev/null +++ b/lua/theme.lua @@ -0,0 +1,21 @@ +-- colorscheme related stuff +vim.g.nvchad_theme = "onedark" + +local base16 +if + not pcall( + function() + base16 = require "base16" + end + ) + then + return false +else + base16(base16.themes["onedark"], true) + local cmd = vim.cmd + + -- load bg color before async for smooth transition + local background = require("themes/" .. vim.g.nvchad_theme).black + vim.cmd("hi Normal guibg=" .. background) + return true +end diff --git a/lua/utils.lua b/lua/utils.lua index db5dea2..a06fa07 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -1,17 +1,5 @@ local M = {} --- blankline config -M.blankline = function() - vim.g.indentLine_enabled = 1 - vim.g.indent_blankline_char = "▏" - - vim.g.indent_blankline_filetype_exclude = {"help", "terminal", "dashboard"} - 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 - -- hide line numbers , statusline in specific buffers! M.hideStuff = function() vim.api.nvim_exec( From d1f23d1bc3b33988131099a77b55dd9f86a04e01 Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Fri, 16 Jul 2021 10:51:12 +0530 Subject: [PATCH 6/7] [4/4] Refactor: install.sh: Don't handle packer use +":lua require 'pluginList' vim.cmd('PackerSync')" only for update as PackerSync should trigger on fresh install automatically --- install.sh | 69 +++++++++++++++--------------------------------------- 1 file changed, 19 insertions(+), 50 deletions(-) diff --git a/install.sh b/install.sh index 3f3b9e1..3ae66ae 100755 --- a/install.sh +++ b/install.sh @@ -33,36 +33,6 @@ _check_nvim_version() { done } -_setup_packer() { - _clone_packer() { - [ -d "${_PACKER_PATH}" ] && rm -rf "${_PACKER_PATH}" - - printf "\n%s\n" "=> Cloning packer.." - if "${_GIT}" clone "${_PACKER_REPO_URL}" \ - "${_PACKER_PATH}" --depth 20; then - printf "%s\n" "=> Packer Installed!" - else - printf "Error: Couldn't clone packer\n" - exit 1 - fi - } - - if [ "${_UPDATE}" = "true" ]; then - printf "%s\n" "Updating packer" - { [ -d "${_PACKER_PATH}" ] \ - && "${_GIT}" -C "${_PACKER_PATH}" pull "${_PACKER_REPO_URL}"; } || _clone_packer - else - printf "%s\n" "Installing packer" - if [ -d ~/.local/share/nvim/site/pack/packer ]; then - printf "%s\n" "Clearing previous packer installs" - rm -rf ~/.local/share/nvim/site/pack - fi - _clone_packer - fi - printf "\n" - return 0 -} - _copy_config() { printf "%s\n" "Linking config" printf "%s\n" "Old nvim config will be changed to nvim.bak if exists! :0" @@ -124,8 +94,6 @@ _setup_terminal_shell() { _setup_arguments() { # default variables to be used - _PACKER_PATH="${HOME}/.local/share/nvim/site/pack/packer/start/packer.nvim" - _PACKER_REPO_URL="https://github.com/wbthomason/packer.nvim" _CONFIG_PATH="${HOME}/.config/nvim" _UPDATE="" _BACKUP_PATH="${_CONFIG_PATH}.bak" @@ -133,22 +101,22 @@ _setup_arguments() { _CURRENT_SHELL="${SHELL##*/}" _check_longoptions() { - [ -z "${2}" ] \ - && printf '%s: %s: option requires an argument\nTry '"%s -h/--help"' for more information.\n' "${0##*/}" "${1}" "${0##*/}" \ - && exit 1 + [ -z "${2}" ] && + printf '%s: %s: option requires an argument\nTry '"%s -h/--help"' for more information.\n' "${0##*/}" "${1}" "${0##*/}" && + exit 1 return 0 } while [ $# -gt 0 ]; do case "${1}" in - -h | --help) _usage ;; - -i | --install) _UPDATE="false" ;; - -u | --update) _UPDATE="true" ;; - -b | --backup) - _check_longoptions "${1}" "${2}" - _BACKUP_PATH="${2}" && shift - ;; - -nb | --nobackup) _NO_BACKUP="true" ;; + -h | --help) _usage ;; + -i | --install) _UPDATE="false" ;; + -u | --update) _UPDATE="true" ;; + -b | --backup) + _check_longoptions "${1}" "${2}" + _BACKUP_PATH="${2}" && shift + ;; + -nb | --nobackup) _NO_BACKUP="true" ;; esac shift done @@ -178,22 +146,23 @@ main() { _check_install_dependencies _setup_arguments "${@}" - _setup_packer _copy_config _setup_terminal_shell # install all plugins + compile them if _NVIM="$(command -v nvim)"; then if _check_nvim_version; then - printf "\n%s\n" "=> Neovim will open with some errors, just press enter" && sleep 1 - "${_NVIM}" +PackerSync + printf "\n%s\n" "=> Neovim will now open." && sleep 1 + if [ "${_UPDATE}" = "false" ]; then + "${_NVIM}" +":lua require 'pluginList' vim.cmd('PackerSync')" + else + "${_NVIM}" + fi else - printf "Error: Neovim is installed, but version is lower than 0.5.x, install Neovim >= 5.x and then run the below command.\n" - printf " nvim +PackerSync\n" + printf "Error: Neovim is installed, but version is lower than 0.5.x, install Neovim >= 5.x and then run nvim & do :PackerSync\n." fi else - printf "Error: Neovim is not installed, install Neovim >= 5.x and then run the below command\n" - printf " nvim +PackerSync\n" + printf "Error: Neovim is not installed, install Neovim >= 5.x and then run neovim & do :PackerSync.\n" fi } From 35b210b46adb6cf2ac9aa58d69df66c4dc266f5d Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Fri, 16 Jul 2021 10:54:04 +0530 Subject: [PATCH 7/7] install.sh: Don't ask for terminal shell when updating | Misc Handle a edgecase for config copying Remove an unnecessary print --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 3ae66ae..fbb0bf1 100755 --- a/install.sh +++ b/install.sh @@ -42,6 +42,7 @@ _copy_config() { printf "%s\n" "Nvim Directory exists" if [ "${_NO_BACKUP}" = "true" ]; then printf "%s\n" "Skipping backup as --no-backup flag was passed.." + [ "${_UPDATE}" = "false" ] && rm -rf "${_CONFIG_PATH}" else printf "%s\n" "Taking backup of existing config.." mv "${_CONFIG_PATH}" "${_BACKUP_PATH}" || { @@ -50,7 +51,6 @@ _copy_config() { exit 1 } fi - printf "%s\n" "Creating new nvim directory" else printf "%s\n" "Nvim Config doesn't exist so creating one" fi @@ -147,7 +147,7 @@ main() { _setup_arguments "${@}" _copy_config - _setup_terminal_shell + [ "${_UPDATE}" = "false" ] && _setup_terminal_shell # install all plugins + compile them if _NVIM="$(command -v nvim)"; then