Skip to content

Commit 6261c61

Browse files
committed
Move vim.pack.add to the relevant sections
1 parent ab8ce2f commit 6261c61

1 file changed

Lines changed: 73 additions & 44 deletions

File tree

init.lua

Lines changed: 73 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,14 @@ do
240240
end
241241

242242
-- ============================================================
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
245245
-- ============================================================
246246
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+
--
248251
-- See `:help vim.pack`, `:help vim.pack-examples` or
249252
-- the excellent blog post from the creator of mini.nvim https://echasnovski.com/blog/2026-03-13-a-guide-to-vim-pack
250253
--
@@ -253,6 +256,13 @@ do
253256
--
254257
-- To update plugins, run
255258
-- :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.
256266

257267
local function run_build(name, cmd, cwd)
258268
local result = vim.system(cmd, { cwd = cwd }):wait()
@@ -292,60 +302,47 @@ do
292302
end
293303
end,
294304
})
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)
331305
end
332306

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+
333313
-- ============================================================
334314
-- SECTION 3: UI / CORE UX PLUGINS
335315
-- guess-indent, gitsigns, which-key, colorscheme, todo-comments, mini modules
336316
-- ============================================================
337317
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.
340323
--
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' }
343332
require('guess-indent').setup {}
344333

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`
346342
--
347343
-- See `:help gitsigns` to understand what each configuration key does.
348344
-- Adds git related signs to the gutter, as well as utilities for managing changes
345+
vim.pack.add { gh 'lewis6991/gitsigns.nvim' }
349346
require('gitsigns').setup {
350347
signs = {
351348
add = { text = '+' }, ---@diagnostic disable-line: missing-fields
@@ -357,6 +354,7 @@ do
357354
}
358355

359356
-- Useful plugin to show you pending keybinds.
357+
vim.pack.add { gh 'folke/which-key.nvim' }
360358
require('which-key').setup {
361359
-- Delay between pressing a key and opening which-key (milliseconds)
362360
delay = 0,
@@ -376,6 +374,7 @@ do
376374
-- change the command under that to load whatever the name of that colorscheme is.
377375
--
378376
-- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
377+
vim.pack.add { gh 'folke/tokyonight.nvim' }
379378
---@diagnostic disable-next-line: missing-fields
380379
require('tokyonight').setup {
381380
styles = {
@@ -389,9 +388,11 @@ do
389388
vim.cmd.colorscheme 'tokyonight-night'
390389

391390
-- Highlight todo, notes, etc in comments
391+
vim.pack.add { gh 'folke/todo-comments.nvim' }
392392
require('todo-comments').setup { signs = false }
393393

394394
-- Collection of various small independent plugins/modules
395+
vim.pack.add { gh 'nvim-mini/mini.nvim' }
395396

396397
-- Better Around/Inside textobjects
397398
--
@@ -461,6 +462,17 @@ do
461462
-- Telescope picker. This is really useful to discover what Telescope can
462463
-- do as well as how to actually do it!
463464

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+
464476
-- See `:help telescope` and `:help telescope.setup()`
465477
require('telescope').setup {
466478
-- You can put your default mappings / updates / etc. in here
@@ -588,6 +600,7 @@ do
588600
-- and elegantly composed help section, `:help lsp-vs-treesitter`
589601

590602
-- Useful status updates for LSP.
603+
vim.pack.add { gh 'j-hui/fidget.nvim' }
591604
require('fidget').setup {}
592605

593606
-- This function gets run when an LSP attaches to a particular buffer.
@@ -711,6 +724,13 @@ do
711724
},
712725
}
713726

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+
714734
-- Automatically install LSPs and related tools to stdpath for Neovim
715735
require('mason').setup {}
716736

@@ -740,6 +760,7 @@ end
740760
-- ============================================================
741761
do
742762
-- [[ Formatting ]]
763+
vim.pack.add { gh 'stevearc/conform.nvim' }
743764
require('conform').setup {
744765
notify_on_error = false,
745766
format_on_save = function(bufnr)
@@ -777,6 +798,10 @@ end
777798
-- ============================================================
778799
do
779800
-- [[ 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.*' } }
780805
require('luasnip').setup {}
781806

782807
-- `friendly-snippets` contains a variety of premade snippets.
@@ -787,6 +812,7 @@ do
787812
-- require('luasnip.loaders.from_vscode').lazy_load()
788813

789814
-- [[ Autocomplete Engine ]]
815+
vim.pack.add { { src = gh 'saghen/blink.cmp', version = vim.version.range '1.*' } }
790816
require('blink.cmp').setup {
791817
keymap = {
792818
-- 'default' (recommended) for mappings similar to built-in completions
@@ -858,6 +884,9 @@ do
858884
--
859885
-- See `:help nvim-treesitter-intro`
860886

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+
861890
-- Ensure basic parsers are installed
862891
local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }
863892
require('nvim-treesitter').install(parsers)

0 commit comments

Comments
 (0)