Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Can anyone provide some guidance on how to load a vim plugin installed with packer in Neovim?

Up till now, I've only ever used plugins written in Lua in Nvim but, I'm trying to install vim-expand-region which is written in Vim Script.

I added use { "terryma/vim-expand-region" } to my plugins.lua file and it was installed with Packer. At least, there is a vim-expand-region directory in ~/.local/share/nvim/site/pack/packer/start.

My current config is organized like this:

~/.config/nvim/
├── init.lua
├── lua
│   └── user
│       ├── alpha.lua
│       ├── autocommands.lua
│       ├── autopairs.lua
│       ├── bufferline.lua
│       ├── cmp.lua
│       ├── colorscheme.lua
│       ├── comment.lua
│       ├── dap
│       │   ├── dap.lua
│       │   ├── dap-python.lua
│       │   ├── init.lua
│       │   └── osv.lua
│       ├── gitsigns.lua
│       ├── hop.lua
│       ├── icons.lua
│       ├── illuminate.lua
│       ├── impatient.lua
│       ├── indentline.lua
│       ├── keymaps.lua
│       ├── lsp
│       │   ├── handlers.lua
│       │   ├── init.lua
│       │   ├── mason.lua
│       │   ├── null-ls.lua
│       │   ├── package-lock.json
│       │   └── settings
│       │       ├── pyright.lua
│       │       └── sumneko_lua.lua
│       ├── lualine.lua
│       ├── navic.lua
│       ├── neoclip.lua
│       ├── nvim-surround.lua
│       ├── nvim-tree.lua
│       ├── options.lua
│       ├── plugins.lua
│       ├── symbols-outline.lua
│       ├── tabnine.lua
│       ├── telescope.lua
│       ├── toggleterm.lua
│       ├── treesitter.lua
│       ├── vim-expand-region.lua
│       └── whichkey.lua
└── plugin
    └── packer_compiled.lua

As described in the nanotee guide, to load a .lua plugin, I run require "user.plugin" in my init.lua file. Then, in the plugin.lua file, I require the plugin itself with code like:

local status_ok, plugin = pcall(require, "plugin")
if not status_ok then
    vim.notify("WARNING: plugin.lua failed to load.")
    return
end

As I understand it, the require function searches the runtime path looking for a file called "plugin.lua" to load. In my case, my runtime path includes ~/.local/share/nvim/site/pack/*/start/* and each of the lua plugins installed with Packer contains a lua directory with a plugin.lua file (e.g. ~/.local/share/nvim/site/pack/*/start/plugin/lua/plugin.lua) which I assume gets sourced when the require function is called.

However, the vim plugin vim-expand-region has this structure:

~/.local/share/nvim/site/pack/packer/start/vim-expand-region/
├── autoload
│   └── expand_region.vim
├── doc
│   ├── expand_region.txt
│   └── tags
├── expand-region.gif
├── MIT-LICENSE.txt
├── plugin
│   └── expand_region.vim
└── README.md

Vim configs that use the Plug package manager load the plugin with a line like Plug 'terryma/vim-expand-region' but since I'm not using Plug, I'm not sure how I should load it.

From some of the instructions listed here it seems like the expand_region.vim file needs to be sourced. For vim it seems like the plugin should be added to ~/.vim/pack/bundle/start but that's not where it gets installed with Packer.

What is the best way to load vim plugins that have been installed with Packer?

You must be logged in to vote

Note to self, any Vim plugins installed with Packer should be sourced automatically. As I discovered in this thread the plugin itself seems to be broken.

Replies: 1 comment · 1 reply

Comment options

Note to self, any Vim plugins installed with Packer should be sourced automatically. As I discovered in this thread the plugin itself seems to be broken.

You must be logged in to vote
1 reply
@wbthomason
Comment options

Yes - in general, Vim and Lua plugins mostly load the same these days (and packer has always loaded both). Failures to load are generally issues with lazy-loading or with the plugin itself (or sometimes with packer).

Answer selected by CharlesARoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.