|
240 | 240 | end |
241 | 241 |
|
242 | 242 | -- ============================================================ |
243 | | --- SECTION 2: PLUGIN MANAGER |
244 | | --- vim.pack, build hooks, install/update plugins, plugin specs |
| 243 | +-- SECTION 2: PLUGIN MANAGER INTRO |
| 244 | +-- vim.pack intro, build hooks |
245 | 245 | -- ============================================================ |
246 | 246 | do |
247 | | - -- [[ Install plugins with `vim.pack` ]] |
| 247 | + -- [[ Intro to `vim.pack` ]] |
| 248 | + -- `vim.pack` is a new plugin manager built into Neovim, |
| 249 | + -- which provides a Lua interface for installing and managing plugins. |
| 250 | + -- |
248 | 251 | -- See `:help vim.pack`, `:help vim.pack-examples` or |
249 | 252 | -- the excellent blog post from the creator of mini.nvim https://echasnovski.com/blog/2026-03-13-a-guide-to-vim-pack |
250 | 253 | -- |
|
253 | 256 | -- |
254 | 257 | -- To update plugins, run |
255 | 258 | -- :lua vim.pack.update() |
| 259 | + -- |
| 260 | + -- |
| 261 | + -- Throughout the rest of the config there will be examples |
| 262 | + -- of how to install and configure plugins using `vim.pack`. |
| 263 | + -- |
| 264 | + -- In this section we set up some autocommands to run build |
| 265 | + -- steps for certain plugins after they are installed or updated. |
256 | 266 |
|
257 | 267 | local function run_build(name, cmd, cwd) |
258 | 268 | local result = vim.system(cmd, { cwd = cwd }):wait() |
|
292 | 302 | end |
293 | 303 | end, |
294 | 304 | }) |
295 | | - |
296 | | - local gh = function(repo) return 'https://github.com/' .. repo end |
297 | | - |
298 | | - ---@type (string|vim.pack.Spec)[] |
299 | | - local plugins = { |
300 | | - -- You can specify plugins with a git URL. `vim.pack` then uses the default branch (usually `main` or `master`) |
301 | | - gh 'NMAC427/guess-indent.nvim', |
302 | | - gh 'lewis6991/gitsigns.nvim', |
303 | | - gh 'folke/which-key.nvim', |
304 | | - gh 'nvim-lua/plenary.nvim', |
305 | | - gh 'nvim-telescope/telescope.nvim', |
306 | | - gh 'nvim-telescope/telescope-ui-select.nvim', |
307 | | - gh 'neovim/nvim-lspconfig', |
308 | | - gh 'mason-org/mason.nvim', |
309 | | - gh 'mason-org/mason-lspconfig.nvim', |
310 | | - gh 'WhoIsSethDaniel/mason-tool-installer.nvim', |
311 | | - gh 'j-hui/fidget.nvim', |
312 | | - gh 'stevearc/conform.nvim', |
313 | | - -- You can also specify plugins with a version range for semver git tags |
314 | | - -- See `:help vim.version.range()` for more info |
315 | | - { src = gh 'saghen/blink.cmp', version = vim.version.range '1.*' }, |
316 | | - { src = gh 'L3MON4D3/LuaSnip', version = vim.version.range '2.*' }, |
317 | | - gh 'folke/tokyonight.nvim', |
318 | | - gh 'folke/todo-comments.nvim', |
319 | | - gh 'nvim-mini/mini.nvim', |
320 | | - -- You can also specify a branch or a specific commit |
321 | | - { src = gh 'nvim-treesitter/nvim-treesitter', version = 'main' }, |
322 | | - } |
323 | | - |
324 | | - if vim.fn.executable 'make' == 1 then table.insert(plugins, gh 'nvim-telescope/telescope-fzf-native.nvim') end |
325 | | - |
326 | | - -- Useful for getting pretty icons, but requires a Nerd Font. |
327 | | - if vim.g.have_nerd_font then table.insert(plugins, gh 'nvim-tree/nvim-web-devicons') end |
328 | | - |
329 | | - -- NOTE: Here is where the plugins are actually installed and added to the path |
330 | | - vim.pack.add(plugins) |
331 | 305 | end |
332 | 306 |
|
| 307 | +---Because most plugins are hosted on GitHub, you can use the helper |
| 308 | +---function to have less repetition in the following sections. |
| 309 | +---@param repo string |
| 310 | +---@return string |
| 311 | +local function gh(repo) return 'https://github.com/' .. repo end |
| 312 | + |
333 | 313 | -- ============================================================ |
334 | 314 | -- SECTION 3: UI / CORE UX PLUGINS |
335 | 315 | -- guess-indent, gitsigns, which-key, colorscheme, todo-comments, mini modules |
336 | 316 | -- ============================================================ |
337 | 317 | do |
338 | | - -- [[ Configure plugins ]] |
339 | | - -- For most plugins you need to call their `.setup()` to start them |
| 318 | + -- [[ Installing and Configuring Plugins ]] |
| 319 | + -- |
| 320 | + -- To install a plugin simply call `vim.pack.add` with its git url. |
| 321 | + -- This will download the default branch of the plugin, which will usually be `main` or `master` |
| 322 | + -- You can also have more advanced specs, which we will talk about later. |
340 | 323 | -- |
341 | | - -- For example, here is the simplest possible setup for `guess-indent.nvim`, |
342 | | - -- which will automatically detect and set your indentation settings based on the current file. |
| 324 | + -- For most plugins its not enough to install them, you also need to call their `.setup()` to start them. |
| 325 | + -- |
| 326 | + -- For example, lets say we want to install `guess-indent.nvim` - a plugin for |
| 327 | + -- automatically detecting and setting the indentation. |
| 328 | + -- |
| 329 | + -- We first install it from https://github.com/NMAC427/guess-indent.nvim |
| 330 | + -- and then call its `setup()` function to start it with default settings. |
| 331 | + vim.pack.add { gh 'NMAC427/guess-indent.nvim' } |
343 | 332 | require('guess-indent').setup {} |
344 | 333 |
|
345 | | - -- Here is a more advanced example that passes configuration options to `gitsigns.nvim` |
| 334 | + -- Because lua is a real programming language, you can also have some logic to your installation - |
| 335 | + -- like only installing a plugin if a condition is met. |
| 336 | + -- |
| 337 | + -- Here we only install `nvim-web-devicons` (which adds pretty icons) if we have a Nerd Font, |
| 338 | + -- since otherwise the icons won't display properly. |
| 339 | + if vim.g.have_nerd_font then vim.pack.add { gh 'nvim-tree/nvim-web-devicons' } end |
| 340 | + |
| 341 | + -- Here is a more advanced configuration example that passes options to `gitsigns.nvim` |
346 | 342 | -- |
347 | 343 | -- See `:help gitsigns` to understand what each configuration key does. |
348 | 344 | -- Adds git related signs to the gutter, as well as utilities for managing changes |
| 345 | + vim.pack.add { gh 'lewis6991/gitsigns.nvim' } |
349 | 346 | require('gitsigns').setup { |
350 | 347 | signs = { |
351 | 348 | add = { text = '+' }, ---@diagnostic disable-line: missing-fields |
|
357 | 354 | } |
358 | 355 |
|
359 | 356 | -- Useful plugin to show you pending keybinds. |
| 357 | + vim.pack.add { gh 'folke/which-key.nvim' } |
360 | 358 | require('which-key').setup { |
361 | 359 | -- Delay between pressing a key and opening which-key (milliseconds) |
362 | 360 | delay = 0, |
|
376 | 374 | -- change the command under that to load whatever the name of that colorscheme is. |
377 | 375 | -- |
378 | 376 | -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. |
| 377 | + vim.pack.add { gh 'folke/tokyonight.nvim' } |
379 | 378 | ---@diagnostic disable-next-line: missing-fields |
380 | 379 | require('tokyonight').setup { |
381 | 380 | styles = { |
|
389 | 388 | vim.cmd.colorscheme 'tokyonight-night' |
390 | 389 |
|
391 | 390 | -- Highlight todo, notes, etc in comments |
| 391 | + vim.pack.add { gh 'folke/todo-comments.nvim' } |
392 | 392 | require('todo-comments').setup { signs = false } |
393 | 393 |
|
394 | 394 | -- Collection of various small independent plugins/modules |
| 395 | + vim.pack.add { gh 'nvim-mini/mini.nvim' } |
395 | 396 |
|
396 | 397 | -- Better Around/Inside textobjects |
397 | 398 | -- |
|
461 | 462 | -- Telescope picker. This is really useful to discover what Telescope can |
462 | 463 | -- do as well as how to actually do it! |
463 | 464 |
|
| 465 | + ---@type (string|vim.pack.Spec)[] |
| 466 | + local telescope_plugins = { |
| 467 | + gh 'nvim-lua/plenary.nvim', |
| 468 | + gh 'nvim-telescope/telescope.nvim', |
| 469 | + gh 'nvim-telescope/telescope-ui-select.nvim', |
| 470 | + } |
| 471 | + if vim.fn.executable 'make' == 1 then table.insert(telescope_plugins, gh 'nvim-telescope/telescope-fzf-native.nvim') end |
| 472 | + |
| 473 | + -- NOTE: You can install multiple plugins at once |
| 474 | + vim.pack.add(telescope_plugins) |
| 475 | + |
464 | 476 | -- See `:help telescope` and `:help telescope.setup()` |
465 | 477 | require('telescope').setup { |
466 | 478 | -- You can put your default mappings / updates / etc. in here |
|
588 | 600 | -- and elegantly composed help section, `:help lsp-vs-treesitter` |
589 | 601 |
|
590 | 602 | -- Useful status updates for LSP. |
| 603 | + vim.pack.add { gh 'j-hui/fidget.nvim' } |
591 | 604 | require('fidget').setup {} |
592 | 605 |
|
593 | 606 | -- This function gets run when an LSP attaches to a particular buffer. |
|
711 | 724 | }, |
712 | 725 | } |
713 | 726 |
|
| 727 | + vim.pack.add { |
| 728 | + gh 'neovim/nvim-lspconfig', |
| 729 | + gh 'mason-org/mason.nvim', |
| 730 | + gh 'mason-org/mason-lspconfig.nvim', |
| 731 | + gh 'WhoIsSethDaniel/mason-tool-installer.nvim', |
| 732 | + } |
| 733 | + |
714 | 734 | -- Automatically install LSPs and related tools to stdpath for Neovim |
715 | 735 | require('mason').setup {} |
716 | 736 |
|
|
740 | 760 | -- ============================================================ |
741 | 761 | do |
742 | 762 | -- [[ Formatting ]] |
| 763 | + vim.pack.add { gh 'stevearc/conform.nvim' } |
743 | 764 | require('conform').setup { |
744 | 765 | notify_on_error = false, |
745 | 766 | format_on_save = function(bufnr) |
|
777 | 798 | -- ============================================================ |
778 | 799 | do |
779 | 800 | -- [[ Snippet Engine ]] |
| 801 | + |
| 802 | + -- NOTE: You can also specify plugin using a version range for its git tag. |
| 803 | + -- See `:help vim.version.range()` for more info |
| 804 | + vim.pack.add { { src = gh 'L3MON4D3/LuaSnip', version = vim.version.range '2.*' } } |
780 | 805 | require('luasnip').setup {} |
781 | 806 |
|
782 | 807 | -- `friendly-snippets` contains a variety of premade snippets. |
|
787 | 812 | -- require('luasnip.loaders.from_vscode').lazy_load() |
788 | 813 |
|
789 | 814 | -- [[ Autocomplete Engine ]] |
| 815 | + vim.pack.add { { src = gh 'saghen/blink.cmp', version = vim.version.range '1.*' } } |
790 | 816 | require('blink.cmp').setup { |
791 | 817 | keymap = { |
792 | 818 | -- 'default' (recommended) for mappings similar to built-in completions |
|
858 | 884 | -- |
859 | 885 | -- See `:help nvim-treesitter-intro` |
860 | 886 |
|
| 887 | + -- NOTE: You can also specify a branch or a specific commit |
| 888 | + vim.pack.add { { src = gh 'nvim-treesitter/nvim-treesitter', version = 'main' } } |
| 889 | + |
861 | 890 | -- Ensure basic parsers are installed |
862 | 891 | local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' } |
863 | 892 | require('nvim-treesitter').install(parsers) |
|
0 commit comments