Skip to content

Commit

Permalink
Add optional packer plugins hook (nvim-lua#20)
Browse files Browse the repository at this point in the history
* Add optional packer plugins hook

* Provide help in README and simplify module

* Fix spelling and tweak verbiage about after/plugin
  • Loading branch information
elijahmanor authored Nov 21, 2022
1 parent e311d48 commit e80aa66
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@ This repo is meant to be used as a starting point for a user's own configuration
* Start Neovim (`nvim`) and run `:PackerInstall` - ignore any error message about missing plugins, `:PackerInstall` will fix that shortly
* Restart Neovim

### Configuration

You could directly modify the `init.lua` file with your personal customizations. This option is the most straightforward, but if you update your config from this repo, you may need to reapply your changes.

An alternative approach is to create a separate `custom.plugins` module to register your own plugins. In addition, you can handle further customizations in the `/after/plugin/` directory (see `:help load-plugins`). See the following examples for more information. Leveraging this technique should make upgrading to a newer version of this repo easier.

#### Example `plugins.lua`

The following is an example of a `plugins.lua` module (located at `$HOME/.config/nvim/lua/custom/plugins.lua`) where you can register your own plugins.

```lua
return function(use)
use({
"folke/which-key.nvim",
config = function()
require("which-key").setup({})
end
})
end
```

#### Example `defaults.lua`

For further customizations, you can add a file in the `/after/plugin/` folder (see `:help load-plugins`) to include your own options, keymaps, autogroups, and more. The following is an example `defaults.lua` file (located at `$HOME/.config/nvim/after/plugin/defaults.lua`).

```lua
vim.opt.relativenumber = true

vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
```

### Contribution

Pull-requests are welcome. The goal of this repo is not to create a Neovim configuration framework, but to offer a starting template that shows, by example, available features in Neovim. Some things that will not be included:
Expand Down
4 changes: 4 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ require('packer').startup(function(use)
-- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available
use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make', cond = vim.fn.executable 'make' == 1 }

-- Add custom plugins to packer from /nvim/lua/custom/plugins.lua
local has_plugins, plugins = pcall(require, "custom.plugins")
if has_plugins then plugins(use) end

if is_bootstrap then
require('packer').sync()
end
Expand Down

0 comments on commit e80aa66

Please sign in to comment.