iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim
MIT License
6.67k stars 277 forks source link

[NeoVim] 使用 README 中第一种 vim-plug 安装方法出现的问题 / Problem that occured during the installation using vim-plug following the instruction from README #497

Open lutalli opened 2 years ago

lutalli commented 2 years ago

这不是一个 bug report,而是一个指出了出现此问题原因的 post,希望能帮助遇到同样问题的用户。

问题描述

我尝试了按照 README 中用 vim-plug 安装的第一种方法(without Node.js and Yarn)安装插件:

Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}

但是插件安装完成后 post-update hook 出现错误:

Post-update hook for markdown-preview.nvim ... Vim(call):E117: Unknown function: mkdp#util#install

很奇怪,因为插件有正常安装完成,而且手动输入 :call mkdp#util#install() 也能正常执行函数,但是这里的 post-update 却找不到这个函数。

原因

经过一点查找后发现:这应该不是 markdown-preview、也不是 vim-plug 的 bug,而是 NeoVim 0.6.0 更新的锅。

首先我猜想可能是一般的 post-update 没法立刻找到新安装插件定义的函数的问题(而不是只有 markdown-preview),搜到了这个 issue:junegunn/vim-plug#1148。那里提到了另一个 issue:neovim/neovim#18822(由 vim-doge 的作者发布)。这个 issue 中指出,这个问题在 Vim 和 NeoVim 0.6.0 之前的版本都没有出现,所以大概是 NeoVim 更新后 autoload 机制改变的问题,导致 'do' 里面的命令在逻辑上执行地太快。此 issue 目前还是 open 状态。

解决办法

一个解决办法即是把 'do': { -> mkdp#util#install() } 去掉(或者直接不管它),在安装完插件后,手动执行

:call mkdp#util#install()

This is not a bug report, but a post that indicates the reason why this problem (see below) occurs and helps those who got confused when encountering the same problem.

Problem

I tried installing the plugin by vim-plug using the method mentioned in README (the one without Node.js and Yarn):

Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}

But after the plugin was installed I got the following the error from the post-update hook:

Post-update hook for markdown-preview.nvim ... Vim(call):E117: Unknown function: mkdp#util#install

which is quite weird, since although the plugin was installed successfully and I could even run :call mkdp#util#install() manually (meaning that this function did exist), the post-update hook could not find it.

Reason why this is happening

It seems not to be a bug of markdown-preview nor vim-plug, but to be a bug of a recent NeoVim update since 0.6.0.

Guessing the real problem is that the post-update hook can not find the functions defined by a new installed plugin in general (but not specifically for markdown-preview), after some searching I found this issue: junegunn/vim-plug#1148, in which another issue was mentioned: neovim/neovim#18822 (posted by the author of vim-doge). In this issue it was pointed out that this problem would not occur in Vim as well as in older versions of NeoVim (before 0.6.0). So presumably it is due to the new update of NeoVim, which changed how autoloading works, and the command in 'do' is executed before the plugin is loaded completely. It is still an open issue at the moment.

Solution

A simple way to resolve this is to remove 'do': { -> mkdp#util#install() } (or leave it if you have already installed the plugin) and manually run

:call mkdp#util#install()

after the plugin is installed.


Operating system: WSL2 on Windows 11 NeoVim version: 0.6.1 vim-plug version: 0.11.0

jdhao commented 1 year ago

Same issue here on macOS, using packer to install markdown-preview.nvim:

use({
    "iamcco/markdown-preview.nvim",
    run = function() vim.fn["mkdp#util#install"]() end,
})

After using :MarkdownPreview, nothing shows. I manually run :call mkdp#util#install(), then I can use command :MarkdownPreview normally.

proatgram commented 1 year ago

This issue is also affecting me, but in a lua config instead of vimscript.

Plug ('iamcco/markdown-preview.nvim', {['do'] = "mkdp#util#install()", ['for'] = {'markdown', 'vim-plug'}})