Skip to content
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

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

Open
sontungexpt opened this issue Jul 23, 2024 · 16 comments
Open

Comments

@sontungexpt
Copy link

sontungexpt commented Jul 23, 2024

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
@Raiden-16F7
Copy link

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

@Tweekism
Copy link

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
Copy link

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
Copy link

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

@baronyoung
Copy link

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
Copy link

Tweekism commented Aug 2, 2024

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
Copy link

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!

hafezfhmi added a commit to hafezfhmi/dotfiles that referenced this issue Aug 5, 2024
There was an error when installing
https://github.com/iamcco/markdown-preview.nvim through plugins in
LazyVim through LazyExtras.
This commit applies a fix found in an issue opened for the error.

Related issues:
iamcco/markdown-preview.nvim#690

Fixes pull request (not merged yet at time of writing):
LazyVim/LazyVim#4196
@SeaHI-Robot
Copy link

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
Copy link

  • 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

@Tweekism
Copy link

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
Copy link

bavo96 commented Aug 14, 2024

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
Copy link

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
Copy link

@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
Copy link

emnul commented Sep 24, 2024

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
Copy link

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,
}

alexarbogast added a commit to alexarbogast/dotfiles that referenced this issue Oct 17, 2024
- update nvchad config to match starter for v2.5.
- fix markdown preview installation according to
iamcco/markdown-preview.nvim#690 (comment)
@saifazmi
Copy link

saifazmi commented Oct 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests