-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make automatic installation script in wiki tips compatible with Neovim #1270
Comments
I've faced this issue as well and this does solve it. |
Any idea why the command is not recognized? Because plug.vim is in I have tested the code without the source line in this init.lua file and it works just fine. local data_dir = vim.fn.stdpath('data')
if vim.fn.empty(vim.fn.glob(data_dir .. '/site/autoload/plug.vim')) == 1 then
vim.cmd('silent !curl -fLo ' ..
data_dir ..
'/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim')
vim.cmd('autocmd VimEnter * PlugInstall --sync | source $MYVIMRC')
end
local vim = vim
local Plug = vim.fn['plug#']
vim.call('plug#begin')
Plug('junegunn/vim-easy-align')
vim.call('plug#end') |
That is interesting, I do have a Might be something specific to neovim? I have not tried with regular vim. |
With regular vim there seems to be no issue |
I ran into the same problem with Neovim 0.9.5 and init.vim (not init.lua), but OP solved it. This script works as expected; " Automatic installation of vim-plug
let s:data_dir = stdpath('data') . '/site'
if empty(glob(s:data_dir . '/autoload/plug.vim'))
silent execute '!curl -fL --create-dirs '
\. '-o ' . s:data_dir . '/autoload/plug.vim '
\. 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
execute 'source ' . s:data_dir . '/autoload/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif @junegunn Could you retry in a fresh environment?
I tried your init.lua with Neovim 0.9.5 in a new Docker container, and got this error;
|
Okay, after removing all the directories related to Neovim, I was able to reproduce the problem, and it seems like a bug of Neovim. The gist of the problem is this: Neovim does not pick up autoload files if rm -rf ~/.config/nvim ~/.local/share/nvim
mkdir -p ~/.config/nvim # ~/.local/share/nvim/site # FIXME: uncomment this part
cat << "EOF" > ~/.config/nvim/init.vim
call mkdir(stdpath('data') . '/site/autoload', 'p')
call writefile(['function! foobar#it()', 'echom 123', 'endfunction'], stdpath('data') . '/site/autoload/foobar.vim')
call foobar#it()
EOF
nvim
However, if we create the directory before starting Neovim, the autoload script is loaded as expected and prints rm -rf ~/.config/nvim ~/.local/share/nvim
mkdir -p ~/.config/nvim ~/.local/share/nvim/site # NOTE: uncommented
cat << "EOF" > ~/.config/nvim/init.vim
call mkdir(stdpath('data') . '/site/autoload', 'p')
call writefile(['function! foobar#it()', 'echom 123', 'endfunction'], stdpath('data') . '/site/autoload/foobar.vim')
call foobar#it()
EOF
nvim I don't know if this is intentional, but I wouldn't call this a feature. Maybe they were trying to speed up processing by remembering which directories existed, so they could ignore non-existent directories afterwards. Anyway, manually sourcing the plug.vim file seems to be the only workaround we can think of now. But this can't really be an ideal solution, because other autoload functions are also unavailable during the start-up. rm -rf ~/.config/nvim ~/.local/share/nvim
mkdir -p ~/.config/nvim # ~/.local/share/nvim/site
cat << "EOF" > ~/.config/nvim/init.vim
call mkdir(stdpath('data') . '/site/autoload', 'p')
call writefile(['function! foobar#it()', 'echom 123', 'endfunction'], stdpath('data') . '/site/autoload/foobar.vim')
call writefile(['function! barfoo#it()', 'echom 456', 'endfunction'], stdpath('data') . '/site/autoload/barfoo.vim')
source ~/.local/share/nvim/site/autoload/foobar.vim
call foobar#it() " This works
call barfoo#it() " This doesn't
EOF
nvim
But after Neovim starts, |
That is an interesting finding. Will report it there and see what the answer is: neovim/neovim#28128 Thanks for the detailed analysis! |
The workaround (resetting runtimepath) shown in neovim/neovim#28128 works, so, local data_dir = vim.fn.stdpath('data')
if vim.fn.empty(vim.fn.glob(data_dir .. '/site/autoload/plug.vim')) == 1 then
vim.cmd('silent !curl -fLo ' .. data_dir .. '/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim')
vim.o.runtimepath = vim.o.runtimepath
vim.cmd('autocmd VimEnter * PlugInstall --sync | source $MYVIMRC')
end
-- An example of vim-plug section --------------------------------------------
local vim = vim
local Plug = vim.fn['plug#']
vim.call('plug#begin')
Plug('junegunn/seoul256.vim')
vim.call('plug#end')
vim.cmd('silent! colorscheme seoul256') |
When using the snippet to auto install everything on Neovim it does not recognise
PlugInstall
as a command without restarting.To solve this I added one line to the suggested tip to source Plug right after downloading it.
It now looks as follows (in lua):
Would it be possible to add this solution for those who get the error that
PlugInstall
is not a command on first setup with this tip?The text was updated successfully, but these errors were encountered: