junegunn / vim-plug

:hibiscus: Minimalist Vim Plugin Manager
https://junegunn.github.io/vim-plug/
MIT License
34.01k stars 1.93k forks source link

neovim Unknown function: plug#begin #245

Closed alexanderjeurissen closed 9 years ago

alexanderjeurissen commented 9 years ago

I have the latest version of neovim, and when I run it using my .vimrc symlinked as .nvimrc I get the following error:

Error detected while processing /Users/alexander/.vim/settings/vimPlug.vim:
line   16:
E117: Unknown function: plug#begin

the vimPlug.vim file is sourced in my .vimrc and contains the following:

"setup vim-plug {{{

  "Note: install vim-plug if not present
  if empty(glob('~/.vim/autoload/plug.vim'))
    silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
      \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    autocmd VimEnter * PlugInstall
  endif

  "Note: Skip initialization for vim-tiny or vim-small.
  if !1 | finish | endif
  if has('vim_starting')
    set nocompatible               " Be iMproved
    " Required:
    call plug#begin()
  endif
"}}}

I'm really not sure what is causing this, I already tried commenting out all plugins, reinstalling neovim etc. but it still fails on the vim-plug initialisation.

starcraftman commented 9 years ago

@alexanderjeurissen I believe the issue is that the plug#begin is sourced from plug.vim which is at ~/.vim/autoload/plug.vim. By default, nvim makes its own files all prefixed with n. So instead of .vim, it makes .nvim. So by default, nvim will source autoloads from ~/.nvim/autoload/plug.vim. I imagine there isn't a plug.vim in that folder. Your snippet only checks/downloads to .vim folder.

To solve, you could: 1) Symlink .vim to .nvim. 2) Symlink .vim/autoload to .nvim/autoload 3) Download/copy plug.vim to ~/.nvim/autoload/plug.vim. Edit: 4) You could also put ~/.vim/autoload onto your nvim runtimepath. I don't like idea though, since vim-plug should do the rtp magic.

Personally, I keep nvim & vim separate and use this snippet in my vimrc to share the vimrc. You can see my bootstrapping here.

alexanderjeurissen commented 9 years ago

symlinking .vim to .nvim did the trick.. Thanks.

megamaddu commented 9 years ago

Will symlinking .vim to .nvim cause things to run/load twice? I have everything in .vim, but someone else is having trouble copying my setup.

megamaddu commented 9 years ago

Tried symlinking anyway, but still getting the same error (can't find plug#begin).

junegunn commented 9 years ago

Check the output of the following commands

eleijonmarck commented 9 years ago

Just copying .vim to .nvim made trick for me. Ofcourse with /autoload/plug.vim inside

jon49 commented 8 years ago

Just for anyone else looking at this for Bash on Windows. if you do the

:echo &rtp

as @junegunn suggested. For some reason the right directory doesn't show up. So, just put the autoload in whatever one of the directories listed in the command above. I just used ~/.config/nvim

wizzat commented 6 years ago

For future reference, this works fine. Mostly to give a copy/pastable answer from the above snippet:

"setup vim-plug {{{

  "Note: install vim-plug if not present
  if empty(glob('~/.config/nvim/autoload/plug.vim'))
    silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    autocmd VimEnter * PlugInstall
  endif

  "Note: Skip initialization for vim-tiny or vim-small.
  if !1 | finish | endif
  if has('vim_starting')
    set nocompatible               " Be iMproved
    " Required:
    call plug#begin()
  endif

"}}}
nicoandresr commented 2 years ago

on my case I was installing vim-plug for vim, instead of Neovim! 🤦 , all was good after installing vim-plug for NeoVim!

mb720 commented 2 years ago

A variation of @wizzat's solution, with variables. Tested using my Neovim's init.vim:

" Put plugins and dictionaries in this directory
let vimDir = expand('$XDG_CONFIG_HOME/nvim')
let vimPlugFile = vimDir . '/autoload/plug.vim'

" Install vim-plug if not present
if empty(glob(vimPlugFile))
    " There is no vim-plug file → Download and install it"
    let vimPlugUrl = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
    exec '!curl -fLo ' . vimPlugFile . ' --create-dirs ' . vimPlugUrl
    autocmd VimEnter * PlugInstall
endif

call plug#begin()
" Surrounds text with other text like parentheses or HTML tags
Plug 'https://github.com/tpope/vim-surround'
" Some more plugins, probably
call plug#end()
ffreemt commented 1 year ago

It works! I have no idex why it works. Thanks very much! I spent hours googling, nothing worked.

ffreemt commented 1 year ago

In Windows 10, $XDG_CONFIG_HOME in nb720's script should be changed to $HOME which will create a nvim directory in %USERPROFILE% (\Users\Username). to hold autoload.