1

I want to fold in markdown using the built in markdown plugin that I believe should come with the version of vim I have (Vi IMproved 8.1 (2018 May 18, compiled Apr 23 2019 20:02:08)).

I am struggling to make the answers in the other question on this topic work for me.

I have no plugins installed, and I made my .vimrc the most minimal it can be:

let g:markdown_folding = 1
let g:markdown_fenced_languages = ['vim', 'yaml', 'python', 'bash=sh', 'sql', 'git', 'make', 'html', 'css', 'javascript', 'js=javascript', 'json=javascript', 'xml']
syntax enable
set nocompatible

With this, if I open a markdown file, I see that it is highlighted correctly, and :set ft? returns markdown. However, :set foldmethod? always returns manual, and zc returns E490: fold not found.

I have no idea what I'm doing wrong, and I've run out of things to try. The only thing I can think of is that if has("folding") from that built in plugin must be returning false, but I don't know what that syntax is or how to enable folding.

  • If you execute the command :filetype... Do you see filetype detection:ON plugin:ON indent:ON? If you see plugin:OFF, then that might explain what you're seeing... Happy to turn this into an answer, if it turns out this is the cause of your issue... Cheers! – filbranden Aug 16 at 23:32
  • You can also use the :scriptnames command to confirm/check that the ftplugin/markdown.vim script is being sourced. Please use the commands suggested and please edit the question to include your findings. (Ok to add a comment indicating you've done that, feel free to mention @filbranden and I'll get a notification about it.) – filbranden Aug 16 at 23:44
1

TL;DR: You should include the command filetype plugin on in your vimrc. You most probably want filetype plugin indent on to enable all filetype-related types of plugins.

Vim has a handful of filetype-related features, and they can be enabled and disabled individually using the :filetype command. (Technically, syntax highlighting is also dependent on filetypes, but you use the :syntax command to enable or disable it.)

The :filetype command can be used to enable filetype detection, which is a pre-requisite for all the other features (since the other features depend on knowing which filetype to load plugins for.) Detection is enabled with filetype on.

Then there are the indent plugins (enabled with filetype indent on), which typically set 'indentexpr' to set up rules for automatic indentation for that particular filetype.

And finally there's the plugin part, which enables loading Vim files from the ftplugin/ directory, such as the one markdown.vim you identified.

You can check whether filetype features are enabled with:

:filetype

If you see filetype detection:OFF plugin:OFF indent:OFF, that means it's disabled. (If you see detection:ON but another feature is OFF, it's not fully enabled either.)

To fix that and enable all filetype features use:

:filetype plugin indent on

If you want that to be always the case, include that line in your vimrc.

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.