4

When I open a file with .md extension, the filetype is set to markdown, as expected. But the ftplugin for HTML is also loaded as I can see since I have some insert mode mappings in there to auto-insert html entities in place of umlauts. I opened ftplugin/markdown.vim and found this

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

setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=>\ %s
setlocal formatoptions+=tcqln formatoptions-=r formatoptions-=o
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+

if exists('b:undo_ftplugin')
  let b:undo_ftplugin .= "|setl cms< com< fo< flp<"
else
  let b:undo_ftplugin = "setl cms< com< fo< flp<"
endif

As you can see, I already commented out the first line. But vim still loads the html plugin. How can I influence this behaviour?

  • How and where do you define those insert mode mappings? – romainl Nov 8 '15 at 17:52
  • @romainl In ftplugin/html.vim, e.g. inoremap <buffer> <Char-246> &ouml; Which will automatically replace the ö as I type it. – oarfish Nov 8 '15 at 18:04
  • 2
    Did you also fix /usr/share/vim/vim74/ftplugin/markdown.vim? I wouldn't call HTML "unrelated" to Markdown. Markdown is clearly intended to work with it. – muru Nov 8 '15 at 18:12
  • 1
    @oarfish Run :scriptnames after opening a markdown file. You can find out if other runtime directories are being used. (The list might be long, so you could filter out stuff by comparing against the output after just opening Vim.) – muru Nov 8 '15 at 18:36
  • 2
    @oarfish excellent. I suppose that's your answer. I should have suggested :e $VIMRUNTIME/ftplugin/markdown.vim, instead of assuming things about your installation. – muru Nov 8 '15 at 18:39
6

Vim already comes with Markdown support so what happens is that you have two Markdown ftplugins doing the same thing. Since you "fixed" one (~/.vim/ftplugin/markdown.vim) without "fixing" the other ($VIMRUNTIME/ftplugin/markdown.vim), your fix is simply overridden by the built-in ftplugin.

If you insist on disabling HTML support in markdown buffers you can simply "fix" the built-in ftplugin (and probably get rid of the extraneous one) but I'd suggest you reconsider your strategy. HTML is valid Markdown so yeah, HTML has its place in Markdown.

  • Yeah, but I need to use html entities in html, while they won't be correctly displayed in markdown. So my only option would be to drop the mappings which are very useful when edition html. – oarfish Nov 8 '15 at 18:44
  • 1
    @oarfish You can use Vim's conceal feature to display your HTML entities as the glyphs they stand for: :syntax match Entity "&ouml;" conceal cchar=ö. See :help syn-cchar for details. Depending on your precise needs, this might be a better fix than removing all HTML support from Markdown buffers. – Rich Jun 21 '16 at 11:51
2

According to the Markdown specification, you are allowed to use inline HTML for any markup that is not covered by Markdown's syntax. For this reason, the Markdown configuration of Vim's ftplugin also loads the HTML configuration, as you pointed out.

Instead of modifying this well-considered relation of default syntax configurations, I would suggest you modify your local ftplugin/html.vim so that commands very specific to HTML are only applied to files that are purely HTML. You could do so, for example, by wrapping these settings in a block of

if (&filetype == 'html')
    " commands that only apply to files of filetype HTML
endif
  • 1
    This is a nice solution. I was going to create an ftplugin for Markdown files in my after sub-directory to over-ride some of the commands in my HTML ftplugin but this is more elegant. – Anthony Geoghegan Nov 25 '16 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.