packer.nvim
packer.nvim copied to clipboard
running packer from blank neovim installation
Hi, I'm trying to setup my installer which installs my entire neovim setup on completely bare systems.
With vimplug, I had installed all my packages from this state with
nvim -c PlugInstall -c qa --headless
(of course there was a bootstrap for fetching vimplug in my init.vim
).
I've tried the same approach with packer, but while the boostrap script does successfully fetch packer itself, for some reason I do not seem to be able to get it to actually execute PackerInstall
, PackerSync
or anything else before it exits.
After a bit more investigation, I found that this seems to be happening because nvim
does not know to wait for PackerSync
before executing qa
and killing itself. A temporary (but not at all ideal) workaround is to do
nvim -c PackerSync -c 'sleep 5' -c qa --headless
Is there some way of forcing nvim to wait for packer to finish its sync before exiting?
There is currently no way to make :PackerSync
blocking. packer
provides a PackerComplete
autocommand event if you want to wait until an operation is complete, see :help packer-user-autocmds
Related:
- #451
- #198 (there are a few
PackerComplete
examples in that issue)
Ah, I see.
Forgive my ignorance but I'm still having some trouble figuring out how to do this after reading the linked documentation, would it be possible to provide a minimal example how to use PackerComplete
to call qa
after packer is done running?
Some examples (in Lua and shell, depending on what you want to do you might have to tweak them):
- https://github.com/wbthomason/packer.nvim/issues/198#issuecomment-808927939
- https://github.com/wbthomason/packer.nvim/issues/198#issuecomment-817426007
Hm, looks like they still needed to do the sleep
hack for some reason. Ok, thanks.
$ nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
seems to work
Yes, that's working, thanks! It would probably be a good idea to stick this in the README.
Thanks @mastertinner! Added this to the README in 346e7af.
@mastertinner What I have found is that script does not work if the script you're running in question is an executable. If you source it, it works fine. When it's an executable you get this
Error detected while processing command line:
E492: Not an editor command: PackerInstall
Press ENTER or type command to continue
Hey guys,
I'm using the method described here in my "update my system" script. This sits at the end of my script as I usually want to know what changed in each plugin. Is there a way to output the changelog buffer out?
I'm in the same boat here trying to update my setup scripts for new machines. I'm effectively looking for functionality like dein
:
nvim --headless -n -u ~/.config/nvim/init.vim -c "call dein#install()|q"
I would assume that I could maybe think of a hacky way of achieving this via shell scripting but would prefer to do something nicer than anything akin to a while ...
loop
Right now, packer
does not have a way to output the change log in headless mode, though I'd be happy to add this functionality - sooner if someone is willing to take a stab at a PR for it.
Re: @chr0n1x's request: Does the snippet posted earlier in this thread/in the README not do what you want? (https://github.com/wbthomason/packer.nvim/issues/502#issuecomment-888079755)
@wbthomason unfortunately, no. I am in the middle of trying to migrate my vim/nvim setup to init.lua
and am trying to package everything into a docker container on build for use across multiple machines. With that command I end up having to run nvim
and have packer
install the plugins, then quit the progress buffer/pane, re-source init.lua
.
@wbthomason for me the command works fine. I just miss being able to see what changed, and thus, would like to see the changelog printed to stdout if possible
I'm converting my nvim setup script to lua, and part of it is switching to packer
. I just wanted to report that this headless command throws an error for me. But succeeds on the next attempt.
I'm also using the snippet in the readme to install packer
if it's not there yet.
My plugin setup in plugins.lua
which is required in init.lua
:
local fn = vim.fn
local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
packer_bootstrap = fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path })
end
return require('packer').startup(function(use)
use "wbthomason/packer.nvim"
-- all my plugins here
-- Automatically set up configuration after cloning packer.nvim
if packer_bootstrap then
require('packer').sync()
end
end)
This is in my routine development environment setup script. It throws an error the first time. I suspect because of the new packer
install.
nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
If you delete "$HOME"/.local/share/nvim/site/pack/packer/start/packer.nvim
you can duplicate it again. Same thing happens the first time you launch nvim
. A second launch has it working fine.
The error:
Error detected while processing /home/ubuntu/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/ubuntu/.config/nvim/lua/plugins.lua:7: module 'packer' not found:
no field package.preload['packer']
no file './packer.lua'
no file '/build/nvim/parts/nvim/build/.deps/usr/share/luajit-2.1.0-beta3/packer.lua'
no file '/usr/local/share/lua/5.1/packer.lua'
no file '/usr/local/share/lua/5.1/packer/init.lua'
no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/packer.lua'
no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/packer/init.lua'
no file './packer.so'
no file '/usr/local/lib/lua/5.1/packer.so'
no file '/build/nvim/parts/nvim/build/.deps/usr/lib/lua/5.1/packer.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
/home/ubuntu/.config/nvim/lua/plugins.lua:7: in main chunk
[C]: in function 'require'
/home/ubuntu/.config/nvim/init.lua:6: in main chunk
Just to share my observations on this matter.
- I had to run
nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
twice as the first run only downloads packer itself. The second run syncs other plugins. - The workaround above only works fine before the number of plugins managed reaches a threshold(21 in my case). When I try to install 22+ plugins, some are partially installed leaving their dirty directories behind! Only
.git
exists in those dirty directories. It even prevents futurePackerInstall
to distinguish the missing ones!
See my script and the result in a docker image (onichandame/dev:20220523151523795a02). Check what's inside /root/.local/share/nvim/site/pack/packer/start/nvim-tree.lua
Hence I do feel the need of a proper way to programmatically cold start packer on a new machine :(
Still having some issues here. @onichandame I'm running an M1 Mac and can't load up your docker image, could you please share that result/file if it could help?
@partounian Maybe my image is too large.
This is what ended in my plugins' directory.
Hello,
I am having issues with this as well. I haven't had any luck using the PackerComplete autocmd to have packer bootstrap and install packages the first time I run nvim and have my nvim config load without any errors the second time.
Is there any way in my init.lua I can check whether packer sync has been run successfully or if the packages I have listed have been installed already? I have tried to provide a minimum working example at https://github.com/WesleySoftware/packer.nvim-issue-502.
When I run nvim
the first time in the container I get the error message that module 'telescope' not found
which makes sense since packer hasn't installed it yet. Once I press enter packer installs the plugin and when I run nvim
the second time everything works. I want some way of avoiding that error message the first time I run nvim
.
Any help is appreciated.
I'm converting my nvim setup script to lua, and part of it is switching to
packer
. I just wanted to report that this headless command throws an error for me. But succeeds on the next attempt.I'm also using the snippet in the readme to install
packer
if it's not there yet.My plugin setup in
plugins.lua
which is required ininit.lua
:local fn = vim.fn local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then packer_bootstrap = fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) end return require('packer').startup(function(use) use "wbthomason/packer.nvim" -- all my plugins here -- Automatically set up configuration after cloning packer.nvim if packer_bootstrap then require('packer').sync() end end)
This is in my routine development environment setup script. It throws an error the first time. I suspect because of the new
packer
install.nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
If you delete
"$HOME"/.local/share/nvim/site/pack/packer/start/packer.nvim
you can duplicate it again. Same thing happens the first time you launchnvim
. A second launch has it working fine.The error:
Error detected while processing /home/ubuntu/.config/nvim/init.lua: E5113: Error while calling lua chunk: /home/ubuntu/.config/nvim/lua/plugins.lua:7: module 'packer' not found: no field package.preload['packer'] no file './packer.lua' no file '/build/nvim/parts/nvim/build/.deps/usr/share/luajit-2.1.0-beta3/packer.lua' no file '/usr/local/share/lua/5.1/packer.lua' no file '/usr/local/share/lua/5.1/packer/init.lua' no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/packer.lua' no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/packer/init.lua' no file './packer.so' no file '/usr/local/lib/lua/5.1/packer.so' no file '/build/nvim/parts/nvim/build/.deps/usr/lib/lua/5.1/packer.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'require' /home/ubuntu/.config/nvim/lua/plugins.lua:7: in main chunk [C]: in function 'require' /home/ubuntu/.config/nvim/init.lua:6: in main chunk
Does anyone know how to solve this?