From 26b5b21aa403d2ffcfce06f579809ab0b0b8179e Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 18:26:43 -0600 Subject: [PATCH] refactor large plugin files into modules --- lua/plugins.lua | 158 --------------------------------- lua/plugins/autocompletion.lua | 16 ++++ lua/plugins/blankline.lua | 5 ++ lua/plugins/gitsigns.lua | 73 +++++++++++++++ lua/plugins/lspconfig.lua | 14 +++ lua/plugins/lualine.lua | 12 +++ lua/plugins/telescope.lua | 16 ++++ lua/plugins/treesitter.lua | 7 ++ 8 files changed, 143 insertions(+), 158 deletions(-) create mode 100644 lua/plugins/autocompletion.lua create mode 100644 lua/plugins/blankline.lua create mode 100644 lua/plugins/gitsigns.lua create mode 100644 lua/plugins/lspconfig.lua create mode 100644 lua/plugins/lualine.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/treesitter.lua diff --git a/lua/plugins.lua b/lua/plugins.lua index f0377166..df718056 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,168 +1,10 @@ return { - -- Git related plugins 'tpope/vim-fugitive', 'tpope/vim-rhubarb', - - -- Detect tabstop and shiftwidth automatically 'tpope/vim-sleuth', - - { - -- LSP Configuration & Plugins - 'neovim/nvim-lspconfig', - dependencies = { - 'williamboman/mason.nvim', - 'williamboman/mason-lspconfig.nvim', - - -- Useful status updates for LSP - { 'j-hui/fidget.nvim', opts = {} }, - - -- Additional lua configuration, makes nvim stuff amazing! - 'folke/neodev.nvim', - }, - }, - - { - -- Autocompletion - 'hrsh7th/nvim-cmp', - dependencies = { - -- Snippet Engine & its associated nvim-cmp source - 'L3MON4D3/LuaSnip', - 'saadparwaiz1/cmp_luasnip', - - -- Adds LSP completion capabilities - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-path', - - -- Adds a number of user-friendly snippets - 'rafamadriz/friendly-snippets', - }, - }, - - -- Useful plugin to show you pending keybinds. { 'folke/which-key.nvim', opts = {} }, - { - -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - on_attach = function(bufnr) - local gs = package.loaded.gitsigns - - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) - end - - -- Navigation - map({ 'n', 'v' }, ']c', function() - if vim.wo.diff then - return ']c' - end - vim.schedule(function() - gs.next_hunk() - end) - return '' - end, { expr = true, desc = 'Jump to next hunk' }) - - map({ 'n', 'v' }, '[c', function() - if vim.wo.diff then - return '[c' - end - vim.schedule(function() - gs.prev_hunk() - end) - return '' - end, { expr = true, desc = 'Jump to previous hunk' }) - - -- Actions - -- visual mode - map('v', 'hs', function() - gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } - end, { desc = 'stage git hunk' }) - map('v', 'hr', function() - gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } - end, { desc = 'reset git hunk' }) - -- normal mode - map('n', 'hs', gs.stage_hunk, { desc = 'git stage hunk' }) - map('n', 'hr', gs.reset_hunk, { desc = 'git reset hunk' }) - map('n', 'hS', gs.stage_buffer, { desc = 'git Stage buffer' }) - map('n', 'hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' }) - map('n', 'hR', gs.reset_buffer, { desc = 'git Reset buffer' }) - map('n', 'hp', gs.preview_hunk, { desc = 'preview git hunk' }) - map('n', 'hb', function() - gs.blame_line { full = false } - end, { desc = 'git blame line' }) - map('n', 'hd', gs.diffthis, { desc = 'git diff against index' }) - map('n', 'hD', function() - gs.diffthis '~' - end, { desc = 'git diff against last commit' }) - - -- Toggles - map('n', 'tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' }) - map('n', 'td', gs.toggle_deleted, { desc = 'toggle git show deleted' }) - - -- Text object - map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) - end, - }, - }, - - { - -- Set lualine as statusline - 'nvim-lualine/lualine.nvim', - opts = { - options = { - icons_enabled = false, - theme = 'onedark', - component_separators = '|', - section_separators = '', - }, - }, - }, - - { - -- Add indentation guides even on blank lines - 'lukas-reineke/indent-blankline.nvim', - main = 'ibl', - opts = {}, - }, - - -- "gc" to comment visual regions/lines { 'numToStr/Comment.nvim', opts = {} }, - -- Fuzzy Finder (files, lsp, etc) - { - 'nvim-telescope/telescope.nvim', - branch = '0.1.x', - dependencies = { - 'nvim-lua/plenary.nvim', - -- Fuzzy Finder Algorithm which requires local dependencies to be built. - { - 'nvim-telescope/telescope-fzf-native.nvim', - build = 'make', - cond = function() - return vim.fn.executable 'make' == 1 - end, - }, - }, - }, - - { - -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - }, - build = ':TSUpdate', - }, - -- require 'kickstart.plugins.autoformat', -- require 'kickstart.plugins.debug', }; diff --git a/lua/plugins/autocompletion.lua b/lua/plugins/autocompletion.lua new file mode 100644 index 00000000..b92b6da2 --- /dev/null +++ b/lua/plugins/autocompletion.lua @@ -0,0 +1,16 @@ +return { + -- Autocompletion + 'hrsh7th/nvim-cmp', + dependencies = { + -- Snippet Engine & its associated nvim-cmp source + 'L3MON4D3/LuaSnip', + 'saadparwaiz1/cmp_luasnip', + + -- Adds LSP completion capabilities + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', + + -- Adds a number of user-friendly snippets + 'rafamadriz/friendly-snippets', + } +} diff --git a/lua/plugins/blankline.lua b/lua/plugins/blankline.lua new file mode 100644 index 00000000..91babce6 --- /dev/null +++ b/lua/plugins/blankline.lua @@ -0,0 +1,5 @@ +return { + 'lukas-reineke/indent-blankline.nvim', + main = 'ibl', + opts = {}, +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 00000000..0b1c7378 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,73 @@ +return { + -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + opts = { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map({ 'n', 'v' }, ']c', function() + if vim.wo.diff then + return ']c' + end + vim.schedule(function() + gs.next_hunk() + end) + return '' + end, { expr = true, desc = 'Jump to next hunk' }) + + map({ 'n', 'v' }, '[c', function() + if vim.wo.diff then + return '[c' + end + vim.schedule(function() + gs.prev_hunk() + end) + return '' + end, { expr = true, desc = 'Jump to previous hunk' }) + + -- Actions + -- visual mode + map('v', 'hs', function() + gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'stage git hunk' }) + map('v', 'hr', function() + gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'reset git hunk' }) + -- normal mode + map('n', 'hs', gs.stage_hunk, { desc = 'git stage hunk' }) + map('n', 'hr', gs.reset_hunk, { desc = 'git reset hunk' }) + map('n', 'hS', gs.stage_buffer, { desc = 'git Stage buffer' }) + map('n', 'hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' }) + map('n', 'hR', gs.reset_buffer, { desc = 'git Reset buffer' }) + map('n', 'hp', gs.preview_hunk, { desc = 'preview git hunk' }) + map('n', 'hb', function() + gs.blame_line { full = false } + end, { desc = 'git blame line' }) + map('n', 'hd', gs.diffthis, { desc = 'git diff against index' }) + map('n', 'hD', function() + gs.diffthis '~' + end, { desc = 'git diff against last commit' }) + + -- Toggles + map('n', 'tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' }) + map('n', 'td', gs.toggle_deleted, { desc = 'toggle git show deleted' }) + + -- Text object + map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) + end + } +} diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua new file mode 100644 index 00000000..b28c83b1 --- /dev/null +++ b/lua/plugins/lspconfig.lua @@ -0,0 +1,14 @@ +return { + -- LSP Configuration & Plugins + 'neovim/nvim-lspconfig', + dependencies = { + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + + -- Useful status updates for LSP + { 'j-hui/fidget.nvim', opts = {} }, + + -- Additional lua configuration, makes nvim stuff amazing! + 'folke/neodev.nvim', + } +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 00000000..074ea501 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,12 @@ +return { + -- Set lualine as statusline + 'nvim-lualine/lualine.nvim', + opts = { + options = { + icons_enabled = false, + theme = 'onedark', + component_separators = '|', + section_separators = '', + } + } +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 00000000..1fcfda56 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,16 @@ +return { + 'nvim-telescope/telescope.nvim', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + + -- Fuzzy Finder Algorithm which requires local dependencies to be built. + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'make', + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + }, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 00000000..a3e92911 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,7 @@ +return { + 'nvim-treesitter/nvim-treesitter', + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', + }, + build = ':TSUpdate', +}