From 67f0f6ffbf56e74740d62f86d71b5ab41aa11fd4 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 17:13:29 -0600 Subject: [PATCH 01/13] refactor plugin installation to plugins folder --- init.lua | 181 +----------------------------------------------- lua/plugins.lua | 179 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 180 deletions(-) create mode 100644 lua/plugins.lua diff --git a/init.lua b/init.lua index eec899a9..09f56b8a 100644 --- a/init.lua +++ b/init.lua @@ -17,186 +17,7 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) --- [[ Configure plugins ]] -require('lazy').setup({ - -- 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, - }, - }, - - { - -- Theme inspired by Atom - 'navarasu/onedark.nvim', - priority = 1000, - config = function() - vim.cmd.colorscheme 'onedark' - 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', - - { import = 'custom.plugins' }, -}, {}) +require('lazy').setup('plugins'); -- [[ Setting options ]] diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 00000000..f544cbb2 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,179 @@ +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, + }, + }, + + { + -- Theme inspired by Atom + 'navarasu/onedark.nvim', + priority = 1000, + config = function() + vim.cmd.colorscheme 'onedark' + 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', + + { import = 'custom.plugins' }, +}; From 0a67a2effdfdad42379da9c3b5579b00aab60ac8 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 17:21:28 -0600 Subject: [PATCH 02/13] modularize all custom plugins --- lua/custom/plugins/init.lua | 23 ----------------------- lua/plugins.lua | 2 -- lua/plugins/catpuccin.lua | 1 + lua/plugins/oil.lua | 1 + lua/plugins/rust.lua | 7 +++++++ lua/plugins/todocomments.lua | 4 ++++ 6 files changed, 13 insertions(+), 25 deletions(-) delete mode 100644 lua/custom/plugins/init.lua create mode 100644 lua/plugins/catpuccin.lua create mode 100644 lua/plugins/oil.lua create mode 100644 lua/plugins/rust.lua create mode 100644 lua/plugins/todocomments.lua diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua deleted file mode 100644 index d1f16ecf..00000000 --- a/lua/custom/plugins/init.lua +++ /dev/null @@ -1,23 +0,0 @@ -return { - -- File Browser - { 'stevearc/oil.nvim' }, - - -- Rust Format on Save - { - 'rust-lang/rust.vim', - ft = "rust", - init = function () - vim.g.rustfmt_autosave = 1 - end - }, - - -- Theme - { 'catppuccin/nvim', name='catppuccin', priority = 1000 }, - - -- Better Comments - { - 'folke/todo-comments.nvim', - dependencies = { 'nvim-lua//plenary.nvim' } - }, -} - diff --git a/lua/plugins.lua b/lua/plugins.lua index f544cbb2..1c9e767b 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -174,6 +174,4 @@ return { -- require 'kickstart.plugins.autoformat', -- require 'kickstart.plugins.debug', - - { import = 'custom.plugins' }, }; diff --git a/lua/plugins/catpuccin.lua b/lua/plugins/catpuccin.lua new file mode 100644 index 00000000..56b8bb9a --- /dev/null +++ b/lua/plugins/catpuccin.lua @@ -0,0 +1 @@ +return { 'catppuccin/nvim', name='catppuccin', priority = 1000 }; diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua new file mode 100644 index 00000000..2950bbf7 --- /dev/null +++ b/lua/plugins/oil.lua @@ -0,0 +1 @@ +return { 'stevearc/oil.nvim' }; diff --git a/lua/plugins/rust.lua b/lua/plugins/rust.lua new file mode 100644 index 00000000..e2a56aec --- /dev/null +++ b/lua/plugins/rust.lua @@ -0,0 +1,7 @@ +return { + 'rust-lang/rust.vim', + ft = "rust", + init = function () + vim.g.rustfmt_autosave = 1 + end +}; diff --git a/lua/plugins/todocomments.lua b/lua/plugins/todocomments.lua new file mode 100644 index 00000000..165d8eae --- /dev/null +++ b/lua/plugins/todocomments.lua @@ -0,0 +1,4 @@ +return { + 'folke/todo-comments.nvim', + dependencies = { 'nvim-lua//plenary.nvim' } +}; From e31671d714905418ff44037562e53a8c4b432e80 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 17:25:12 -0600 Subject: [PATCH 03/13] remove unused theme --- lua/plugins.lua | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lua/plugins.lua b/lua/plugins.lua index 1c9e767b..f0377166 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -114,15 +114,6 @@ return { }, }, - { - -- Theme inspired by Atom - 'navarasu/onedark.nvim', - priority = 1000, - config = function() - vim.cmd.colorscheme 'onedark' - end, - }, - { -- Set lualine as statusline 'nvim-lualine/lualine.nvim', From a65fbaf5baa484d059a9b5cee5fa3deb75151a45 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 17:51:47 -0600 Subject: [PATCH 04/13] configure catpuccin in module --- init.lua | 14 -------------- lua/plugins/catpuccin.lua | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index 09f56b8a..25c6e8d7 100644 --- a/init.lua +++ b/init.lua @@ -375,20 +375,6 @@ vim.keymap.set('n', '-', 'Oil --float', { desc = 'Open current -- Configure Todo-Comments require('todo-comments').setup() --- Configure Theme -require('catppuccin').setup({ - flavour = 'macchiato', - no_italic = false, - styles = { - comments = { 'italic' }, - conditionals = { 'italic' }, - }, - integrations = { - treesitter = true, - }, -}) - -vim.cmd.colorscheme 'catppuccin' vim.opt.spell = true vim.opt.spelloptions = 'camel' diff --git a/lua/plugins/catpuccin.lua b/lua/plugins/catpuccin.lua index 56b8bb9a..ade84e6c 100644 --- a/lua/plugins/catpuccin.lua +++ b/lua/plugins/catpuccin.lua @@ -1 +1,16 @@ -return { 'catppuccin/nvim', name='catppuccin', priority = 1000 }; +return { 'catppuccin/nvim', name='catppuccin', priority = 1000, + config = function() + require('catppuccin').setup({ + flavour = "macchiato", + no_italic = false, + styles = { + comments = { 'italic' }, + conditionals = { 'italic' }, + }, + integrations = { + treesitter = true, + } + }) + vim.cmd.colorscheme 'catppuccin' + end +}; From 216440979eca0204befe1089ac3c35075ddd46fa Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 17:56:35 -0600 Subject: [PATCH 05/13] handle setup for all custom plugins in their respective modules --- init.lua | 6 ------ lua/plugins/oil.lua | 7 ++++++- lua/plugins/todocomments.lua | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/init.lua b/init.lua index 25c6e8d7..e16d1b43 100644 --- a/init.lua +++ b/init.lua @@ -368,12 +368,6 @@ cmp.setup { { name = 'path' }, }, } --- Configure Oil -require('oil').setup() -vim.keymap.set('n', '-', 'Oil --float', { desc = 'Open current directory' }) - --- Configure Todo-Comments -require('todo-comments').setup() vim.opt.spell = true vim.opt.spelloptions = 'camel' diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua index 2950bbf7..36593445 100644 --- a/lua/plugins/oil.lua +++ b/lua/plugins/oil.lua @@ -1 +1,6 @@ -return { 'stevearc/oil.nvim' }; +return { 'stevearc/oil.nvim', + config = function() + require("oil").setup(); + vim.keymap.set('n', '-', 'Oil --float', { desc = 'Open current directory' }) + end +}; diff --git a/lua/plugins/todocomments.lua b/lua/plugins/todocomments.lua index 165d8eae..2797ff53 100644 --- a/lua/plugins/todocomments.lua +++ b/lua/plugins/todocomments.lua @@ -1,4 +1,5 @@ return { 'folke/todo-comments.nvim', - dependencies = { 'nvim-lua//plenary.nvim' } + dependencies = { 'nvim-lua//plenary.nvim' }, + config = {} }; From 26b5b21aa403d2ffcfce06f579809ab0b0b8179e Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 18:26:43 -0600 Subject: [PATCH 06/13] 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', +} From bee32df567610b374cab920ff21cc02442adc035 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 18:36:07 -0600 Subject: [PATCH 07/13] create and configure whichkey module --- init.lua | 21 --------------------- lua/plugins.lua | 1 - lua/plugins/whichkey.lua | 20 ++++++++++++++++++++ 3 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 lua/plugins/whichkey.lua diff --git a/init.lua b/init.lua index e16d1b43..aa38724e 100644 --- a/init.lua +++ b/init.lua @@ -1,9 +1,6 @@ --- Set as the leader key vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' --- [[ Install `lazy.nvim` plugin manager ]] --- https://github.com/folke/lazy.nvim local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not vim.loop.fs_stat(lazypath) then vim.fn.system { @@ -16,7 +13,6 @@ if not vim.loop.fs_stat(lazypath) then } end vim.opt.rtp:prepend(lazypath) - require('lazy').setup('plugins'); -- [[ Setting options ]] @@ -272,23 +268,6 @@ local on_attach = function(_, bufnr) end, { desc = 'Format current buffer with LSP' }) end --- document existing key chains -require('which-key').register { - ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, - ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, - ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, - ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, - ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, - ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, - ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, - ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, -} --- register which-key VISUAL mode -require('which-key').register({ - [''] = { name = 'VISUAL ' }, - ['h'] = { 'Git [H]unk' }, -}, { mode = 'v' }) - -- mason-lspconfig requires that these setup functions are called in this order -- before setting up the servers. require('mason').setup() diff --git a/lua/plugins.lua b/lua/plugins.lua index df718056..ef1a1c08 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -2,7 +2,6 @@ return { 'tpope/vim-fugitive', 'tpope/vim-rhubarb', 'tpope/vim-sleuth', - { 'folke/which-key.nvim', opts = {} }, { 'numToStr/Comment.nvim', opts = {} }, -- require 'kickstart.plugins.autoformat', diff --git a/lua/plugins/whichkey.lua b/lua/plugins/whichkey.lua new file mode 100644 index 00000000..7dc820a9 --- /dev/null +++ b/lua/plugins/whichkey.lua @@ -0,0 +1,20 @@ +return { 'folke/which-key.nvim', opts = {}, + config = function() + -- document existing key chains + require('which-key').register { + ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, + ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, + ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, + ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, + ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, + ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + } + -- register which-key VISUAL mode + require('which-key').register({ + [''] = { name = 'VISUAL ' }, + ['h'] = { 'Git [H]unk' }, + }, { mode = 'v' }) + end +} From 4840b5d97fdedf441585b677e46fe8ee98fbb36f Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 19:01:16 -0600 Subject: [PATCH 08/13] configure treesiter in treesitter module --- init.lua | 67 ----------------------------------- lua/plugins/treesitter.lua | 71 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 67 deletions(-) diff --git a/init.lua b/init.lua index aa38724e..a4818e3c 100644 --- a/init.lua +++ b/init.lua @@ -164,73 +164,6 @@ vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) --- [[ Configure Treesitter ]] -vim.defer_fn(function() - require('nvim-treesitter.configs').setup { - -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' }, - - -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) - auto_install = false, - - highlight = { enable = true }, - indent = { enable = true }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', - }, - }, - textobjects = { - select = { - enable = true, - lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim - keymaps = { - -- You can use the capture groups defined in textobjects.scm - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@class.outer', - ['ic'] = '@class.inner', - }, - }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - [']m'] = '@function.outer', - [']]'] = '@class.outer', - }, - goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', - }, - goto_previous_start = { - ['[m'] = '@function.outer', - ['[['] = '@class.outer', - }, - goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', - }, - }, - swap = { - enable = true, - swap_next = { - ['a'] = '@parameter.inner', - }, - swap_previous = { - ['A'] = '@parameter.inner', - }, - }, - }, - } -end, 0) - -- [[ Configure LSP ]] local on_attach = function(_, bufnr) local nmap = function(keys, func, desc) diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index a3e92911..f440189e 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -1,7 +1,78 @@ +local text_objects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + [']m'] = '@function.outer', + [']]'] = '@class.outer', + }, + goto_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', + }, + goto_previous_start = { + ['[m'] = '@function.outer', + ['[['] = '@class.outer', + }, + goto_previous_end = { + ['[M'] = '@function.outer', + ['[]'] = '@class.outer', + }, + }, + swap = { + enable = true, + swap_next = { + ['a'] = '@parameter.inner', + }, + swap_previous = { + ['A'] = '@parameter.inner', + }, + }, +} + return { 'nvim-treesitter/nvim-treesitter', dependencies = { 'nvim-treesitter/nvim-treesitter-textobjects', }, build = ':TSUpdate', + config = function() + vim.defer_fn(function() + -- FIX: Missing required fields in type `TSConfig` + require('nvim-treesitter.configs').setup { + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' }, + + -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) + auto_install = false, + + highlight = { enable = true }, + indent = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + scope_incremental = '', + node_decremental = '', + }, + }, + textobjects = text_objects, + } + end, 0) + end } + From 3831de930ca772a60303e8e5711aae94929ee6ab Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 19:10:02 -0600 Subject: [PATCH 09/13] refactor vim options into new file --- init.lua | 74 ++---------------------------------------------- lua/settings.lua | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 72 deletions(-) create mode 100644 lua/settings.lua diff --git a/init.lua b/init.lua index a4818e3c..288ce8f2 100644 --- a/init.lua +++ b/init.lua @@ -13,79 +13,9 @@ if not vim.loop.fs_stat(lazypath) then } end vim.opt.rtp:prepend(lazypath) + require('lazy').setup('plugins'); - --- [[ Setting options ]] - --- Line numbers -vim.opt.nu = true -vim.opt.relativenumber = true - --- Highlighting on search -vim.opt.hlsearch = true -vim.opt.incsearch = true - --- Enable mouse mode -vim.opt.mouse = '' - --- Sync clipboard between OS and Neovim. -vim.opt.clipboard = 'unnamedplus' - --- Handle indentation -vim.opt.tabstop = 4 -vim.opt.softtabstop = 4 -vim.opt.shiftwidth = 4 -vim.opt.expandtab = true -vim.opt.smartindent = true -vim.opt.breakindent = true - --- Remove line wrapping -vim.opt.wrap = false - --- Scroll buffer -vim.opt.scrolloff = 8 - --- Save undo history -vim.o.undofile = true - --- Case-insensitive searching UNLESS \C or capital in search -vim.o.ignorecase = true -vim.o.smartcase = true - --- Keep signcolumn on by default -vim.wo.signcolumn = 'yes' - --- Decrease update time -vim.o.updatetime = 250 -vim.o.timeoutlen = 300 - --- Set completeopt to have a better completion experience -vim.o.completeopt = 'menuone,noselect' - -vim.o.termguicolors = true - --- [[ Basic Keymaps ]] -vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) - --- Remap for dealing with word wrap -vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) -vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) - --- Diagnostic keymaps -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) - --- [[ Highlight on yank ]] -local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) -vim.api.nvim_create_autocmd('TextYankPost', { - callback = function() - vim.highlight.on_yank() - end, - group = highlight_group, - pattern = '*', -}) +require('lua/settings'); -- [[ Configure Telescope ]] require('telescope').setup { diff --git a/lua/settings.lua b/lua/settings.lua new file mode 100644 index 00000000..905f368f --- /dev/null +++ b/lua/settings.lua @@ -0,0 +1,72 @@ +-- Line numbers +vim.opt.nu = true +vim.opt.relativenumber = true + +-- Highlighting on search +vim.opt.hlsearch = true +vim.opt.incsearch = true + +-- Enable mouse mode +vim.opt.mouse = '' + +-- FIX: shared clipboard not working +-- Sync clipboard between OS and Neovim. +vim.opt.clipboard = 'unnamedplus' + +-- FIX: tabs do not seem to be working as expected +-- Handle indentation +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true +vim.opt.smartindent = true +vim.opt.breakindent = true + +-- Remove line wrapping +vim.opt.wrap = false + +-- Scroll buffer +vim.opt.scrolloff = 8 + +-- Save undo history +vim.o.undofile = true + +-- Case-insensitive searching UNLESS \C or capital in search +vim.o.ignorecase = true +vim.o.smartcase = true + +-- Keep signcolumn on by default +vim.wo.signcolumn = 'yes' + +-- Decrease update time +vim.o.updatetime = 250 +vim.o.timeoutlen = 300 + +-- Set completeopt to have a better completion experience +vim.o.completeopt = 'menuone,noselect' + +vim.o.termguicolors = true + +-- [[ Basic Keymaps ]] +vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) + +-- Remap for dealing with word wrap +vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) +vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) + +-- Diagnostic keymaps +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) + +-- Highlight on yank +local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) +vim.api.nvim_create_autocmd('TextYankPost', { + callback = function() + vim.highlight.on_yank() + end, + group = highlight_group, + pattern = '*', +}) + From 8b6091717a7a64c282e12951553d62b93f6108c5 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 19:25:01 -0600 Subject: [PATCH 10/13] configure telescope from telescope module --- init.lua | 76 --------------------------------------- lua/plugins/telescope.lua | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 76 deletions(-) diff --git a/init.lua b/init.lua index 288ce8f2..c3185061 100644 --- a/init.lua +++ b/init.lua @@ -18,82 +18,6 @@ require('lazy').setup('plugins'); require('lua/settings'); -- [[ Configure Telescope ]] -require('telescope').setup { - defaults = { - mappings = { - i = { - [''] = false, - [''] = false, - }, - }, - }, -} - --- Enable telescope fzf native, if installed -pcall(require('telescope').load_extension, 'fzf') - --- Telescope live_grep in git root --- Function to find the git root directory based on the current buffer's path -local function find_git_root() - -- Use the current buffer's path as the starting point for the git search - local current_file = vim.api.nvim_buf_get_name(0) - local current_dir - local cwd = vim.fn.getcwd() - -- If the buffer is not associated with a file, return nil - if current_file == '' then - current_dir = cwd - else - -- Extract the directory from the current file's path - current_dir = vim.fn.fnamemodify(current_file, ':h') - end - - -- Find the Git root directory from the current file's path - local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] - if vim.v.shell_error ~= 0 then - print 'Not a git repository. Searching on current working directory' - return cwd - end - return git_root -end - --- Custom live_grep function to search in git root -local function live_grep_git_root() - local git_root = find_git_root() - if git_root then - require('telescope.builtin').live_grep { - search_dirs = { git_root }, - } - end -end - -vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) - -vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) -vim.keymap.set('n', '', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) -vim.keymap.set('n', '/', function() - require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) -end, { desc = '[/] Fuzzily search in current buffer' }) - -local function telescope_live_grep_open_files() - require('telescope.builtin').live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } -end -vim.keymap.set('n', 's/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' }) -vim.keymap.set('n', 'ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' }) -vim.keymap.set('n', 'gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) -vim.keymap.set('n', 'sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) -vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) -vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) -vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) -vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by [G]rep on Git Root' }) -vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) -vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) - -- [[ Configure LSP ]] local on_attach = function(_, bufnr) local nmap = function(keys, func, desc) diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 1fcfda56..aa12e1ca 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -1,3 +1,31 @@ +local function telescope_live_grep_open_files() + require('telescope.builtin').live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } +end + +local function keymaps() + vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) + vim.keymap.set('n', '', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', '/', function() + require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, { desc = '[/] Fuzzily search in current buffer' }) + vim.keymap.set('n', 's/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' }) + vim.keymap.set('n', 'ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' }) + vim.keymap.set('n', 'gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) + vim.keymap.set('n', 'sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) + vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by [G]rep on Git Root' }) + vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) + vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) +end + return { 'nvim-telescope/telescope.nvim', branch = '0.1.x', @@ -13,4 +41,49 @@ return { end, }, }, + config = function() + require('telescope').setup { + defaults = { + mappings = { + i = { + [''] = false, + [''] = false, + }, + }, + }, + } + + pcall(require('telescope').load_extension, 'fzf') + + local function find_git_root() + local current_file = vim.api.nvim_buf_get_name(0) + local current_dir + local cwd = vim.fn.getcwd() + if current_file == '' then + current_dir = cwd + else + current_dir = vim.fn.fnamemodify(current_file, ':h') + end + + local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] + if vim.v.shell_error ~= 0 then + print 'Not a git repository. Searching on current working directory' + return cwd + end + return git_root + end + + local function live_grep_git_root() + local git_root = find_git_root() + if git_root then + require('telescope.builtin').live_grep { + search_dirs = { git_root }, + } + end + end + + vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) + + keymaps() + end } From 5f50cd8368e4da96e14e5e8b3eb2c6c818379a42 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 19:38:53 -0600 Subject: [PATCH 11/13] configure lsp config from lsp config module --- init.lua | 87 --------------------------------------- lua/plugins/lspconfig.lua | 86 +++++++++++++++++++++++++++++++++++++- lua/settings.lua | 4 ++ 3 files changed, 89 insertions(+), 88 deletions(-) diff --git a/init.lua b/init.lua index c3185061..dd3239fb 100644 --- a/init.lua +++ b/init.lua @@ -17,91 +17,6 @@ vim.opt.rtp:prepend(lazypath) require('lazy').setup('plugins'); require('lua/settings'); --- [[ Configure Telescope ]] --- [[ Configure LSP ]] -local on_attach = function(_, bufnr) - local nmap = function(keys, func, desc) - if desc then - desc = 'LSP: ' .. desc - end - - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) - end - - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - - nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - nmap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') - nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') - - -- Lesser used LSP functionality - nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') - nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') - nmap('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, '[W]orkspace [L]ist Folders') - - -- Create a command `:Format` local to the LSP buffer - vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) - vim.lsp.buf.format() - end, { desc = 'Format current buffer with LSP' }) -end - --- mason-lspconfig requires that these setup functions are called in this order --- before setting up the servers. -require('mason').setup() -require('mason-lspconfig').setup() - --- Enable the following language servers -local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, - rust_analyzer = { filetypes = {'rust', 'rs'}}, - tsserver = {}, - -- html = { filetypes = { 'html', 'twig', 'hbs'} }, - - lua_ls = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, - }, - }, -} - --- Setup neovim lua configuration -require('neodev').setup() - --- nvim-cmp supports additional completion capabilities, so broadcast that to servers -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - --- Ensure the servers above are installed -local mason_lspconfig = require 'mason-lspconfig' - -mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers), -} - -mason_lspconfig.setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = capabilities, - on_attach = on_attach, - settings = servers[server_name], - filetypes = (servers[server_name] or {}).filetypes, - } - end, -} - -- [[ Configure nvim-cmp ]] local cmp = require 'cmp' local luasnip = require 'luasnip' @@ -135,7 +50,5 @@ cmp.setup { }, } -vim.opt.spell = true -vim.opt.spelloptions = 'camel' -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index b28c83b1..122cda60 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -1,3 +1,34 @@ +local function keymaps(bufnr) + local keymap = function(keys, func, desc) + if desc then + desc = 'LSP: ' .. desc + end + + vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) + end + + keymap('rn', vim.lsp.buf.rename, '[R]e[n]ame') + keymap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + + keymap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + keymap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + keymap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + keymap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + keymap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + keymap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + + keymap('K', vim.lsp.buf.hover, 'Hover Documentation') + keymap('', vim.lsp.buf.signature_help, 'Signature Documentation') + + -- Lesser used LSP functionality + keymap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + keymap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') + keymap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') + keymap('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, '[W]orkspace [L]ist Folders') +end + return { -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', @@ -10,5 +41,58 @@ return { -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', - } + }, + config = function() + local on_attach = function(_, bufnr) + keymaps(bufnr) + + -- Create a command `:Format` local to the LSP buffer + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) + vim.lsp.buf.format() + end, { desc = 'Format current buffer with LSP' }) + end + + -- mason-lspconfig requires that these setup functions are called in this order + -- before setting up the servers. + require('mason').setup() + require('mason-lspconfig').setup() + + -- Enable the following language servers + local servers = { + rust_analyzer = { filetypes = {'rust', 'rs'}}, + tsserver = {}, + lua_ls = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + }, + } + + -- Setup neovim lua configuration + require('neodev').setup() + + -- nvim-cmp supports additional completion capabilities, so broadcast that to servers + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + + -- Ensure the servers above are installed + local mason_lspconfig = require 'mason-lspconfig' + + mason_lspconfig.setup { + ensure_installed = vim.tbl_keys(servers), + } + + mason_lspconfig.setup_handlers { + function(server_name) + require('lspconfig')[server_name].setup { + capabilities = capabilities, + on_attach = on_attach, + settings = servers[server_name], + filetypes = (servers[server_name] or {}).filetypes, + } + end, + } + + end } diff --git a/lua/settings.lua b/lua/settings.lua index 905f368f..d793e745 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -13,6 +13,10 @@ vim.opt.mouse = '' -- Sync clipboard between OS and Neovim. vim.opt.clipboard = 'unnamedplus' +-- Enable spell check +vim.opt.spell = true +vim.opt.spelloptions = 'camel' + -- FIX: tabs do not seem to be working as expected -- Handle indentation vim.opt.tabstop = 4 From 684fcff874d2938f9254e86f75bc219b0a0e6bb6 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 19:42:29 -0600 Subject: [PATCH 12/13] handle autocomplete setup from autocomplete module --- init.lua | 34 --------------------------------- lua/plugins/autocompletion.lua | 35 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/init.lua b/init.lua index dd3239fb..1ebbe5ed 100644 --- a/init.lua +++ b/init.lua @@ -17,38 +17,4 @@ vim.opt.rtp:prepend(lazypath) require('lazy').setup('plugins'); require('lua/settings'); --- [[ Configure nvim-cmp ]] -local cmp = require 'cmp' -local luasnip = require 'luasnip' -require('luasnip.loaders.from_vscode').lazy_load() -luasnip.config.setup {} - -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - completion = { - completeopt = 'menu,menuone,noinsert', - }, - mapping = cmp.mapping.preset.insert { - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete {}, - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - }, -} - - -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/plugins/autocompletion.lua b/lua/plugins/autocompletion.lua index b92b6da2..a85c7202 100644 --- a/lua/plugins/autocompletion.lua +++ b/lua/plugins/autocompletion.lua @@ -12,5 +12,38 @@ return { -- Adds a number of user-friendly snippets 'rafamadriz/friendly-snippets', - } + }, + config = function() + local cmp = require 'cmp' + local luasnip = require 'luasnip' + require('luasnip.loaders.from_vscode').lazy_load() + luasnip.config.setup {} + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { + completeopt = 'menu,menuone,noinsert', + }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete {}, + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }, + } + end } From 3493e38f5e5cc4dfdfd72dee93f2b4bc5077ca70 Mon Sep 17 00:00:00 2001 From: Nick Burt Date: Mon, 8 Jan 2024 22:18:01 -0600 Subject: [PATCH 13/13] fix setting path --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 1ebbe5ed..625c2f24 100644 --- a/init.lua +++ b/init.lua @@ -15,6 +15,6 @@ end vim.opt.rtp:prepend(lazypath) require('lazy').setup('plugins'); -require('lua/settings'); +require('settings'); -- vim: ts=2 sts=2 sw=2 et