0

I really like how vim paragraph auto format works for markdown. The one place where it falls flat on its face is when editing/formatting code and log output that I want to put into the markdown (maybe this says something questionable about the content of my blogs...) as code blocks.

I am hoping to configure this in such a way that vim treats regular text as comment and actual code blocks as sacred and not to be messed with. This would be consistent with its usual behavior I configure (formatoptions=a1njwbtcroql) But I haven't found out how to do this. Could it be possible with a custom markdown syntax file? The one it comes with seems to highlight code blocks in green, which i appreciate since it lets me see that i've got it correct without having to keep an eye on the rendered output all the time.

For now I use this au filetype markdown setlocal nosmartindent | setlocal formatoptions-=a to preserve sanity, but this forces me to manually format the paragraphs, which I'd rather avoid.

3
  • If there's no easy native solution I'd be surprised if there's not a plugin out there that does this (among other thingis). Asciidoc, which is far less prevalent than Markdown, has at least one plugin with this feature. Did you google anything like that? (Unless you're trying to avoid plugins...)
    – B Layer
    Dec 23, 2020 at 9:46
  • FYI, I looked at an example for Asciidoc (which is very similar to MD when it comes to code blocks) and the function that does formatting runs almost 50 lines...which suggests a quick, robust native solution is probably a tall order. (There still might be something native that's a bit more rough around the edges but possible with less effort.)
    – B Layer
    Dec 23, 2020 at 9:51
  • I think that different languages getting nested inside is unfortunately just a bit of a limitation for the syntax engine.
    – Steven Lu
    Oct 28, 2021 at 2:31

0

Your Answer

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

Browse other questions tagged or ask your own question.