When writing indented fenced codeblocks (the only ones I use) like

    some shell code

in markdown the indentation of comments is automatically removed when I type the comment character #.

# as soon as I type '#' the indentation is removed

Also, the indentation in normal mode using > does not work on the comments (even though the rest is properly indented).

Note, I do not use any markdown specific plugins, but make use of the default syntax highlighting using

  let g:markdown_fenced_languages = [
    \ 'py=python', 'python',
    \ 'sh', 'bash=sh', 'shell=sh',
    \ 'c', 'c++=cpp',
    \ 'rb=ruby', 'ruby',
    \ 'html', 'css',
    \ 'js=javascript', 'javascript',
    \ 'json',
    \ 'yaml', 'yml=yaml',
    \ 'vim'

How do I debug this to find the cause?

1 Answer 1


Remove set smartindent from your configuration.

Excerpt from the :h 'smartindent'

        When typing '#' as the first character in a new line, the indent for
        that line is removed, the '#' is put in the first column.  The indent
        is restored for the next line.  If you don't want this, use this
        mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.
        When using the ">>" command, lines starting with '#' are not shifted

How do I debug this to find the cause?

As usual, start with no config, check if it works, and add half of the config, check, etc. How do I debug my vimrc file? should also apply to neovim wrt to adjusted vimrc -> init.vim/lua and runtimepath changes maybe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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