iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim
MIT License
6.76k stars 280 forks source link

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

Open sontungexpt opened 3 months ago

sontungexpt commented 3 months ago

Describe the bug

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):

Raiden-16F7 commented 3 months ago

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

Tweekism commented 3 months ago

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

Kamilcuk commented 2 months ago

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,
  },
nilsherzig commented 2 months ago

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

baronyoung commented 2 months ago

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 ?

Tweekism commented 2 months ago

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

baronyoung commented 2 months ago

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!

SeaHI-Robot commented 2 months ago

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.

viscount-monty commented 2 months ago

~/.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

Tweekism commented 2 months ago

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.

bavo96 commented 2 months ago

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

Liam-Twomey commented 1 month ago

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,
  },
}
Tweekism commented 1 month ago

@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. 😅

emnul commented 4 weeks ago

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,
  },
ZenithFlux commented 1 week ago

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,
}
saifazmi commented 3 days ago

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