markdown-preview.nvim icon indicating copy to clipboard operation
markdown-preview.nvim copied to clipboard

Vim:E117: Unknown function: mkdp#util#install when install by lazy.nvim

Open sontungexpt opened this issue 1 year ago • 22 comments

Describe the bug

  • I use lazy.nvim to install this plugin followed the instructions but it seems the build failed. { "iamcco/markdown-preview.nvim", cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, ft = { "markdown" }, build = function() vim.fn"mkdp#util#install" end, config = function() vim.g.mkdp_auto_close = 1 end, },

  • So i fixed it by this #691, is it the right way?

To Reproduce Steps to reproduce the behavior:

  1. Remove the store of this plugin
  2. Install it again
  3. Wait to completed
  4. See error

Expected behavior Build successfully

Screenshots image

Desktop (please complete the following information):

  • OS: Arch linux: 6.9.10-arch1-1

sontungexpt avatar Jul 23 '24 03:07 sontungexpt

+1 Also faced this error on Mac OS 12.7.5 Intel Based

Raiden-16F7 avatar Jul 23 '24 11:07 Raiden-16F7

Hi peeps,

Seems like iamcco isn’t watching this one anymore, so it’s unlikely this will get merged here. A few of us are looking at possibly reviving the project elsewhere if there is enough interest in helping maintain it.

Alternatively a couple of previous users started a new project https://github.com/jannis-baum/Vivify as a potential replacement

Tweekism avatar Jul 23 '24 14:07 Tweekism

Hi, before executing the functin, Lazy load the plugin.

This is my resulting lazy configuration, that uses npx is available:

  {
    -- Install markdown preview, use npx if available.
    "iamcco/markdown-preview.nvim",
    cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
    ft = { "markdown" },
    build = function(plugin)
      if vim.fn.executable "npx" then
        vim.cmd("!cd " .. plugin.dir .. " && cd app && npx --yes yarn install")
      else
        vim.cmd [[Lazy load markdown-preview.nvim]]
        vim.fn["mkdp#util#install"]()
      end
    end,
    init = function()
      if vim.fn.executable "npx" then vim.g.mkdp_filetypes = { "markdown" } end
    end,
  },

Kamilcuk avatar Jul 27 '24 23:07 Kamilcuk

thanks @Kamilcuk this also worked for nixos (adding commend to allow other people to find this solution)

nilsherzig avatar Aug 01 '24 09:08 nilsherzig

Please excuse my dumb question but I'm somewhat new to LazyVim and even Neovim for that matter. In what file should I place the above configuration from @Kamilcuk ?

baronyoung avatar Aug 01 '24 19:08 baronyoung

This goes where ever you are specifying your plugins.

So for me, that would be ~/.config/nvim/lua/plugins/markdown-preview.lua

and the file contents would be:-

return {
    -- Install markdown preview, use npx if available.
    "iamcco/markdown-preview.nvim",
    cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
    ft = { "markdown" },
    build = function(plugin)
      if vim.fn.executable "npx" then
        vim.cmd("!cd " .. plugin.dir .. " && cd app && npx --yes yarn install")
      else
        vim.cmd [[Lazy load markdown-preview.nvim]]
        vim.fn["mkdp#util#install"]()
      end
    end,
    init = function()
      if vim.fn.executable "npx" then vim.g.mkdp_filetypes = { "markdown" } end
    end,
  }

Looks like Kamilcuk might be using a single file setup so he probably has his in ~/.config/nvim/lua/config/lazy.lua or ~/.config/nvim/init.lua in the spec = {... section

It all depends on what you are using and how exactly you've set it up, which is why its so hard to get good help on the topic, there are many variables.

I'm using:-

If you let me know what you are using and I can be a bit more specific.

Here is a screenshot of my plugins folder if that helps.

image

Tweekism avatar Aug 02 '24 02:08 Tweekism

I'm using the lazyvim "distro" w/structured setup on linux. Your fix seems to be working for me. Thanks so much for your help!

baronyoung avatar Aug 02 '24 05:08 baronyoung

This goes where ever you are specifying your plugins.

So for me, that would be ~/.config/nvim/lua/plugins/markdown-preview.lua

and the file contents would be:-

return {
    -- Install markdown preview, use npx if available.
    "iamcco/markdown-preview.nvim",
    cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
    ft = { "markdown" },
    build = function(plugin)
      if vim.fn.executable "npx" then
        vim.cmd("!cd " .. plugin.dir .. " && cd app && npx --yes yarn install")
      else
        vim.cmd [[Lazy load markdown-preview.nvim]]
        vim.fn["mkdp#util#install"]()
      end
    end,
    init = function()
      if vim.fn.executable "npx" then vim.g.mkdp_filetypes = { "markdown" } end
    end,
  }

Looks like Kamilcuk might be using a single file setup so he probably has his in ~/.config/nvim/lua/config/lazy.lua or ~/.config/nvim/init.lua in the spec = {... section

It all depends on what you are using and how exactly you've set it up, which is why its so hard to get good help on the topic, there are many variables.

I'm using:-

If you let me know what you are using and I can be a bit more specific.

Here is a screenshot of my plugins folder if that helps.

image

Thanks so much, this works well for me.

==Yarn is needed==, make sure npm install -g yarn first.

syw-robotics avatar Aug 09 '24 16:08 syw-robotics

  • No yarn/npm/npx
  • Lazy package manager
  • Neovim v0.11.0-dev
  • Ubuntu 22.04.4 LTS
  • WSL2 (Windows 10)

~/.config/nvim/init.lua config code:

  -- install markdown-preview.nvim without yarn or npm
  {
    'iamcco/markdown-preview.nvim',
    cmd = { 'MarkdownPreviewToggle', 'MarkdownPreview', 'MarkdownPreviewStop' },
    ft = { 'markdown' },
    build = function()
      vim.fn['mkdp#util#install']()
    end,
  },

I found I needed to run

:Lazy build markdown-preview.nvim

Just once before :MarkdownPreview would work, after which it would work fine without having to run the build command. I am very unfamiliar with lua, but surely there's a way to run this build command on install?

Also, I'd be keen to help @Tweekism !

Hi peeps,

Seems like iamcco isn’t watching this one anymore, so it’s unlikely this will get merged here. A few of us are looking at possibly reviving the project elsewhere if there is enough interest in helping maintain it.

Alternatively a couple of previous users started a new project https://github.com/jannis-baum/Vivify as a potential replacement

viscount-monty avatar Aug 12 '24 11:08 viscount-monty

Hey @viscount-monty, that'd be awesome.

I'm actually away for a couple days attending a funeral, but if you are interested check out that Vivify project. I'm helping them out at the moment as it's seeing a lot of active development. Let me know what you think, and I'll chat more later in the week when I get back.

Tweekism avatar Aug 12 '24 12:08 Tweekism

Hi, before executing the functin, Lazy load the plugin.

This is my resulting lazy configuration, that uses npx is available:

  {
    -- Install markdown preview, use npx if available.
    "iamcco/markdown-preview.nvim",
    cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
    ft = { "markdown" },
    build = function(plugin)
      if vim.fn.executable "npx" then
        vim.cmd("!cd " .. plugin.dir .. " && cd app && npx --yes yarn install")
      else
        vim.cmd [[Lazy load markdown-preview.nvim]]
        vim.fn["mkdp#util#install"]()
      end
    end,
    init = function()
      if vim.fn.executable "npx" then vim.g.mkdp_filetypes = { "markdown" } end
    end,
  },

This works for me, many thanks :D

bavo96 avatar Aug 14 '24 09:08 bavo96

Just to add the full contents of init.lua (if the single-file method is used), for others who are as new to lua scripting as me:

require("config.lazy") -- already present in the default init.lua
spec = {
  {
    "iamcco/markdown-preview.nvim",
    cmd = { 'MarkdownPreviewToggle', 'MarkdownPreview', 'MarkdownPreviewStop' },
    ft = { 'markdown' },
    build = function()
      vim.cmd [[Lazy load markdown-preview.nvim]]
      vim.fn['mkdp#util#install']()
    end,
  },
}

Liam-Twomey avatar Aug 27 '24 04:08 Liam-Twomey

@viscount-monty Hey mate, soz I've been away, things got a little busy here.

I'll be at https://github.com/jannis-baum/Vivify If ya keen, drop a new thread in the discussions over there, no need to spam all the subscribers here. 😅

Tweekism avatar Aug 30 '24 13:08 Tweekism

This fixed the error for me:

  -- install markdown-preview.nvim without yarn or npm
  {
    'iamcco/markdown-preview.nvim',
    event = "VeryLazy",
    cmd = { 'MarkdownPreviewToggle', 'MarkdownPreview', 'MarkdownPreviewStop' },
    ft = { 'markdown' },
    build = function()
      vim.fn['mkdp#util#install']()
    end,
  },

emnul avatar Sep 24 '24 16:09 emnul

This fixed the error for me:

  -- install markdown-preview.nvim without yarn or npm
  {
    'iamcco/markdown-preview.nvim',
    event = "VeryLazy",
    cmd = { 'MarkdownPreviewToggle', 'MarkdownPreview', 'MarkdownPreviewStop' },
    ft = { 'markdown' },
    build = function()
      vim.fn['mkdp#util#install']()
    end,
  },

There is a slight problem with this. In this config, plugin will be loaded on the VeryLazy event each time, not just when you open a markdown file or enter a cmd. I wrote a solution that respects the lazy loading of the plugin:

return {
  "iamcco/markdown-preview.nvim",
  cmd = { "MarkdownPreviewToggle", "MarkdownPreview"},
  build = function()
    vim.opt.rtp:prepend(vim.fn.stdpath('data') .. '/lazy/markdown-preview.nvim')
    vim.fn["mkdp#util#install"]()
  end,
}

ZenithFlux avatar Oct 12 '24 06:10 ZenithFlux

My two cents on fixing this, while keeping the default lazy.nvim config

Config for reference:

return {
  -- markdown preview from nvim
  'iamcco/markdown-preview.nvim',
  cmd = { 'MarkdownPreviewToggle', 'MarkdownPreview', 'MarkdownPreviewStop' },
  ft = { 'markdown' },
  build = function()
    vim.fn['mkdp#util#install']()
  end,
}

The plugin will need to be loaded first, currently its tied to cmd and ft

:Lazy load markdown-preview.nvim

Then call the build command:

:Lazy build markdown-preview.nvim

saifazmi avatar Oct 20 '24 23:10 saifazmi

I fixed it with this spec:

{
  "iamcco/markdown-preview.nvim",
  cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
  ft = { "markdown" },
  build = ":call mkdp#util#install()",
}

jblsp avatar Dec 02 '24 03:12 jblsp

I fixed it with this spec:

{
  "iamcco/markdown-preview.nvim",
  cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
  ft = { "markdown" },
  build = ":call mkdp#util#install()",
}

Fixed for me

propilideno avatar Dec 13 '24 09:12 propilideno

I found I needed to run

:Lazy build markdown-preview.nvim

Thanks so much for that! You helped me with the final step to get it working on Windows!

JohnWilliston avatar Dec 19 '24 21:12 JohnWilliston

I found another solution, changing the build to

{
    "iamcco/markdown-preview.nvim",
    ft = "markdown",
    build = ":call mkdp#util#install()",
  }

found here

Mithrandir2k18 avatar Apr 07 '25 07:04 Mithrandir2k18

I found another solution, changing the build to

{ "iamcco/markdown-preview.nvim", ft = "markdown", build = ":call mkdp#util#install()", }

found here

Worked for me too, thanks!

franco-ruggeri avatar May 26 '25 12:05 franco-ruggeri

I found another solution, changing the build to

{ "iamcco/markdown-preview.nvim", ft = "markdown", build = ":call mkdp#util#install()", }

found here

This worked like a charm! Thanks!

pipx2 avatar Jun 01 '25 21:06 pipx2