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.

  • 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 '20 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 '20 at 9:51

Your Answer

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

Browse other questions tagged or ask your own question.