Why does vim default markdown ftplugin source html ftplugins? Is there any ways to avoid it?

StackOverflow https://stackoverflow.com/questions/22839269

  •  27-06-2023
  •  | 
  •  

質問

all is in the title... I did a ftplugin to live preview an html file (php and css also) with a browser, but now, when I open a markdown file, the browser opens too... I saw why: there is this line in the default ftplugin/markdown.vim:

runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim

so first question, why does markdown source html ftplugin ? It seems irrevelant for me, but perhaps there are good reasons that I'd be glad to know.

Then, is there a way not to source html ftplugins for markdown files ?

役に立ちましたか?

解決

Markdown allows you to use inline HTML. From the spec:

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags.

That explains the behavior of the filetype plugin.

Disabling this

It would be best if you could just disable the mentioned live preview; as this is probably triggered by an :autocmd BufWritePost <buffer> ..., you could probably disable it via something like this in your ~/.vim/after/ftplugin/markdown.vim:

:autocmd! BufWritePost <buffer>

To completely get rid of the HTML stuff, copy the $VIMRUNTIME/ftplugin/markdown.vim to your user's ~/.vim/ftplugin/markdown.vim, and delete / comment out the :runtime command. The b:did_ftplugin check will ensure that the original ftplugin, though still being sourced, does nothing.

他のヒント

You could add this at the top of your ~/.vim/ftplugin/html.vim:

if &ft=="markdown"
  finish
endif

this will prevent markdown files from processing the html settings.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top