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

wsl2 ubuntu 20.04 markdownpreview无法启动chrome #309

Closed
sectum-sempra opened this issue Mar 3, 2021 · 4 comments
Closed

wsl2 ubuntu 20.04 markdownpreview无法启动chrome #309

sectum-sempra opened this issue Mar 3, 2021 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@sectum-sempra
Copy link

:mess显示结果如下
[markdown-preview.nvim]: Can not open browser by using cmd.exe command

init.vim里对应部分设置如下:
let g:mkdp_preview_options = { \ 'mkit': {},
\ 'katex': {},
\ 'uml': {},
\ 'maid': {},
\ 'disable_sync_scroll': 0,
\ 'sync_scroll_type': 'middle',
\ 'hide_yaml_meta': 1,
\ 'sequence_diagrams': {},
\ 'flowchart_diagrams': {},
\ 'content_editable': v:false,
\ 'disable_filename': 0
\ }
let g:mkdp_browser = 'chrome'
let g:mkdp_filetypes = ['markdown','rmd']
let g:mkdp_auto_start = 1
let g:mkdp_command_for_global = 1
let g:mkdp_echo_preview_url = 1
let g:mkdp_open_to_the_world = 1

另外chrome已经添加到user和system的path里, 在cmd里输入chrome可以正常打开chrome

@iamcco iamcco added the help wanted Extra attention is needed label Mar 7, 2021
@iamcco
Copy link
Owner

iamcco commented Mar 7, 2021

你用 wsl 关键字搜下 issue,记得之前有人遇到过

@Qiguang
Copy link

Qiguang commented May 1, 2021

After several hours of research, I found the reason of this issue (at least for my situation).

TL;DR

Just try launch nvim by this command: sudo env "PATH=$PATH" nvim, then check if the issue is solved.


As this plugin launches Chorme using cmd.exe , So test if you can launch cmd.exe from your WSL console directly. If the environment of your WSL is correct, just typecmd.exe

then, cmd window will shown.

If it cannot be launched, check your $PATH variable. Reference

You can launch cmd.exe in WSL console means you can launch it in nvim. (how to run shell command in vim)

But I tried to launch cmd.exe in nvim by command :!cmd.exe, error prompted /bin/bash: cmd.exe: command not found

After researching, I found this is because I launched nvim by command sudo nvim, but sudo changed my default $PATH variable of shell, so cmd.exe cannot be found. Reference

To avoid this, run nvim by using sudo env "PATH=$PATH" nvim which keeps the default $PATH, then all issues disappears.

@sectum-sempra 你试一下在nvim里直接启动cmd.exe能启动成功吗?不能的话,可能是PATH变量的问题。

@isanasan
Copy link

This problem is resolved.

Just try this command

export PATH=$PATH:/mnt/c/Windows/System32/

@LoliPain
Copy link

Also:
/etc/wsl.conf

[interop]
enabled = true
appendWindowsPath = true

then close WSL terminal

Run cmd.exe
wsl --shutdown

Now open WSL again and $PATH is merged with Windows

@iamcco iamcco closed this as completed May 13, 2022
@0re5ama 0re5ama mentioned this issue Aug 21, 2023
wzf03 added a commit to wzf03/markdown-preview.nvim that referenced this issue Jan 4, 2024
The absolute path of cmd.exe is a more stable choice in wsl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants