From 29ab09bed9a9fa89b6d6a7d98d93e1921a8f65e7 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Thu, 11 May 2023 17:31:02 +0300 Subject: [PATCH] refactor config structure --- after/plugin/telescope-theme.lua | 22 ++ init.lua | 40 +--- lua/bindings.lua | 2 +- lua/config/autosource.lua | 10 +- lua/config/baleia.lua | 14 +- lua/config/based.lua | 11 +- lua/config/cellular-automaton.lua | 46 ---- lua/config/colorizer.lua | 34 +-- lua/config/comment.lua | 24 +- lua/config/devicons.lua | 6 + lua/config/dressing.lua | 26 ++ lua/config/fugitive.lua | 9 +- lua/config/gitblame.lua | 17 +- lua/config/gitsigns.lua | 60 ++--- lua/config/leap.lua | 11 +- lua/config/legendary.lua | 13 + lua/config/lspinstaller.lua | 13 +- lua/config/lspsignature.lua | 11 +- lua/config/lsputils.lua | 55 +---- lua/config/lualine.lua | 144 +++++------ lua/config/luapad.lua | 2 +- lua/config/luasnip.lua | 173 ++++++------- lua/config/move.lua | 27 ++- lua/config/nvim-tree.lua | 26 +- lua/config/quickscope.lua | 16 +- lua/config/telescope.lua | 141 ++++++----- lua/config/tidy.lua | 6 + lua/config/todo-comments.lua | 7 + lua/config/toggleterm.lua | 10 +- lua/config/treesitter.lua | 14 +- lua/config/trouble.lua | 18 +- lua/config/ts-playground.lua | 5 + lua/disable-builtin.lua | 11 + lua/{ => personal}/add-guard.lua | 0 lua/{ => personal}/cmacro-align.lua | 0 lua/pludin-dev.lua | 3 +- lua/plugin-manager.lua | 88 +++++++ lua/plugins-local.lua | 2 + lua/plugins.lua | 360 +++++++--------------------- 39 files changed, 738 insertions(+), 739 deletions(-) create mode 100644 after/plugin/telescope-theme.lua delete mode 100644 lua/config/cellular-automaton.lua create mode 100644 lua/config/devicons.lua create mode 100644 lua/config/dressing.lua create mode 100644 lua/config/legendary.lua create mode 100644 lua/config/tidy.lua create mode 100644 lua/config/todo-comments.lua create mode 100644 lua/config/ts-playground.lua create mode 100644 lua/disable-builtin.lua rename lua/{ => personal}/add-guard.lua (100%) rename lua/{ => personal}/cmacro-align.lua (100%) create mode 100644 lua/plugin-manager.lua create mode 100644 lua/plugins-local.lua diff --git a/after/plugin/telescope-theme.lua b/after/plugin/telescope-theme.lua new file mode 100644 index 0000000..c71df0c --- /dev/null +++ b/after/plugin/telescope-theme.lua @@ -0,0 +1,22 @@ +if vim.g.colors_name == "srcery" then + local bright_white = vim.api.nvim_get_hl_by_name("SrceryBrightWhite", true).foreground + local hard_black = vim.api.nvim_get_hl_by_name("SrceryHardBlack", true).foreground + local red = vim.api.nvim_get_hl_by_name("SrceryRed", true).foreground + local yellow = vim.api.nvim_get_hl_by_name("SrceryYellow", true).foreground + local gray1 = vim.api.nvim_get_hl_by_name("SrceryXgray1", true).foreground + + local TelescopePrompt = { + TelescopeBorder = {bg = hard_black, fg = hard_black}, + TelescopePromptBorder = {bg = gray1, fg = gray1}, + TelescopePromptNormal = {bg = gray1}, + TelescopePromptTitle = {fg = hard_black, bg = red }, + TelescopePreviewTitle = {fg = hard_black, bg = yellow }, + TelescopeNormal = {bg = hard_black, fg = bright_white}, + TelescopeResultsNormal = {bg = hard_black, fg = bright_white}, + TelescopePreviewNormal = {bg = hard_black, fg = bright_white}, + TelescopeSelection = {bg = hard_black, fg = bright_white, underline = true}, + } + for hl, col in pairs(TelescopePrompt) do + vim.api.nvim_set_hl(0, hl, col) + end +end diff --git a/init.lua b/init.lua index 77a068d..58d840f 100644 --- a/init.lua +++ b/init.lua @@ -1,45 +1,21 @@ -local g = vim.g -local cmd = vim.cmd - -- Allow loading */init.lua files package.path = "./?/init.lua;"..package.path -- Leader/local leader -g.mapleader = [[ ]] -g.maplocalleader = [[,]] +vim.g.mapleader = [[ ]] +vim.g.maplocalleader = [[,]] -- Disable some built-in plugins we don't want -local disabled_built_ins = { - 'matchit', - 'netrw', - 'netrwPlugin', - 'netrwSettings', - 'netrwFileHandlers', -} - -for _, name in ipairs(disabled_built_ins) do - g['loaded_' .. name] = 1 -end - -require("plugins") +require("disable-builtin") +require("highlight-yank") +require("plugin-manager") require("options") require("bindings") require("pludin-dev") -require("add-guard") -require("cmacro-align") - --- Misc features -require("highlight-yank") - --- Background transparency --- cmd [[autocmd ColorScheme * highlight Normal ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight Folded ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight SignColumn ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight VertSplit ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight StatusLineNC ctermbg=none guibg=none]] --- cmd [[autocmd ColorScheme * highlight CursorLineNr ctermbg=none guibg=none]] +require("personal.add-guard") +require("personal.cmacro-align") -- THEME_BEGIN -cmd("colorscheme srcery") +vim.cmd("colorscheme srcery") -- THEME_END diff --git a/lua/bindings.lua b/lua/bindings.lua index 1625593..12df6cc 100644 --- a/lua/bindings.lua +++ b/lua/bindings.lua @@ -6,7 +6,7 @@ local silent = {silent = true} map('n', 'Q', '') -- Save file -map('n', '', ':w') +map('n', '', ':w', silent) -- Paste from register and not replace it -- map('x', 'p', '"_dP') diff --git a/lua/config/autosource.lua b/lua/config/autosource.lua index 2c6534e..5a7a6e3 100644 --- a/lua/config/autosource.lua +++ b/lua/config/autosource.lua @@ -1,3 +1,7 @@ -local user = os.getenv("USER") -vim.g.autosource_hashdir = '/home/'..user..'/.cache/vim-autosource/hashes' - +return { + 'jenterkin/vim-autosource', + config = function() + local user = os.getenv("USER") + vim.g.autosource_hashdir = '/home/'..user..'/.cache/vim-autosource/hashes' + end +} diff --git a/lua/config/baleia.lua b/lua/config/baleia.lua index 1a6dd94..6237409 100644 --- a/lua/config/baleia.lua +++ b/lua/config/baleia.lua @@ -1,4 +1,10 @@ -local baleia = require("baleia").setup() -vim.api.nvim_create_user_command("BaleiaColorize", function() - baleia.once(vim.api.nvim_get_current_buf()) -end, { }) +return { + 'm00qek/baleia.nvim', + tag = 'v1.2.0', + config = function() + local baleia = require("baleia").setup() + vim.api.nvim_create_user_command("BaleiaColorize", function() + baleia.once(vim.api.nvim_get_current_buf()) + end, { }) + end +} diff --git a/lua/config/based.lua b/lua/config/based.lua index f9f989b..2bda153 100644 --- a/lua/config/based.lua +++ b/lua/config/based.lua @@ -1,4 +1,9 @@ -local based = require("based") -based.setup{} +return { + 'trmckay/based.nvim', + config = function () + local based = require("based") + based.setup{} -vim.keymap.set({"n", "v"}, "", based.convert) + vim.keymap.set({"n", "v"}, "", based.convert) + end +} diff --git a/lua/config/cellular-automaton.lua b/lua/config/cellular-automaton.lua deleted file mode 100644 index bddfbf2..0000000 --- a/lua/config/cellular-automaton.lua +++ /dev/null @@ -1,46 +0,0 @@ -local automaton = require("cellular-automaton") - -local timeout = 120 - -local timer -local function enable_screensaver() - local group = vim.api.nvim_create_augroup('CellularAutomatonScreenSaver', {clear=true}) - - local animations = {} - for name in pairs(automaton.animations) do - table.insert(animations, name) - end - - local function play_random_animation() - local idx = math.random(#animations) - local animation_name = animations[idx] - if animation_name then - automaton.start_animation(animation_name) - end - end - - vim.api.nvim_create_autocmd({'CursorHold', 'CursorHoldI'}, { - group = group, - callback = function() - -- TODO: Will vim.defer_fn suffice here? - timer = vim.loop.new_timer() - timer:start(timeout * 1000, 0, vim.schedule_wrap(function() - if timer:is_active() then timer:stop() end - if not timer:is_closing() then timer:close() end - - play_random_animation() - end)) - - vim.api.nvim_create_autocmd({'CursorMoved', 'CursorMovedI'}, { - group = group, - callback = function() - if timer:is_active() then timer:stop() end - if not timer:is_closing() then timer:close() end - end, - once = true - }) - end - }) -end - -enable_screensaver() diff --git a/lua/config/colorizer.lua b/lua/config/colorizer.lua index 444a0a4..98dd054 100644 --- a/lua/config/colorizer.lua +++ b/lua/config/colorizer.lua @@ -1,15 +1,19 @@ -require('colorizer').setup( - nil, - { - RGB = true, - RRGGBB = true, - names = false, - RRGGBBAA = true, - rgb_fn = true, - hsl_fn = true, - css = false, - css_fn = false, - mode = 'background' - } -) - +return { + 'norcalli/nvim-colorizer.lua', + config = function() + require('colorizer').setup( + nil, + { + RGB = true, + RRGGBB = true, + names = false, + RRGGBBAA = true, + rgb_fn = true, + hsl_fn = true, + css = false, + css_fn = false, + mode = 'background' + } + ) + end +} diff --git a/lua/config/comment.lua b/lua/config/comment.lua index a70d91a..b360fd1 100644 --- a/lua/config/comment.lua +++ b/lua/config/comment.lua @@ -1,11 +1,17 @@ -local config = {} +return { + 'terrortylor/nvim-comment', + requires = 'JoosepAlviste/nvim-ts-context-commentstring', + config = function() + local config = {} -if packer_plugins['nvim-ts-context-commentstring'] and packer_plugins['nvim-ts-context-commentstring'].loaded then - config.hook = function() - if vim.api.nvim_buf_get_option(0, "filetype") == "vue" then - require("ts_context_commentstring.internal").update_commentstring() - end + if packer_plugins['nvim-ts-context-commentstring'] and packer_plugins['nvim-ts-context-commentstring'].loaded then + config.hook = function() + if vim.api.nvim_buf_get_option(0, "filetype") == "vue" then + require("ts_context_commentstring.internal").update_commentstring() + end + end + end + + require("nvim_comment").setup(config) end -end - -require("nvim_comment").setup(config) +} diff --git a/lua/config/devicons.lua b/lua/config/devicons.lua new file mode 100644 index 0000000..7e72d6a --- /dev/null +++ b/lua/config/devicons.lua @@ -0,0 +1,6 @@ +return { + 'kyazdani42/nvim-web-devicons', + config = function() + require('nvim-web-devicons').setup() + end +} diff --git a/lua/config/dressing.lua b/lua/config/dressing.lua new file mode 100644 index 0000000..204af5a --- /dev/null +++ b/lua/config/dressing.lua @@ -0,0 +1,26 @@ +return { + 'stevearc/dressing.nvim', + config = function() + require('dressing').setup({ + select = { + get_config = function(opts) + opts = opts or {} + local cfg = { + telescope = { + layout_config = { + -- width = 120, + -- height = 60, + width = 0.87, + height = 0.80, + }, + }, + } + if opts.kind == 'legendary.nvim' then + cfg.telescope.sorter = require('telescope.sorters').fuzzy_with_index_bias({}) + end + return cfg + end, + }, + }) + end +} diff --git a/lua/config/fugitive.lua b/lua/config/fugitive.lua index da0ce8d..f671521 100644 --- a/lua/config/fugitive.lua +++ b/lua/config/fugitive.lua @@ -1,3 +1,6 @@ -local map = require 'utils.map' - -map('n', 'gg', ':G', { silent = true }) +return { + 'tpope/vim-fugitive', + config = function () + vim.keymap.set('n', 'gg', ':G', { silent = true }) + end +} diff --git a/lua/config/gitblame.lua b/lua/config/gitblame.lua index 85729ca..4d4dc73 100644 --- a/lua/config/gitblame.lua +++ b/lua/config/gitblame.lua @@ -1,8 +1,13 @@ -local map = require 'utils.map' -local silent = {silent = true} +return { + 'f-person/git-blame.nvim', + config = function () + local map = require 'utils.map' + local silent = {silent = true} -map('n', 'gm', ":GitBlameCopySHA", silent) -map('n', 'gj', ":GitBlameOpenCommitURL", silent) -map('n', 'gu', ":GitBlameToggle", silent) + map('n', 'gm', ":GitBlameCopySHA", silent) + map('n', 'gj', ":GitBlameOpenCommitURL", silent) + map('n', 'gu', ":GitBlameToggle", silent) -vim.g["gitblame_enabled"] = 0 + vim.g["gitblame_enabled"] = 0 + end +} diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua index 7c3b280..e28a922 100644 --- a/lua/config/gitsigns.lua +++ b/lua/config/gitsigns.lua @@ -1,33 +1,39 @@ -local gitsigns = require 'gitsigns' +return { + 'lewis6991/gitsigns.nvim', + requires = 'nvim-lua/plenary.nvim', + config = function () + local gitsigns = require 'gitsigns' -gitsigns.setup{ - on_attach = function(bufnr) - local function map(mode, lhs, rhs, opts) - opts = vim.tbl_extend('force', {noremap = true, silent = true}, opts or {}) - vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts) - end + gitsigns.setup{ + on_attach = function(bufnr) + local function map(mode, lhs, rhs, opts) + opts = vim.tbl_extend('force', {noremap = true, silent = true}, opts or {}) + vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts) + end - -- Navigation - map('n', ']c', "&diff ? ']c' : 'Gitsigns next_hunk'", {expr=true}) - map('n', '[c', "&diff ? '[c' : 'Gitsigns prev_hunk'", {expr=true}) + -- Navigation + map('n', ']c', "&diff ? ']c' : 'Gitsigns next_hunk'", {expr=true}) + map('n', '[c', "&diff ? '[c' : 'Gitsigns prev_hunk'", {expr=true}) - -- Actions - map('n', 'hs', ':Gitsigns stage_hunk') - map('v', 'hs', ':Gitsigns stage_hunk') - map('n', 'hr', ':Gitsigns reset_hunk') - map('v', 'hr', ':Gitsigns reset_hunk') - map('n', 'hS', 'Gitsigns stage_buffer') - map('n', 'hu', 'Gitsigns undo_stage_hunk') - map('n', 'hR', 'Gitsigns reset_buffer') - map('n', 'hp', 'Gitsigns preview_hunk') - map('n', 'hb', 'lua require"gitsigns".blame_line{full=true}') - map('n', 'tb', 'Gitsigns toggle_current_line_blame') - map('n', 'hd', 'Gitsigns diffthis') - map('n', 'hD', 'lua require"gitsigns".diffthis("~")') - map('n', 'td', 'Gitsigns toggle_deleted') + -- Actions + map('n', 'hs', ':Gitsigns stage_hunk') + map('v', 'hs', ':Gitsigns stage_hunk') + map('n', 'hr', ':Gitsigns reset_hunk') + map('v', 'hr', ':Gitsigns reset_hunk') + map('n', 'hS', 'Gitsigns stage_buffer') + map('n', 'hu', 'Gitsigns undo_stage_hunk') + map('n', 'hR', 'Gitsigns reset_buffer') + map('n', 'hp', 'Gitsigns preview_hunk') + map('n', 'hb', 'lua require"gitsigns".blame_line{full=true}') + map('n', 'tb', 'Gitsigns toggle_current_line_blame') + map('n', 'hd', 'Gitsigns diffthis') + map('n', 'hD', 'lua require"gitsigns".diffthis("~")') + map('n', 'td', 'Gitsigns toggle_deleted') - -- Text object - map('o', 'ih', ':Gitsigns select_hunk') - map('x', 'ih', ':Gitsigns select_hunk') + -- Text object + map('o', 'ih', ':Gitsigns select_hunk') + map('x', 'ih', ':Gitsigns select_hunk') + end + } end } diff --git a/lua/config/leap.lua b/lua/config/leap.lua index fbb3e6c..0040997 100644 --- a/lua/config/leap.lua +++ b/lua/config/leap.lua @@ -1,3 +1,8 @@ -local silent = {silent=true} -vim.keymap.set("n", "s", "(leap-forward-to)", silent) -vim.keymap.set("n", "S", "(leap-backward-to)", silent) +return { + 'ggandor/leap.nvim', + config = function() + local silent = {silent=true} + vim.keymap.set("n", "s", "(leap-forward-to)", silent) + vim.keymap.set("n", "S", "(leap-backward-to)", silent) + end +} diff --git a/lua/config/legendary.lua b/lua/config/legendary.lua new file mode 100644 index 0000000..639c297 --- /dev/null +++ b/lua/config/legendary.lua @@ -0,0 +1,13 @@ +return { + 'mrjones2014/legendary.nvim', + config = function() + vim.keymap.set("n", "l", ":Legendary", {silent = true}) + + require("legendary").setup{ + include_legendary_cmds = false, + commands = { + { ":TodoTelescope", description = "Show TODO's in telescope" } + } + } + end +} diff --git a/lua/config/lspinstaller.lua b/lua/config/lspinstaller.lua index e6bb58e..4d4292a 100644 --- a/lua/config/lspinstaller.lua +++ b/lua/config/lspinstaller.lua @@ -1,7 +1,6 @@ -local lspconfig_config = require 'config.lspconfig' -local lsp_installer = require 'nvim-lsp-installer' -local lsp_installer_servers = require'nvim-lsp-installer.servers' -local M = {} +local lspconfig_config = require('config.lspconfig') +local lsp_installer = require('nvim-lsp-installer') +local lsp_installer_servers = require('nvim-lsp-installer.servers') -- local autoinstall_servers = {"sumneko_lua", "efm"} local autoinstall_servers = {"sumneko_lua"} @@ -17,8 +16,8 @@ local capabilities = lspconfig_config.get_capabilities() for _, server in ipairs(lsp_installer.get_installed_servers()) do local opts = { root_dir = function() - return vim.fn.getcwd() - end, + return vim.fn.getcwd() + end, init_options = lspconfig_config.get_server_init_options(server.name), on_attach = lspconfig_config.on_attach, on_init = lspconfig_config.on_init, @@ -38,5 +37,3 @@ for _, server in ipairs(lsp_installer.get_installed_servers()) do server:setup(opts) ::continue:: end - -return M diff --git a/lua/config/lspsignature.lua b/lua/config/lspsignature.lua index 122669c..6940cd4 100644 --- a/lua/config/lspsignature.lua +++ b/lua/config/lspsignature.lua @@ -1,4 +1,9 @@ -require "lsp_signature".setup{ - hint_enable = false, - toggle_key = '' +return { + "ray-x/lsp_signature.nvim", + config = function() + require "lsp_signature".setup{ + hint_enable = false, + toggle_key = '' + } + end } diff --git a/lua/config/lsputils.lua b/lua/config/lsputils.lua index dc91e60..d3dd310 100644 --- a/lua/config/lsputils.lua +++ b/lua/config/lsputils.lua @@ -1,43 +1,14 @@ -if vim.fn.has('nvim-0.5.1') == 1 then - vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler - vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler - vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler - vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler - vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler - vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler - vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler - vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler -else - local bufnr = vim.api.nvim_buf_get_number(0) - vim.lsp.handlers['textDocument/codeAction'] = function(_, _, actions) - require('lsputil.codeAction').code_action_handler(nil, actions, nil, nil, nil) +return { + 'RishabhRD/nvim-lsputils', + requires = 'RishabhRD/popfix', + config = function() + vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler + vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler + vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler + vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler + vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler + vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler + vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler + vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler end - - vim.lsp.handlers['textDocument/references'] = function(_, _, result) - require('lsputil.locations').references_handler(nil, result, { bufnr = bufnr }, nil) - end - - vim.lsp.handlers['textDocument/definition'] = function(_, method, result) - require('lsputil.locations').definition_handler(nil, result, { bufnr = bufnr, method = method }, nil) - end - - vim.lsp.handlers['textDocument/declaration'] = function(_, method, result) - require('lsputil.locations').declaration_handler(nil, result, { bufnr = bufnr, method = method }, nil) - end - - vim.lsp.handlers['textDocument/typeDefinition'] = function(_, method, result) - require('lsputil.locations').typeDefinition_handler(nil, result, { bufnr = bufnr, method = method }, nil) - end - - vim.lsp.handlers['textDocument/implementation'] = function(_, method, result) - require('lsputil.locations').implementation_handler(nil, result, { bufnr = bufnr, method = method }, nil) - end - - vim.lsp.handlers['textDocument/documentSymbol'] = function(_, _, result, _, bufn) - require('lsputil.symbols').document_handler(nil, result, { bufnr = bufn }, nil) - end - - vim.lsp.handlers['textDocument/symbol'] = function(_, _, result, _, bufn) - require('lsputil.symbols').workspace_handler(nil, result, { bufnr = bufn }, nil) - end -end +} diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index 8b81b71..c2a47b7 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -24,50 +24,50 @@ local theme = { local empty = require('lualine.component'):extend() function empty:draw(default_highlight) - self.status = '' - self.applied_separator = '' - self:apply_highlights(default_highlight) - self:apply_section_separators() - return self.status + self.status = '' + self.applied_separator = '' + self:apply_highlights(default_highlight) + self:apply_section_separators() + return self.status end -- Put proper separators and gaps between components in sections local function process_sections(sections) - for name, section in pairs(sections) do - local left = name:sub(9, 10) < 'x' - for pos = 1, name ~= 'lualine_z' and #section or #section - 1 do - table.insert(section, pos * 2, { empty, color = { fg = bg, bg = bg } }) - end - for id, comp in ipairs(section) do - if type(comp) ~= 'table' then - comp = { comp } - section[id] = comp - end - comp.separator = left and { right = '' } or { left = '' } - end - end - return sections + for name, section in pairs(sections) do + local left = name:sub(9, 10) < 'x' + for pos = 1, name ~= 'lualine_z' and #section or #section - 1 do + table.insert(section, pos * 2, { empty, color = { fg = bg, bg = bg } }) + end + for id, comp in ipairs(section) do + if type(comp) ~= 'table' then + comp = { comp } + section[id] = comp + end + comp.separator = left and { right = '' } or { left = '' } + end + end + return sections end local function search_result() - local last_search = vim.fn.getreg('/') - if not last_search or last_search == '' then - return '' - end - local searchcount = vim.fn.searchcount { maxcount = 9999 } + local last_search = vim.fn.getreg('/') + if not last_search or last_search == '' then + return '' + end + local searchcount = vim.fn.searchcount { maxcount = 9999 } if searchcount.total == 0 then return '' end - return last_search .. '(' .. searchcount.current .. '/' .. searchcount.total .. ')' + return last_search .. '(' .. searchcount.current .. '/' .. searchcount.total .. ')' end local function modified() - if vim.bo.modified then - return '+' - elseif vim.bo.modifiable == false or vim.bo.readonly == true then - return '-' - end - return '' + if vim.bo.modified then + return '+' + elseif vim.bo.modifiable == false or vim.bo.readonly == true then + return '-' + end + return '' end local function recording_macro() @@ -113,49 +113,49 @@ if pcall(require, "luapad.statusline") then end require('lualine').setup { - options = { - theme = theme, - component_separators = '', - section_separators = { left = '', right = '' }, + options = { + theme = theme, + component_separators = '', + section_separators = { left = '', right = '' }, -- ignore_focus = {"NvimTree"}, globalstatus = true - }, - sections = process_sections { - lualine_a = { 'mode' }, - lualine_b = { - 'branch', - 'diff', - { - 'diagnostics', - source = { 'nvim' }, - sections = { 'error' }, - diagnostics_color = { error = { bg = colors.red, fg = colors.white } }, - }, - { - 'diagnostics', - source = { 'nvim' }, - sections = { 'warn' }, - diagnostics_color = { warn = { bg = colors.orange, fg = colors.white } }, - }, - { 'filename', file_status = false, path = 1 }, - { modified, color = { bg = colors.red } }, - { '%w', cond = function() return vim.wo.previewwindow end }, - { '%r', cond = function() return vim.bo.readonly end }, - { '%q', cond = function() return vim.bo.buftype == 'quickfix' end }, + }, + sections = process_sections { + lualine_a = { 'mode' }, + lualine_b = { + 'branch', + 'diff', + { + 'diagnostics', + source = { 'nvim' }, + sections = { 'error' }, + diagnostics_color = { error = { bg = colors.red, fg = colors.white } }, + }, + { + 'diagnostics', + source = { 'nvim' }, + sections = { 'warn' }, + diagnostics_color = { warn = { bg = colors.orange, fg = colors.white } }, + }, + { 'filename', file_status = false, path = 1 }, + { modified, color = { bg = colors.red } }, + { '%w', cond = function() return vim.wo.previewwindow end }, + { '%r', cond = function() return vim.bo.readonly end }, + { '%q', cond = function() return vim.bo.buftype == 'quickfix' end }, { recording_macro, color = { bg = colors.orange } } - }, - lualine_c = {}, - lualine_x = {}, - lualine_y = { search_result, 'filetype' }, - lualine_z = { '%l:%c', '%p%%/%L' }, - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {}, - lualine_x = {}, - lualine_y = {}, - lualine_z = {}, - }, + }, + lualine_c = {}, + lualine_x = {}, + lualine_y = { search_result, 'filetype' }, + lualine_z = { '%l:%c', '%p%%/%L' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, extensions = extensions } diff --git a/lua/config/luapad.lua b/lua/config/luapad.lua index 35b0b2a..87d5fcd 100644 --- a/lua/config/luapad.lua +++ b/lua/config/luapad.lua @@ -1,5 +1,5 @@ local pattern = "^/tmp/.*/%d+_Luapad%.lua$" -local group = vim.api.nvim_create_augroup('LuaPadFiletype', {clear=true}) +local group = vim.api.nvim_create_augroup("LuaPadFiletype", {clear=true}) vim.api.nvim_create_autocmd("FileType", { group = group, callback = function(data) diff --git a/lua/config/luasnip.lua b/lua/config/luasnip.lua index a1f9e7b..87285c7 100644 --- a/lua/config/luasnip.lua +++ b/lua/config/luasnip.lua @@ -1,92 +1,99 @@ -local ls = require("luasnip") -local capture = require("utils.capture") -local s = ls.snippet -local sn = ls.snippet_node -local fmt = require("luasnip.extras.fmt").fmt -local t = ls.text_node -local i = ls.insert_node -local f = ls.function_node -local c = ls.choice_node -local d = ls.dynamic_node +local function config() + local ls = require("luasnip") + local capture = require("utils.capture") + local s = ls.snippet + local sn = ls.snippet_node + local fmt = require("luasnip.extras.fmt").fmt + local t = ls.text_node + local i = ls.insert_node + local f = ls.function_node + local c = ls.choice_node + local d = ls.dynamic_node -local function getCurrentYear() - return os.date("%Y") -end - -local function getGitUsername() - local stdout = capture("git config user.name") - if stdout == "" then - return nil + local function getCurrentYear() + return os.date("%Y") end - return stdout -end -ls.config.set_config { - history = true, - updateevents = "TextChanged,TextChangedI", - enable_autosnippets = true -} - -vim.keymap.set({"i", "s"}, "", function() - if ls.expand_or_jumpable() then - ls.expand_or_jump() + local function getGitUsername() + local stdout = capture("git config user.name") + if stdout == "" then + return nil + end + return stdout end -end, { silent = true }) -vim.keymap.set({ "i", "s" }, "", function() - if ls.jumpable(-1) then - ls.jump(-1) - end -end, { silent = -1 }) + ls.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + enable_autosnippets = true + } -vim.keymap.set({"i"}, "", function() - if ls.choice_active() then - ls.change_choice(1) - end -end) + vim.keymap.set({"i", "s"}, "", function() + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end, { silent = true }) -ls.add_snippets("all", { - s("MIT", { - t({"The MIT License (MIT)", "Copyright © "}), - f(getCurrentYear, {}), - t(" "), - d(1, function() - return sn(nil, { - i(1, getGitUsername() or "") - }) - end, {}), - t{ - "", - "", - "Permission is hereby granted, free of charge, to any person obtaining a copy of", - "this software and associated documentation files (the “Software”), to deal in", - "the Software without restriction, including without limitation the rights to", - "use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies", - "of the Software, and to permit persons to whom the Software is furnished to do", - "so, subject to the following conditions:", - "", - "The above copyright notice and this permission notice shall be included in all", - "copies or substantial portions of the Software.", - "", - "THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", - "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", - "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", - "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", - "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", - "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", - "SOFTWARE.", - } - }) -}) + vim.keymap.set({ "i", "s" }, "", function() + if ls.jumpable(-1) then + ls.jump(-1) + end + end, { silent = -1 }) -ls.add_snippets("lua", { - s("req", - fmt([[local {} = require("{}")]], { - f(function(module_name) - local parts = vim.split(module_name[1][1], ".", true) - return (parts[#parts] or ""):gsub("-", "_") - end, { 1 }), - i(1) + vim.keymap.set({"i"}, "", function() + if ls.choice_active() then + ls.change_choice(1) + end + end) + + ls.add_snippets("all", { + s("MIT", { + t({"The MIT License (MIT)", "Copyright © "}), + f(getCurrentYear, {}), + t(" "), + d(1, function() + return sn(nil, { + i(1, getGitUsername() or "") + }) + end, {}), + t{ + "", + "", + "Permission is hereby granted, free of charge, to any person obtaining a copy of", + "this software and associated documentation files (the “Software”), to deal in", + "the Software without restriction, including without limitation the rights to", + "use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies", + "of the Software, and to permit persons to whom the Software is furnished to do", + "so, subject to the following conditions:", + "", + "The above copyright notice and this permission notice shall be included in all", + "copies or substantial portions of the Software.", + "", + "THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", + "SOFTWARE.", + } }) - ) -}) + }) + + ls.add_snippets("lua", { + s("req", + fmt([[local {} = require("{}")]], { + f(function(module_name) + local parts = vim.split(module_name[1][1], ".", true) + return (parts[#parts] or ""):gsub("-", "_") + end, { 1 }), + i(1) + }) + ) + }) +end + +return { + 'L3MON4D3/LuaSnip', + config = config +} diff --git a/lua/config/move.lua b/lua/config/move.lua index 3369da6..b20fadb 100644 --- a/lua/config/move.lua +++ b/lua/config/move.lua @@ -1,12 +1,17 @@ -local opts = { noremap = true, silent = true } --- Normal-mode commands --- vim.keymap.set('n', '', ':MoveLine(1)', opts) --- vim.keymap.set('n', '', ':MoveLine(-1)', opts) --- vim.keymap.set('n', '', ':MoveHChar(-1)', opts) --- vim.keymap.set('n', '', ':MoveHChar(1)', opts) +return { + 'fedepujol/move.nvim', + config = function() + local opts = { noremap = true, silent = true } + -- Normal-mode commands + -- vim.keymap.set('n', '', ':MoveLine(1)', opts) + -- vim.keymap.set('n', '', ':MoveLine(-1)', opts) + -- vim.keymap.set('n', '', ':MoveHChar(-1)', opts) + -- vim.keymap.set('n', '', ':MoveHChar(1)', opts) --- Visual-mode commands -vim.keymap.set('v', '', ':MoveBlock(1)', opts) -vim.keymap.set('v', '', ':MoveBlock(-1)', opts) -vim.keymap.set('v', '', ':MoveHBlock(-1)', opts) -vim.keymap.set('v', '', ':MoveHBlock(1)', opts) + -- Visual-mode commands + vim.keymap.set('v', '', ':MoveBlock(1)', opts) + vim.keymap.set('v', '', ':MoveBlock(-1)', opts) + vim.keymap.set('v', '', ':MoveHBlock(-1)', opts) + vim.keymap.set('v', '', ':MoveHBlock(1)', opts) + end +} diff --git a/lua/config/nvim-tree.lua b/lua/config/nvim-tree.lua index 7fa61af..0954009 100644 --- a/lua/config/nvim-tree.lua +++ b/lua/config/nvim-tree.lua @@ -1,13 +1,17 @@ -local map = require("utils.map") +return { + 'kyazdani42/nvim-tree.lua', + requires = 'kyazdani42/nvim-web-devicons', + config = function () + require("nvim-tree").setup{ + git = { + enable = false + }, + renderer = { + group_empty = true, + }, + } -require("nvim-tree").setup{ - git = { - enable = false - }, - renderer = { - group_empty = true, - }, + vim.keymap.set("n", "e", ":NvimTreeToggle", {silent = true}) + vim.keymap.set("n", "f", ":NvimTreeFindFileToggle", {silent = true}) + end } - -map("n", "e", ":NvimTreeToggle", {silent = true}) -map("n", "f", ":NvimTreeFindFileToggle", {silent = true}) diff --git a/lua/config/quickscope.lua b/lua/config/quickscope.lua index 0390c0b..5d29545 100644 --- a/lua/config/quickscope.lua +++ b/lua/config/quickscope.lua @@ -1,8 +1,12 @@ -local g = vim.g -local cmd = vim.cmd +return { + 'unblevable/quick-scope', + config = function () + local g = vim.g + local cmd = vim.cmd --- Trigger a highlight in the appropriate direction when pressing these keys: -g['qs_highlight_on_keys'] = {'f', 'F', 't', 'T'} - -g['qs_max_chars'] = 150 + -- Trigger a highlight in the appropriate direction when pressing these keys: + g['qs_highlight_on_keys'] = {'f', 'F', 't', 'T'} + g['qs_max_chars'] = 150 + end +} diff --git a/lua/config/telescope.lua b/lua/config/telescope.lua index d10f2c8..b02c023 100644 --- a/lua/config/telescope.lua +++ b/lua/config/telescope.lua @@ -1,99 +1,108 @@ local telescope = require('telescope') -local map = require('utils.map') local actions = require('telescope.actions') local builtin = require('telescope.builtin') -local previewers = require('telescope.previewers') -local M = {} - -local function sizelimit_maker(filepath, bufnr, opts) - opts = opts or {} - local size_limit = 100 * 1024 -- 100KiB - - filepath = vim.fn.expand(filepath) - vim.loop.fs_stat(filepath, function(_, stat) - if not stat then return end - if stat.size > size_limit then - return - else - previewers.buffer_previewer_maker(filepath, bufnr, opts) - end - end) -end -- Falling back to find_files if git_files can't find a .git directory -function M.project_files(opts) - local ok = pcall(builtin.git_files, opts) - if not ok then builtin.find_files(opts) end +local function project_files() + local opts = { prompt_title = 'Project files' } + local ok = pcall(builtin.git_files, opts) + if not ok then builtin.find_files(opts) end end -function M.edit_config(_opts) +local function edit_config() return M.project_files{ cwd = "~/.config/nvim", prompt_title = "Neovim config" } end -local silent = {silent = true} - --- Search project files -map('n', '', [[:lua require('config.telescope').project_files{ prompt_title = 'Project files' }]], silent) - --- Search files from current working directory -map('n', 'p', [[:lua require('telescope.builtin').find_files()]], silent) - --- Edit neovim config -map('n', 'ce', [[:lua require('config.telescope').edit_config()]], silent) - --- Find string -map('n', 'fw', [[:lua require('telescope.builtin').live_grep()]], silent) - --- Change colorscheme -map('n', 'cs', [[:lua require('telescope.builtin').colorscheme()]], silent) - --- See help tags -map('n', 'fh', [[:lua require('telescope.builtin').help_tags()]], silent) - telescope.setup{ defaults = { - buffer_previewer_maker = sizelimit_maker, - path_display = { "shorten" }, + vimgrep_arguments = { + "rg", + "-L", + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + }, + prompt_prefix = "  ", + selection_caret = " ", + entry_prefix = " ", + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = "ascending", + layout_strategy = "horizontal", + layout_config = { + horizontal = { + prompt_position = "top", + preview_width = 0.55, + results_width = 0.8, + }, + vertical = { mirror = false }, + width = 0.87, + height = 0.80, + preview_cutoff = 120, + }, + file_sorter = require("telescope.sorters").get_fuzzy_file, + file_ignore_patterns = { "node_modules" }, + generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, + path_display = { "truncate" }, color_devicons = true, + winblend = 0, + border = {}, + borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + 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, + -- Developer configurations: Not meant for general override + buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker, mappings = { - i = { - [""] = actions.close - } - } + i = { [""] = actions.close } + }, }, pickers = { - find_files = { - theme = "dropdown", - }, - marks = { - theme = "dropdown", - }, - help_tags = { - theme = "dropdown", - }, - oldfiles = { - theme = "dropdown", - }, - git_files = { - theme = "dropdown", - }, live_grep = { - theme = "dropdown", disable_coordinates = true }, colorscheme = { - theme = "dropdown", enable_preview = true } + }, + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown {} + } } } +telescope.load_extension("ui-select") + local fzfPlugin = packer_plugins["telescope-fzf-native.nvim"] if fzfPlugin and fzfPlugin.loaded then telescope.load_extension('fzf') end -return M + +local silent = {silent = true} + +-- Search project files +vim.keymap.set("n", "", project_files, silent) + +-- Search files from current working directory +vim.keymap.set("n", "p", function() builtin.find_files() end, silent) + +-- Edit neovim config +vim.keymap.set("n", "ce", edit_config, silent) + +-- Find string +vim.keymap.set("n", "fw", function() builtin.live_grep() end, silent) + +-- Change colorscheme +vim.keymap.set("n", "cs", function() builtin.colorscheme() end, silent) + +-- See help tags +vim.keymap.set("n", "fh", function() builtin.help_tags() end, silent) diff --git a/lua/config/tidy.lua b/lua/config/tidy.lua new file mode 100644 index 0000000..f324797 --- /dev/null +++ b/lua/config/tidy.lua @@ -0,0 +1,6 @@ +return { + "mcauley-penney/tidy.nvim", + config = function() + require("tidy").setup() + end +} diff --git a/lua/config/todo-comments.lua b/lua/config/todo-comments.lua new file mode 100644 index 0000000..79f8614 --- /dev/null +++ b/lua/config/todo-comments.lua @@ -0,0 +1,7 @@ +return { + "folke/todo-comments.nvim", + requires = "nvim-lua/plenary.nvim", + config = function() + require("todo-comments").setup { signs = false } + end +} diff --git a/lua/config/toggleterm.lua b/lua/config/toggleterm.lua index 22ddcba..f84d054 100644 --- a/lua/config/toggleterm.lua +++ b/lua/config/toggleterm.lua @@ -1,3 +1,9 @@ -require('toggleterm').setup() +return { + 'akinsho/toggleterm.nvim', + tag = '*', + config = function() + require('toggleterm').setup() -vim.keymap.set("n", "t", ":ToggleTerm") + vim.keymap.set("n", "t", ":ToggleTerm") + end +} diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 9d1d955..a35f111 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,6 +1,12 @@ -local treesitter = require("nvim-treesitter.configs") +return { + 'nvim-treesitter/nvim-treesitter', + run = function() require('nvim-treesitter.install').update{ with_sync = true } end, + config = function () + local treesitter = require("nvim-treesitter.configs") -treesitter.setup{ - highlight = { enable = true }, - auto_install = true + treesitter.setup{ + highlight = { enable = true }, + auto_install = true + } + end } diff --git a/lua/config/trouble.lua b/lua/config/trouble.lua index a0b4d46..24e4f65 100644 --- a/lua/config/trouble.lua +++ b/lua/config/trouble.lua @@ -1,9 +1,15 @@ -local map = require 'utils.map' +return { + 'folke/trouble.nvim', + requires = 'kyazdani42/nvim-web-devicons', + config = function () + local map = require 'utils.map' -require('trouble').setup() + require('trouble').setup() -local silent = {silent = true} + local silent = {silent = true} -map('n', 'qq', ':TroubleToggle document_diagnostics', silent) -map('n', 'qf', ':TroubleToggle workspace_diagnostics', silent) -map('n', 'rf', ':TroubleToggle lsp_references', silent) + map('n', 'qq', ':TroubleToggle document_diagnostics', silent) + map('n', 'qf', ':TroubleToggle workspace_diagnostics', silent) + map('n', 'rf', ':TroubleToggle lsp_references', silent) + end +} diff --git a/lua/config/ts-playground.lua b/lua/config/ts-playground.lua new file mode 100644 index 0000000..9b48306 --- /dev/null +++ b/lua/config/ts-playground.lua @@ -0,0 +1,5 @@ +return { + 'nvim-treesitter/playground', + requires = 'nvim-treesitter/nvim-treesitter', + cmd = "TSPlaygroundToggle" +} diff --git a/lua/disable-builtin.lua b/lua/disable-builtin.lua new file mode 100644 index 0000000..6c6fe83 --- /dev/null +++ b/lua/disable-builtin.lua @@ -0,0 +1,11 @@ +local disabled_built_ins = { + 'matchit', + 'netrw', + 'netrwPlugin', + 'netrwSettings', + 'netrwFileHandlers', +} + +for _, name in ipairs(disabled_built_ins) do + vim.g['loaded_' .. name] = 1 +end diff --git a/lua/add-guard.lua b/lua/personal/add-guard.lua similarity index 100% rename from lua/add-guard.lua rename to lua/personal/add-guard.lua diff --git a/lua/cmacro-align.lua b/lua/personal/cmacro-align.lua similarity index 100% rename from lua/cmacro-align.lua rename to lua/personal/cmacro-align.lua diff --git a/lua/pludin-dev.lua b/lua/pludin-dev.lua index 5106c89..0d6b64b 100644 --- a/lua/pludin-dev.lua +++ b/lua/pludin-dev.lua @@ -1,6 +1,5 @@ -local map = require 'utils.map' -map("n", "x", ":w:source %") +vim.keymap.set("n", "x", ":w:source %", { silent = true }) function P(...) print(vim.inspect(...)) diff --git a/lua/plugin-manager.lua b/lua/plugin-manager.lua new file mode 100644 index 0000000..7e397d4 --- /dev/null +++ b/lua/plugin-manager.lua @@ -0,0 +1,88 @@ +-- Register custom commands for plugin manager +vim.cmd [[command! -bang -nargs=+ -complete=customlist,v:lua.require'plugin-manager'.loader_complete PackerLoad lua require('plugin-manager').loader(, '' == '!')]] +vim.cmd [[command! PackerInstall packadd packer.nvim | lua require('plugin-manager').install()]] +vim.cmd [[command! PackerUpdate packadd packer.nvim | lua require('plugin-manager').update()]] +vim.cmd [[command! PackerSync packadd packer.nvim | lua require('plugin-manager').sync()]] +vim.cmd [[command! PackerClean packadd packer.nvim | lua require('plugin-manager').clean()]] +vim.cmd [[command! PackerCompile source lua/plugin-manager.lua | packadd packer.nvim | lua require('plugin-manager').compile()]] + +-- Bootstrap packer.nvim. If packer.nvim is not installed, install it. +local function bootstrap() + local fn = vim.fn + local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' + if fn.empty(fn.glob(install_path)) > 0 then + return fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + end +end + +local function create_custom_use(use) + return function (opts) + if type(opts) == "string" then + use(opts) + return opts + elseif type(opts) == "table" then + if opts.load_config then + local name = vim.split(opts[1], "/")[2] + if name:match("%.nvim$") then + name = name:sub(1, -6) + end + opts.config_name = name + end + if opts.config_name then + opts.config = ("require('config.%s')"):format(opts.config_name) + end + use(opts) + + return opts[1] + else + error("What are you doing???") + end + end +end + +local packer = nil +local function init() + -- Perform bootstrap + local packer_bootstrap = bootstrap() + + -- Initialize packer + if packer == nil then + packer = require 'packer' + local util = require 'packer.util' + packer.init { + compile_path = util.join_paths(vim.fn.stdpath('config'), 'plugin', 'packer-compiled.lua'), + disable_commands = true + } + end + + -- Reset plugins if already loaded + packer.reset() + + -- Packer can manage itself + packer.use 'wbthomason/packer.nvim' + + -- Use plugins + local use = create_custom_use(packer.use) + for _, module_name in ipairs{"plugins", "plugins-local"} do + local ok, use_plugins = pcall(require, module_name) + if ok then + assert(type(use_plugins) == "function") + use_plugins(use) + end + end + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if packer_bootstrap then + require('packer').sync() + end +end + +local plugins = setmetatable({}, { + __index = function(_, key) + init() + return packer[key] + end +}) + +return plugins diff --git a/lua/plugins-local.lua b/lua/plugins-local.lua new file mode 100644 index 0000000..1b6f21c --- /dev/null +++ b/lua/plugins-local.lua @@ -0,0 +1,2 @@ +return function(use) +end diff --git a/lua/plugins.lua b/lua/plugins.lua index bf06731..f41a70b 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,16 +1,87 @@ -- TODO: Add minimal plugin mode. Disables all plugins which are not super -- important, to get better performance. ----@diagnostic disable-next-line: unused-local -local function usePlugins(use, use_rocks) - -- Toggle terminal - use { 'akinsho/toggleterm.nvim', tag = '*', load_config=true } +return function(use) + local function use_config(name) + use(require(("config.%s"):format(name))) + end - -- Colorize ANSI codes - use { 'm00qek/baleia.nvim', tag = 'v1.2.0', config=[[require('config.baleia')]] } + use_config "toggleterm" + use_config "baleia" + use_config "todo-comments" + use_config "legendary" + use_config "dressing" + use_config "move" + use_config "gitblame" + use_config "based" + use_config "lspsignature" + use_config "lsputils" + use_config "luasnip" + use_config "trouble" + use_config "fugitive" + use_config "gitsigns" + use_config "nvim-tree" + use_config "autosource" + use_config "tidy" + use_config "quickscope" + use_config "leap" + use_config "comment" + use_config "colorizer" + use_config "devicons" + use_config "treesitter" + use_config "ts-playground" + + use { + "nvim-telescope/telescope.nvim", + requires = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "kyazdani42/nvim-web-devicons", + "nvim-telescope/telescope-ui-select.nvim", + {"nvim-telescope/telescope-fzf-native.nvim", run = "make"} + }, + load_config = true + } + + use { + "neovim/nvim-lspconfig", + config_name = "lspconfig" + } + + use { + 'williamboman/nvim-lsp-installer', + requires = 'neovim/nvim-lspconfig', + config_name = "lspinstaller" + } + + use { + "nvim-lualine/lualine.nvim", + requires = "kyazdani42/nvim-web-devicons", + load_config = true + } + + use { + 'rafcamlet/nvim-luapad', + config_name = "luapad" + } + + use "tpope/vim-eunuch" + use "christoomey/vim-tmux-navigator" + use "eandrju/cellular-automaton.nvim" + use "tweekmonster/startuptime.vim" + use "tpope/vim-unimpaired" + use { "sindrets/diffview.nvim", requires = 'nvim-lua/plenary.nvim' } + use "wellle/targets.vim" + use "michaeljsmith/vim-indent-object" + use "psliwka/vim-smoothie" + use "godlygeek/tabular" + use "editorconfig/editorconfig-vim" + use "tpope/vim-surround" + use "tpope/vim-repeat" + use "tikhomirov/vim-glsl" -- Debugger - use { 'mfussenegger/nvim-dap', config_name="dap" } + use { "mfussenegger/nvim-dap", config_name="dap" } use { "rcarriga/nvim-dap-ui", requires = "mfussenegger/nvim-dap", config=[[require('dapui').setup()]] } use 'simrat39/rust-tools.nvim' use { @@ -19,46 +90,6 @@ local function usePlugins(use, use_rocks) config=[[require('nvim-dap-virtual-text')]] } - -- Git blame - use { 'f-person/git-blame.nvim', config_name="gitblame" } - - use { 'trmckay/based.nvim', load_config = true } - - -- Seemless pane switching betwen tmux and vim - use 'christoomey/vim-tmux-navigator' - - -- UNIX commands - use 'tpope/vim-eunuch' - - use {'rafcamlet/nvim-luapad', config_name = "luapad"} - - use { 'fedepujol/move.nvim', load_config=true } - - -- fun - use {'eandrju/cellular-automaton.nvim', load_config = true} - - -- Movement utilities - use 'tpope/vim-unimpaired' - - -- LSP - use { 'neovim/nvim-lspconfig', config_name = "lspconfig" } - use { - 'williamboman/nvim-lsp-installer', - requires = 'neovim/nvim-lspconfig', - config_name = "lspinstaller" - } - - -- LSP utils - use {"ray-x/lsp_signature.nvim", config_name = "lspsignature"} - use { - 'RishabhRD/nvim-lsputils', - config_name = "lsputils", - requires = 'RishabhRD/popfix' - } - - -- Snippets - use { 'L3MON4D3/LuaSnip', config_name = "luasnip" } - -- Completion use { 'onsails/lspkind-nvim' } use { @@ -76,231 +107,20 @@ local function usePlugins(use, use_rocks) use {'hrsh7th/cmp-cmdline', after = 'nvim-cmp', requires = 'hrsh7th/nvim-cmp'} use {'saadparwaiz1/cmp_luasnip', after = 'nvim-cmp', requires = {'L3MON4D3/LuaSnip', 'nvim-cmp'}} - -- Better diagnostics viewer - use { - 'folke/trouble.nvim', - requires = 'kyazdani42/nvim-web-devicons', - load_config = true - } - - -- Color themes - use 'srcery-colors/srcery-vim' - -- use 'morhetz/gruvbox' - -- use 'tomasr/molokai' - -- use 'Mangeshrex/uwu.vim' - -- use 'ayu-theme/ayu-vim' - -- use 'sickill/vim-monokai' - -- use 'joshdick/onedark.vim' - -- use 'mswift42/vim-themes' - -- use 'squarefrog/tomorrow-night.vim' - -- use 'fnune/base16-vim' - - -- Text object target - use 'wellle/targets.vim' - - -- Git integration - use { 'tpope/vim-fugitive', config_name = "fugitive" } - use { - 'lewis6991/gitsigns.nvim', - requires = 'nvim-lua/plenary.nvim', - load_config = true - -- tag = 'release' -- To use the latest release - } - - -- Refactoring - -- use { - -- "ThePrimeagen/refactoring.nvim", - -- requires = { - -- "nvim-lua/plenary.nvim", - -- "nvim-treesitter/nvim-treesitter" - -- }, - -- disable = true, - -- config = [[require 'config.refactoring']] - -- } - - -- Analyze startup time - use 'tweekmonster/startuptime.vim' - - -- Status line and tab line - -- use { 'itchyny/lightline.vim', config = [[require 'config.lightline']]} - use { - 'nvim-lualine/lualine.nvim', - requires = 'kyazdani42/nvim-web-devicons', - load_config = true - } - - -- Load project specific settings from exrc - use { 'jenterkin/vim-autosource', config_name = "autosource" } - - -- Remove spaces at end of lines - use{ "mcauley-penney/tidy.nvim", config = [[require("tidy").setup()]] } + do -- Color themes + use 'srcery-colors/srcery-vim' + -- use 'morhetz/gruvbox' + -- use 'tomasr/molokai' + -- use 'Mangeshrex/uwu.vim' + -- use 'ayu-theme/ayu-vim' + -- use 'sickill/vim-monokai' + -- use 'joshdick/onedark.vim' + -- use 'mswift42/vim-themes' + -- use 'squarefrog/tomorrow-night.vim' + -- use 'fnune/base16-vim' + end -- Training plugins -- use 'tjdevries/train.nvim' -- use 'ThePrimeagen/vim-be-good' - - -- Quick movement - -- use { 'justinmk/vim-sneak', config = [[require 'config.sneak']] } - use { 'unblevable/quick-scope', config_name = "quickscope" } - use 'michaeljsmith/vim-indent-object' - use { 'ggandor/leap.nvim', load_config = "leap"} - - -- Smooth smooth scrolling - -- use { 'karb94/neoscroll.nvim', config = [[require('neoscroll').setup()]] } - use 'psliwka/vim-smoothie' - - -- Commenting - use { - 'terrortylor/nvim-comment', - config_name = "comment", - requires = 'JoosepAlviste/nvim-ts-context-commentstring' - } - - -- Color code colorizer - use { 'norcalli/nvim-colorizer.lua', config_name = "colorizer" } - - -- Fuzzy file finder - use { - 'nvim-telescope/telescope.nvim', - load_config = true, - requires = { - 'nvim-lua/plenary.nvim', - 'nvim-treesitter/nvim-treesitter', - 'kyazdani42/nvim-web-devicons', - {'nvim-telescope/telescope-fzf-native.nvim', run = 'make'} - } - } - - -- Align characters vertically - use 'godlygeek/tabular' - - -- Used for loading project specific code styles - use 'editorconfig/editorconfig-vim' - - -- Provides mappings for working with symbols like (), {}, [], etc. - use 'tpope/vim-surround' - - -- Allow repeating - use 'tpope/vim-repeat' - - -- GLSL language support - use 'tikhomirov/vim-glsl' - - -- Treesitter - use { - 'nvim-treesitter/nvim-treesitter', - config = [[require 'config.treesitter']], - run = function() require('nvim-treesitter.install').update{ with_sync = true } end - } - use { - 'nvim-treesitter/playground', - requires = 'nvim-treesitter/nvim-treesitter', - cmd = "TSPlaygroundToggle" - } - - -- Dev icons - use {'kyazdani42/nvim-web-devicons', config = [[require('nvim-web-devicons').setup()]]} - - -- File browser - use { - 'kyazdani42/nvim-tree.lua', - requires = 'kyazdani42/nvim-web-devicons', - config = [[require 'config.nvim-tree']] - } - -- use { - -- 'lambdalisue/fern.vim', - -- config = [[require 'config.fern']], - -- requires = { - -- 'antoinemadec/FixCursorHold.nvim', - -- 'lambdalisue/fern-hijack.vim', - -- {'lambdalisue/fern-renderer-nerdfont.vim', config = [[vim.g["fern#renderer"] = "nerdfont"]]}, - -- 'lambdalisue/nerdfont.vim' - -- } - -- } - -- alternatives: - -- use 'kyazdani42/nvim-tree.lua' - -- use 'zgpio/tree.nvim' - -- use 'tpope/vim-vinegar' end - --- Register custom commands for plugin manager -vim.cmd [[command! -bang -nargs=+ -complete=customlist,v:lua.require'plugins'.loader_complete PackerLoad lua require('plugins').loader(, '' == '!')]] -vim.cmd [[command! PackerInstall packadd packer.nvim | lua require('plugins').install()]] -vim.cmd [[command! PackerUpdate packadd packer.nvim | lua require('plugins').update()]] -vim.cmd [[command! PackerSync packadd packer.nvim | lua require('plugins').sync()]] -vim.cmd [[command! PackerClean packadd packer.nvim | lua require('plugins').clean()]] -vim.cmd [[command! PackerCompile source lua/plugins.lua | packadd packer.nvim | lua require('plugins').compile()]] - --- Bootstrap packer.nvim. If packer.nvim is not installed, install it. -local function bootstrap() - local fn = vim.fn - local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' - if fn.empty(fn.glob(install_path)) > 0 then - return fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) - end -end - -local function create_custom_use(use) - return function (opts) - if type(opts) == "string" then - use(opts) - return opts - elseif type(opts) == "table" then - if opts.load_config then - local name = vim.split(opts[1], "/")[2] - if name:match("%.nvim$") then - name = name:sub(1, -6) - end - opts.config_name = name - end - if opts.config_name then - opts.config = ("require('config.%s')"):format(opts.config_name) - end - use(opts) - - return opts[1] - else - error("What are you doing???") - end - end -end - -local packer = nil -local function init() - -- Perform bootstrap - local packer_bootstrap = bootstrap() - - -- Initialize packer - if packer == nil then - packer = require 'packer' - local util = require 'packer.util' - packer.init { - compile_path = util.join_paths(vim.fn.stdpath('config'), 'plugin', 'packer-compiled.lua'), - disable_commands = true - } - end - - -- Reset plugins if already loaded - packer.reset() - - -- Packer can manage itself - packer.use 'wbthomason/packer.nvim' - - -- Use plugins - usePlugins(create_custom_use(packer.use), packer.use_rocks) - - -- Automatically set up your configuration after cloning packer.nvim - -- Put this at the end after all plugins - if packer_bootstrap then - require('packer').sync() - end -end - -local plugins = setmetatable({}, { - __index = function(_, key) - init() - return packer[key] - end, -}) - -return plugins