2

Here is my test .vimrc:

unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim

set textwidth=78
let &colorcolumn = &textwidth + 1
set linebreak breakindent
set number

augroup disable_auto_wrapping
  autocmd!
  autocmd filetype * set formatoptions-=t
augroup END

If I open a .txt file, :set fo? returns cq.

If I type a regular long line, it won't be hard-wrapped. Fine.

But if a line starts with an asterisk or hyphen, Vim will hard-wrap it nevertheless.

this is normal line that exceeds textwidth+1 value

* and this is the same line
  if I start it with asterisk
  or hyphen

I know I can stop this by using :set fo-=c, but why is that? It seems the c option is completely unrelated to the issue.

1 Answer 1

4
  1. From :help fo-table we get:

    c    Auto-wrap comments using 'textwidth', inserting the current comment
         leader automatically.
    
  2. *.txt are given the text filetype, which defines the following option:

    set comments=fb:-,fb:*,n:>
    
  3. The * that you use to mark up list items is recognized as a comment leader so your list is formatted as if it were a comment.

See :help format-comment.

5
  • This is somewhat strange they are treated as comment leaders. Even more strange this is still true for "text" files and not only "markdown".
    – user90726
    Sep 19, 2022 at 7:53
  • What is "strange"? How it is done or why?
    – romainl
    Sep 19, 2022 at 7:58
  • "Why" ........................
    – user90726
    Sep 19, 2022 at 8:00
  • 1
    That's quite an open-ended question. The original Markdown spec never mandated a specific extension so you can have Markdown or Markdown-like markup with or without .md. Also, people have been using lightweight markup in *.txt or extension-less files for decades (hint: the ancestor of GitHub era README.md were README.txt and, before that, plain README). That said, I think that the use of an explicitly comment-related feature for something unrelated with comments is more like a dirty hack than a well thought out feature.
    – romainl
    Sep 19, 2022 at 8:54
  • @user90726 well it certainly wouldn't be true for markdown, * isn't a comment in markdown.
    – hobbs
    Sep 19, 2022 at 13:00

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.