Closed nickjj closed 4 years ago
I have update README and improve the error message
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.
It doesn't work well for me now in WSL2.
I have changed ip and port, when I execute :MarkdownPreview
, my chrome on windows10 will open with site http://172.30.39.164:8854/page/1
, and warn me :
This site can’t be reached
172.30.39.164 refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
What can I do to solve it?
I didn't change my ip:port and it works here with an address of http://127.0.0.1:8576/page/1
, although there is still a multi-second delay for it to open. I'm running commit faacfbcefe88badb0a5bee3290ec690373552f2b
of this plugin.
I would try disabling Windows defender / firewall to see if that fixes anything.
hahahahahhahaha... I have solved it!
I have execute lsof -i
in WSL2, and this plugin is listening localhost
but not IP address
, WSL2 treats Windows as a stand-alone host, so the connection from Windows is refused.
Add let g:mkdp_open_to_the_world = 1
to init.vim will solve this problem!
@iamcco 可以把这加文档里啦,老哥。换windows可搞死我了,wsl(我死了):joy:
@mrbeardad README 有链接链到这里了
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.
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.
@ndaman it works on my debian wsl2, mostly perfect except that my terminal window will go blank after i start preview, then it gradually reloads everything when i make some mouse or keyboard movement. no big deal but kinda annoying.
@XeonChow it can be solved by using wsl-open instead of wslview
. Install wsl-open
and set g:mkdp_browser='wsl-open'
If you prefer a general vim setting to a WSL specified one, use this trick without modifying g:mkdp_browser
sudo rm $(which xdg-open)
sudo ln -s $(which wsl-open) /usr/local/bin/xdg-open
Just run :MarkdownPreview
and you should be good to go.
@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
sudo rm $(which xdg-open) sudo ln -s $(which wsl-open) /usr/local/bin/xdg-open
Just run
:MarkdownPreview
and you should be good to go.
@qingbyin thank yuo so much, i followed your instruction and it works flawlessly.
I didn't change my ip:port and it works here with an address of
http://127.0.0.1:8576/page/1
, although there is still a multi-second delay for it to open. I'm running commitfaacfbcefe88badb0a5bee3290ec690373552f2b
of this plugin.I would try disabling Windows defender / firewall to see if that fixes anything.
when i tap ':MarkdownPreview' on WSL1 vim. my chrome on windows10 will open with site 'http://127.0.0.1:9410/markdown/16300587241?L2hvbWUvemloYW94aW5nL3NoaW55X3Byb2plY3RzL1N3aW1NYXAvd3d3L3Rlc3QubWQmL2hvbWUvemloYW94aW5nLy52aW0vYnVuZGxlL21hdGhqYXgtc3VwcG9ydC1mb3ItbWtkcC9tYXRoamF4LXN0YXRpYy8=' it can't access this website, what should i do to solve this problem?
@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
sudo rm $(which xdg-open) sudo ln -s $(which wsl-open) /usr/local/bin/xdg-open
Just run
:MarkdownPreview
and you should be good to go.
when i tap ':MarkdownPreview' on WSL1 vim. my chrome on windows10 will open with site 'http://127.0.0.1:9410/markdown/16300587241?L2hvbWUvemloYW94aW5nL3NoaW55X3Byb2plY3RzL1N3aW1NYXAvd3d3L3Rlc3QubWQmL2hvbWUvemloYW94aW5nLy52aW0vYnVuZGxlL21hdGhqYXgtc3VwcG9ydC1mb3ItbWtkcC9tYXRoamF4LXN0YXRpYy8=' it can't access this website, what should i do to solve this problem?
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'
when i tap ':MarkdownPreview' on WSL1 vim. my edge on windows10 will open with site 'http://127.0.0.1:9410/markdown/16300587241?L2hvbWUvemloYW94aW5nL3NoaW55X3Byb2plY3RzL1N3aW1NYXAvd3d3L3Rlc3QubWQmL2hvbWUvemloYW94aW5nLy52aW0vYnVuZGxlL21hdGhqYXgtc3VwcG9ydC1mb3ItbWtkcC9tYXRoamF4LXN0YXRpYy8=' it can't access this website, what should i do to solve this problem?
If anyone is looking for a solution that doesn't require installing wsl-open
, modifying your vimrc or creating a symlink you can set up this alias: alias open="/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe"
I've been doing this on WSL 2 for months and running :MarkdownPreview
works.
I use this plugin in WSL1, ubuntu. Every time I input :MarkdownPreview
, the statusline shows " openning 'http://127.0.0.1:8781/page/5' ... done! (xdg-open)". And I have to type this address in my browser to view my markdown.
I would like to ask how to make the preview page show automatically? Thank you very much.
@ndaman it works on my debian wsl2, mostly perfect except that my terminal window will go blank after i start preview, then it gradually reloads everything when i make some mouse or keyboard movement. no big deal but kinda annoying.
@XeonChow Another way to solve is to redraw!
in the last line of the function pointed by g:mkdp_browserfunc
I use this plugin in WSL1, ubuntu. Every time I input :MarkdownPreview, the statusline shows " openning 'http://127.0.0.1:8781/page/5' ... done! (xdg-open)". And I have to type this address in my browser to view my markdown.
I would like to ask how to make the preview page show automatically? Thank you very much.
@johnsonkee I guess your settings is broken.
When I was testing, I encountered this as well. And it turned out that I made mistakes. Furthermore, even if silent
is not used, error messages regarding to the call to browser hide behind vim.
@ndaman it works on my debian wsl2, mostly perfect except that my terminal window will go blank after i start preview, then it gradually reloads everything when i make some mouse or keyboard movement. no big deal but kinda annoying.
@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.
function! MdpOpenPreview(url) abort let l:mdp_browser = '/mnt/c/Program\ Files/Google/Chrome/Application/chrome.exe' let l:mdp_browser_opts = '--new-window' if !filereadable(substitute(l:mdp_browser, '\\ ', ' ', 'g')) let l:mdp_browser = '/mnt/c/Program\ Files\ \(x86\)/Microsoft/Edge/Application/msedge.exe' let l:mdp_browser_opts = '--new-window' endif execute join(['silent! !', l:mdp_browser, l:mdp_browser_opts, a:url]) redraw! endfunction let g:mkdp_browserfunc = 'MdpOpenPreview'
You solve my problem! Thank you
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: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.