markdown-preview.nvim: Running MarkdownPreview throws uncaught exception: Error: spawn xdg-open ENOENT in WSL 2 with terminal Vim
Hi,
I’m using Vim 8.1 inside of Ubuntu 20.04 running in WSL 2 using the latest pull from master at the time of writing this comment.
Inside of WSL 1 this plugin worked great. It would open my default browser when running that command without having to do anything custom.
But now within WSL 2 it fails to run :MarkdownPreview
with:
[markdown-preview.vim] uncaught exception: Error: spawn xdg-open ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Turns out you need to install sudo apt-get install -y xdg-utils
, and then things work fine. Although there is a ~5 second delay before it opens where as with WSL 1 it was instant.
Might be worth adding something to the docs or wiki for such an issue in a WSL section.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (2 by maintainers)
There is my solution: sudo ln -s /mnt/c/Program\ Files\ (x86)/Microsoft/Edge/Application/msedge.exe /usr/bin/edge let let g:mkdp_browser = ‘edge’
I just wanted to mention, using WSL2 (Arch if that makes a difference) the above methods did not work for me.
What DID work was to install wslu and set
g:mkdp_browser='wslview'
in my vimrc (well, init.vim). I have not experienced the multi-second delays the others are talking about using this approach.@XeonChow Another way to solve is to
redraw!
in the last line of the function pointed byg:mkdp_browserfunc
This is working on WSL2(Ubuntu 22.04) on a x64 machine. This opens using Chrome by default, and switch to Edge if Chrome not found.
I have update README and improve the error message
You solve my problem! Thank you
@XeonChow it can be solved by using wsl-open instead of
wslview
. Installwsl-open
and setg:mkdp_browser='wsl-open'
If you prefer a general vim setting to a WSL specified one, use this trick without modifying
g:mkdp_browser
Just run
:MarkdownPreview
and you should be good to go.