2

I use a rather nifty automatic text formatting for Markdown:

(Seen https://asciidoc.org/userguide.html#X61)

augroup TXT | au!
  autocmd FileType asciidoc,markdown
    \ setlocal autoindent expandtab tabstop=8 softtabstop=2 shiftwidth=2
    \ textwidth=70 wrap formatoptions=atqn
    \ formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\\|^\\s*<\\d\\+>\\s\\+\\\\|^\\s*[a-zA-Z.]\\.\\s\\+\\\\|^\\s*[ivxIVX]\\+\\.\\s\\+
    \ comments=s1:/*,ex:*/,://,b:#,:%,:XCOMM,fb:-,fb:*,fb:+,fb:.,fb:>
    \ listchars=tab:»·,trail:·
    \ list |
  autocmd FileType asciidoc,markdown silent! %foldopen!
augroup END

This auto-indents lists and keeps my text blocks short by automatically inserting hard breaks or removing them where appropriate.

However this behaviour gets in my way when entering fenced code, as Vim tries to merge lines not separated by a paragraph together until textwidth is reached.

Can I disable auto formatting in fenced code altogether? How would comments= look like to treat everything between

```
fenced code
```

as a comment Vim should not auto-format? See the absence of formatoptions=-c above which I assume Vim would take to leave my comments alone.

0

1 Answer 1

2

I am afraid it is "impossible" to do with comments. The thing is, it doesn't analyze if it is in real comments of not -- it actually treated as real comments. It was just hijacked for list items as they are similar in asciidoc and markdown to what C-like comments are:

/*****************************
* comment line 1
* comment line 2
******************************/

Thus if your press enter after comment line 2 it will continue it on the next line prepending with a "bullet".

Of course you can try to implement your own solution:

  1. map <CR> in insert mode to a function where you have to analyze surroundings, like search backward for a fenced block start and turn off comments if found

  2. or do the same without comments but with your own implementation of bullet inserting.

But it would be fragile or slow or both.

1
  • I played around the configuration options for some time. comments and formatoptions-=c unfortunately do not mean leave comments alone. There seems to be no way achieving what I want using Vim's out of the box configuration options.
    – JohnDoe
    Sep 15, 2020 at 7:55

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.

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